@@ -497,76 +497,68 @@ subclass which installs setuptools and pip into a created virtual environment::
497497 url = 'https://bootstrap.pypa.io/get-pip.py'
498498 self.install_script(context, 'pip', url)
499499
500+
500501 def main(args=None):
501- compatible = True
502- if sys.version_info < (3, 3):
503- compatible = False
504- elif not hasattr(sys, 'base_prefix'):
505- compatible = False
506- if not compatible:
507- raise ValueError('This script is only for use with '
508- 'Python 3.3 or later')
502+ import argparse
503+
504+ parser = argparse.ArgumentParser(prog=__name__,
505+ description='Creates virtual Python '
506+ 'environments in one or '
507+ 'more target '
508+ 'directories.')
509+ parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
510+ help='A directory in which to create the '
511+ 'virtual environment.')
512+ parser.add_argument('--no-setuptools', default=False,
513+ action='store_true', dest='nodist',
514+ help="Don't install setuptools or pip in the "
515+ "virtual environment.")
516+ parser.add_argument('--no-pip', default=False,
517+ action='store_true', dest='nopip',
518+ help="Don't install pip in the virtual "
519+ "environment.")
520+ parser.add_argument('--system-site-packages', default=False,
521+ action='store_true', dest='system_site',
522+ help='Give the virtual environment access to the '
523+ 'system site-packages dir.')
524+ if os.name == 'nt':
525+ use_symlinks = False
509526 else:
510- import argparse
511-
512- parser = argparse.ArgumentParser(prog=__name__,
513- description='Creates virtual Python '
514- 'environments in one or '
515- 'more target '
516- 'directories.')
517- parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
518- help='A directory in which to create the '
519- 'virtual environment.')
520- parser.add_argument('--no-setuptools', default=False,
521- action='store_true', dest='nodist',
522- help="Don't install setuptools or pip in the "
523- "virtual environment.")
524- parser.add_argument('--no-pip', default=False,
525- action='store_true', dest='nopip',
526- help="Don't install pip in the virtual "
527- "environment.")
528- parser.add_argument('--system-site-packages', default=False,
529- action='store_true', dest='system_site',
530- help='Give the virtual environment access to the '
531- 'system site-packages dir.')
532- if os.name == 'nt':
533- use_symlinks = False
534- else:
535- use_symlinks = True
536- parser.add_argument('--symlinks', default=use_symlinks,
537- action='store_true', dest='symlinks',
538- help='Try to use symlinks rather than copies, '
539- 'when symlinks are not the default for '
540- 'the platform.')
541- parser.add_argument('--clear', default=False, action='store_true',
542- dest='clear', help='Delete the contents of the '
543- 'virtual environment '
544- 'directory if it already '
545- 'exists, before virtual '
546- 'environment creation.')
547- parser.add_argument('--upgrade', default=False, action='store_true',
548- dest='upgrade', help='Upgrade the virtual '
549- 'environment directory to '
550- 'use this version of '
551- 'Python, assuming Python '
552- 'has been upgraded '
553- 'in-place.')
554- parser.add_argument('--verbose', default=False, action='store_true',
555- dest='verbose', help='Display the output '
556- 'from the scripts which '
557- 'install setuptools and pip.')
558- options = parser.parse_args(args)
559- if options.upgrade and options.clear:
560- raise ValueError('you cannot supply --upgrade and --clear together.')
561- builder = ExtendedEnvBuilder(system_site_packages=options.system_site,
562- clear=options.clear,
563- symlinks=options.symlinks,
564- upgrade=options.upgrade,
565- nodist=options.nodist,
566- nopip=options.nopip,
567- verbose=options.verbose)
568- for d in options.dirs:
569- builder.create(d)
527+ use_symlinks = True
528+ parser.add_argument('--symlinks', default=use_symlinks,
529+ action='store_true', dest='symlinks',
530+ help='Try to use symlinks rather than copies, '
531+ 'when symlinks are not the default for '
532+ 'the platform.')
533+ parser.add_argument('--clear', default=False, action='store_true',
534+ dest='clear', help='Delete the contents of the '
535+ 'virtual environment '
536+ 'directory if it already '
537+ 'exists, before virtual '
538+ 'environment creation.')
539+ parser.add_argument('--upgrade', default=False, action='store_true',
540+ dest='upgrade', help='Upgrade the virtual '
541+ 'environment directory to '
542+ 'use this version of '
543+ 'Python, assuming Python '
544+ 'has been upgraded '
545+ 'in-place.')
546+ parser.add_argument('--verbose', default=False, action='store_true',
547+ dest='verbose', help='Display the output '
548+ 'from the scripts which '
549+ 'install setuptools and pip.')
550+ options = parser.parse_args(args)
551+ if options.upgrade and options.clear:
552+ raise ValueError('you cannot supply --upgrade and --clear together.')
553+ builder = ExtendedEnvBuilder(system_site_packages=options.system_site,
554+ clear=options.clear,
555+ symlinks=options.symlinks,
556+ upgrade=options.upgrade,
557+ nodist=options.nodist,
558+ nopip=options.nopip,
559+ verbose=options.verbose)
560+ for d in options.dirs:
561+ builder.create(d)
570562
571563 if __name__ == '__main__':
572564 rc = 1
0 commit comments