Skip to content

Commit

Permalink
Try to download the latest versions of preinstalled packages
Browse files Browse the repository at this point in the history
* Will only accept Wheels (because that is all we can install
  without setuptools).
* Will still fall back to using the bundled copies of the
  preinstalled packages if it cannot access the internet.

This should prevent errors happening from too old of versions of
software being bundled with virtualenv, while still allowing people
to prevent talking to the internet with --no-download.
  • Loading branch information
dstufft committed Jan 19, 2016
1 parent deb3f6a commit f50df26
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
5 changes: 5 additions & 0 deletions docs/changes.rst
Expand Up @@ -29,6 +29,11 @@ Release History

* Remove use of () in .bat files so ``Program Files (x86)`` works :issue:`35`

* Download new releases of the preinstalled software from PyPI when there are
new releases available. This behavior can be disabled using
``--no-download``.


13.1.2 (2015-08-23)
-------------------

Expand Down
10 changes: 6 additions & 4 deletions docs/reference.rst
Expand Up @@ -90,11 +90,13 @@ Options
Provides an alternative prompt prefix for this
environment.

.. option:: --never-download
.. option:: --download

DEPRECATED. Retained only for backward compatibility.
This option has no effect. Virtualenv never downloads
pip or setuptools.
Download preinstalled packages from PyPI.

.. option:: --no-download

Do not download preinstalled packages from PyPI.

.. option:: --no-site-packages

Expand Down
4 changes: 1 addition & 3 deletions docs/userguide.rst
Expand Up @@ -128,7 +128,7 @@ below.
Removing an Environment
~~~~~~~~~~~~~~~~~~~~~~~

Removing a virtual environment is simply done by deactivating it and deleting the
Removing a virtual environment is simply done by deactivating it and deleting the
environment folder with all its contents::

(ENV)$ deactivate
Expand Down Expand Up @@ -254,5 +254,3 @@ As well as the extra directories, the search order includes:
#. The directory where virtualenv.py is located.
#. The current directory.

If no satisfactory local distributions are found, virtualenv will
fail. Virtualenv will never download packages.
61 changes: 37 additions & 24 deletions virtualenv.py
Expand Up @@ -606,12 +606,19 @@ def main():
"This option can be used multiple times.")

parser.add_option(
'--never-download',
dest="never_download",
"--download",
dest="download",
action="store_true",
default=True,
help="DEPRECATED. Retained only for backward compatibility. This option has no effect. "
"Virtualenv never downloads pip or setuptools.")
help="Download preinstalled packages from PyPI.",
)

parser.add_option(
"--no-download",
'--never-download',
dest="download",
action="store_false",
help="Do not download preinstalled packages from PyPI.",
)

parser.add_option(
'--prompt',
Expand Down Expand Up @@ -682,17 +689,13 @@ def main():
make_environment_relocatable(home_dir)
return

if not options.never_download:
logger.warn('The --never-download option is for backward compatibility only.')
logger.warn('Setting it to false is no longer supported, and will be ignored.')

create_environment(home_dir,
site_packages=options.system_site_packages,
clear=options.clear,
unzip_setuptools=options.unzip_setuptools,
prompt=options.prompt,
search_dirs=options.search_dirs,
never_download=True,
download=options.download,
no_setuptools=options.no_setuptools,
no_pip=options.no_pip,
no_wheel=options.no_wheel,
Expand Down Expand Up @@ -811,7 +814,8 @@ def find_wheels(projects, search_dirs):

return wheels

def install_wheel(project_names, py_executable, search_dirs=None):
def install_wheel(project_names, py_executable, search_dirs=None,
download=False):
if search_dirs is None:
search_dirs = file_search_dirs()

Expand All @@ -825,25 +829,29 @@ def install_wheel(project_names, py_executable, search_dirs=None):
] + project_names
logger.start_progress('Installing %s...' % (', '.join(project_names)))
logger.indent += 2

env = {
"PYTHONPATH": pythonpath,
"JYTHONPATH": pythonpath, # for Jython < 3.x
"PIP_FIND_LINKS": findlinks,
"PIP_USE_WHEEL": "1",
"PIP_ONLY_BINARY": ":all:",
"PIP_PRE": "1",
"PIP_USER": "0",
}

if not download:
env["PIP_NO_INDEX"] = "1"

try:
call_subprocess(cmd, show_stdout=False,
extra_env = {
'PYTHONPATH': pythonpath,
'JYTHONPATH': pythonpath, # for Jython < 3.x
'PIP_FIND_LINKS': findlinks,
'PIP_USE_WHEEL': '1',
'PIP_PRE': '1',
'PIP_NO_INDEX': '1',
'PIP_USER': '0'
}
)
call_subprocess(cmd, show_stdout=False, extra_env=env)
finally:
logger.indent -= 2
logger.end_progress()

def create_environment(home_dir, site_packages=False, clear=False,
unzip_setuptools=False,
prompt=None, search_dirs=None, never_download=False,
prompt=None, search_dirs=None, download=False,
no_setuptools=False, no_pip=False, no_wheel=False,
symlink=True):
"""
Expand All @@ -869,7 +877,12 @@ def create_environment(home_dir, site_packages=False, clear=False,
to_install.append('pip')
if not no_wheel:
to_install.append('wheel')
install_wheel(to_install, py_executable, search_dirs)
install_wheel(
to_install,
py_executable,
search_dirs,
download=download,
)

install_activate(home_dir, bin_dir, prompt)

Expand Down

0 comments on commit f50df26

Please sign in to comment.