Jannis Leidel  committed c0705f6 Merge

Merge branch 'never-download' of into ejucovy-never-download

  • Participants
  • Parent commits b9eadb0, 7dc6a9e

Comments (0)

Files changed (2)

File docs/index.txt

 distributions must be ``.egg`` files; distribute and pip distributions
 should be `.tar.gz` source distributions.
+Virtualenv will still download these packages if no satisfactory local
+distributions are found.
+If you are really concerned about virtualenv fetching these packages
+from the Internet and want to ensure that it never will, you can also
+provide an option ``--never-download`` like so::
+    $ virtualenv --extra-search-dir=/path/to/distributions --never-download ENV
+If this option is provided, virtualenv will never try to download
+setuptools/distribute or pip. Instead, it will exit with status code 1
+if it fails to find local distributions for any of these required
 Compare & Contrast with Alternatives


     return filename
 def _install_req(py_executable, unzip=False, distribute=False,
-                 search_dirs=None):
+                 search_dirs=None, never_download=False):
     if not distribute:
         setup_fn = 'setuptools-0.6c11-py%s.egg' % sys.version[:3]
         project_name = 'setuptools'
             # that it's in virtualenv_support
+            if never_download:
+                logger.fatal("Can't find any local distributions of %s to install "
+                             "and --never-download is set.  Either re-run virtualenv "
+                             "without the --never-download option, or place a %s "
+                             "distribution (%s) in one of these "
+                             "locations: %r" % (project_name, project_name, 
+                                                setup_fn or source,
+                                                search_dirs))
+                sys.exit(1)
   'No %s egg found; downloading' % project_name)
         cmd.extend(['--always-copy', '-U', project_name])
     logger.start_progress('Installing %s...' % project_name)
             dirs.append(os.path.join(os.path.dirname(virtualenv.__file__), 'virtualenv_support'))
     return [d for d in dirs if os.path.isdir(d)]
-def install_setuptools(py_executable, unzip=False, search_dirs=None):
-    _install_req(py_executable, unzip, search_dirs=search_dirs)
+def install_setuptools(py_executable, unzip=False,
+                       search_dirs=None, never_download=False):
+    _install_req(py_executable, unzip, 
+                 search_dirs=search_dirs, never_download=never_download)
-def install_distribute(py_executable, unzip=False, search_dirs=None):
-    _install_req(py_executable, unzip, distribute=True, search_dirs=search_dirs)
+def install_distribute(py_executable, unzip=False, 
+                       search_dirs=None, never_download=False):
+    _install_req(py_executable, unzip, distribute=True, 
+                 search_dirs=search_dirs, never_download=never_download)
 _pip_re = re.compile(r'^pip-.*(zip|tar.gz|tar.bz2|tgz|tbz)$', re.I)
-def install_pip(py_executable, search_dirs=None):
+def install_pip(py_executable, search_dirs=None, never_download=False):
     filenames = []
     for dir in search_dirs:
         filenames.extend([join(dir, fn) for fn in os.listdir(dir)
         easy_install_script = ''
     cmd = [py_executable, join(os.path.dirname(py_executable), easy_install_script), filename]
     if filename == 'pip':
+        if never_download:
+            logger.fatal("Can't find any local distributions of pip to install "
+                         "and --never-download is set.  Either re-run virtualenv "
+                         "without the --never-download option, or place a pip "
+                         "source distribution (zip/tar.gz/tar.bz2) in one of these "
+                         "locations: %r" % search_dirs)
+            sys.exit(1)'Installing pip from network...')
     else:'Installing existing %s distribution: %s' % (
         "You can add any number of additional --extra-search-dir paths.")
+        '--never-download',
+        dest="never_download",
+        action="store_true",
+        help="Never download anything from the network.  Instead, virtualenv will fail "
+        "if local distributions of setuptools/distribute/pip are not present.")
+    parser.add_option(
         help='Provides an alternative prompt prefix for this environment')
                        use_distribute=options.use_distribute or majver > 2,
-                       search_dirs=options.search_dirs)
+                       search_dirs=options.search_dirs,
+                       never_download=options.never_download)
     if 'after_install' in globals():
         after_install(options, home_dir)
 def create_environment(home_dir, site_packages=True, clear=False,
                        unzip_setuptools=False, use_distribute=False,
-                       prompt=None, search_dirs=None):
+                       prompt=None, search_dirs=None, never_download=False):
     Creates a new environment in ``home_dir``.
     if use_distribute or os.environ.get('VIRTUALENV_USE_DISTRIBUTE'):
-        install_distribute(py_executable, unzip=unzip_setuptools, search_dirs=search_dirs)
+        install_distribute(py_executable, unzip=unzip_setuptools, 
+                           search_dirs=search_dirs, never_download=never_download)
-        install_setuptools(py_executable, unzip=unzip_setuptools, search_dirs=search_dirs)
+        install_setuptools(py_executable, unzip=unzip_setuptools, 
+                           search_dirs=search_dirs, never_download=never_download)
-    install_pip(py_executable, search_dirs=search_dirs)
+    install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
     install_activate(home_dir, bin_dir, prompt)