Skip to content

Setting download = true does not enable virtualenv downloads #1558

@pglass

Description

@pglass

Overview

Behavior I'm seeing is described below: download = true in tox.ini does NOT cause virtualenv to enable downloads.

tox option virtualenv invocation virtualenv behavior
download = false virtualenv --no-download disable downloads
No download option virtualenv --no-download disable downloads
download = true virtualenv ... (no "download" flags) Defaults to disable downloads

Here is the virtualenv help for --download and --no-download, showing that virtualenv defaults to disabling downloads if none of these options are specified.

$ virtualenv --help | grep download
  --download                    pass to enable download of the latest pip/setuptools/wheel from PyPI (default: False)
  --no-download, --never-download
                                pass to disable download of the latest pip/setuptools/wheel from PyPI (default: True)

My environment

I'm on macOS 10.14.6, python 3.6.3, tox 3.14.2, and virtualenv 20.0.18

$ pip freeze
appdirs==1.4.3
distlib==0.3.0
filelock==3.0.12
importlib-metadata==1.3.0
importlib-resources==1.4.0
more-itertools==8.0.2
packaging==19.2
pluggy==0.13.1
py==1.8.0
pyparsing==2.4.5
six==1.13.0
toml==0.10.0
tox==3.14.2
virtualenv==20.0.18
zipp==0.6.0

$ python --version
Python 3.6.3

To reproduce

Here is a tox.ini to reproduce. I'm attempting to leverage virtualenv 20 features to ensure a specific version of pip is downloaded and installied in the virtualenv, to be used to install subsequent packages.

[tox]
envlist = py36
minversion = 3.10.0
requires = virtualenv >= 20.0
skipsdist = True

[testenv]
download = True
setenv =
    VIRTUALENV_PIP=19.2.3
    VIRTUALENV_SEEDER=pip
commands = {toxinidir}/.tox/py36/bin/pip --version

This outputs the following:

$ tox -rvv
using tox.ini: /Users/pglass/code/tox-bug/tox.ini (pid 67542)
  removing /Users/pglass/code/tox-bug/.tox/log
using tox-3.14.2 from /Users/pglass/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tox/__init__.py (pid 67542)
skipping sdist step
py36 start: getenv /Users/pglass/code/tox-bug/.tox/py36
py36 cannot reuse: -r flag
py36 create: /Users/pglass/code/tox-bug/.tox/py36
py36 uses /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6
  removing /Users/pglass/code/tox-bug/.tox/py36
setting PATH=/Users/pglass/code/tox-bug/.tox/py36/bin:/Users/pglass/.pyenv/versions/3.6.3/bin:/usr/local/Cellar/pyenv/1.2.16/libexec:/Users/pglass/.cargo/bin:/Users/pglass/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
[67559] /Users/pglass/code/tox-bug/.tox$ /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 -m virtualenv --python /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 py36
ERROR: Could not find a version that satisfies the requirement pip==19.2.3 (from versions: 19.1.1, 20.0.2)
ERROR: No matching distribution found for pip==19.2.3
RuntimeError: failed seed with code 1
ERROR: invocation failed (exit code 1)
ERROR: InvocationError for command /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 -m virtualenv --python /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 py36 (exited with code 1)
py36 finish: getenv /Users/pglass/code/tox-bug/.tox/py36 after 2.03 seconds
__________________________________________________________________________________________________________________ summary ___________________________________________________________________________________________________________________
ERROR:   py36: InvocationError for command /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 -m virtualenv --python /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 py36 (exited with code 1)

I get an error that it can't find this particular pip version because virtualenv is defaulting to "no download" behavior, even though I've specified download = true in tox.ini. I expect that version of pip to be downloaded and installed into the tox virtualenv.

You can see that the virtualenv command run is /Users/pglass/code/tox-bug/.tox$ /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 -m virtualenv --python /Users/pglass/.pyenv/versions/3.6.3/bin/python3.6 py36, so virtualenv will disable downloads since --download is not specified.

Workaround with VIRTUALENV_DOWNLOAD=1

The following tox.ini with VIRTUALENV_DOWNLOAD=1 added seems to work.

NOTE: disable = True is still required for this to work, in order to prevent tox from passing --no-download to virtualenv (which seems to ignore/override any environment variables).

[tox]
envlist = py36
minversion = 3.10.0
requires = virtualenv >= 20.0
skipsdist = True

[testenv]
download = True
setenv =
    VIRTUALENV_PIP=19.2.3
    VIRTUALENV_SEEDER=pip
    VIRTUALENV_DOWNLOAD=1
commands = {toxinidir}/.tox/py36/bin/pip --version

This gives me success:

$ tox -r
py36 recreate: /Users/pglass/code/tox-bug/.tox/py36
py36 run-test-pre: PYTHONHASHSEED='1771017363'
py36 run-test: commands[0] | /Users/pglass/code/tox-bug/.tox/py36/bin/pip --version
pip 19.2.3 from /Users/pglass/code/tox-bug/.tox/py36/lib/python3.6/site-packages/pip (python 3.6)
__________________________________________________________________________________________________________________ summary ___________________________________________________________________________________________________________________
  py36: commands succeeded
  congratulations :)

However, this workaround should not be required if I specify download = True

Expected behavior

Setting download = True in tox.ini should cause tox to run virtualenv --download

Desired behavior

The following breaks the existing default behavior, but would be my ideal from a UX perspective:

tox option virtualenv invocation virtualenv behavior
download = false virtualenv --no-download disable downloads
No download option virtualenv ... Default. Users can set VIRTUALENV_DOWNLOAD or VIRTUALENV_NO_DOWNLOAD as needed
download = true virtualenv --download enables downloads

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:normalaffects many people or has quite an impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions