Skip to content

Commit

Permalink
fix: --download option (#2262)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut authored Dec 31, 2021
1 parent b17dcd4 commit 61c065b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2120.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``--download`` option - by :user:`mayeut`.
12 changes: 8 additions & 4 deletions src/virtualenv/seed/wheels/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ def get_wheel(distribution, version, for_py_version, search_dirs, download, app_
Get a wheel with the given distribution-version-for_py_version trio, by using the extra search dir + download
"""
# not all wheels are compatible with all python versions, so we need to py version qualify it
# 1. acquire from bundle
wheel = from_bundle(distribution, version, for_py_version, search_dirs, app_data, do_periodic_update, env)
wheel = None

# 2. download from the internet
if version not in Version.non_version and download:
if not download or version != Version.bundle:
# 1. acquire from bundle
wheel = from_bundle(distribution, version, for_py_version, search_dirs, app_data, do_periodic_update, env)

if download and wheel is None and version != Version.embed:
# 2. download from the internet
wheel = download_wheel(
distribution=distribution,
version_spec=Version.as_version_spec(version),
Expand All @@ -32,6 +35,7 @@ def get_wheel(distribution, version, for_py_version, search_dirs, download, app_
to_folder=app_data.house,
env=env,
)

return wheel


Expand Down
31 changes: 29 additions & 2 deletions tests/unit/seed/wheels/test_acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import pytest

from virtualenv.seed.wheels.acquire import download_wheel, pip_wheel_env_run
from virtualenv.seed.wheels.acquire import download_wheel, get_wheel, pip_wheel_env_run
from virtualenv.seed.wheels.embed import BUNDLE_FOLDER, get_embed_wheel
from virtualenv.seed.wheels.util import discover_wheels
from virtualenv.seed.wheels.util import Wheel, discover_wheels
from virtualenv.util.path import Path


def test_pip_wheel_env_run_could_not_find(session_app_data, mocker):
Expand Down Expand Up @@ -68,3 +69,29 @@ def test_download_fails(mocker, for_py_version, session_app_data):
str(as_path),
"pip==1",
] == exc.cmd


@pytest.fixture
def downloaded_wheel(mocker):
wheel = Wheel.from_path(Path("setuptools-0.0.0-py2.py3-none-any.whl"))
mocker.patch("virtualenv.seed.wheels.acquire.download_wheel", return_value=wheel)
yield wheel


@pytest.mark.parametrize("version", ["bundle", "0.0.0"])
def test_get_wheel_download_called(for_py_version, session_app_data, downloaded_wheel, version):
distribution = "setuptools"
wheel = get_wheel(distribution, version, for_py_version, [], True, session_app_data, False, os.environ)
assert wheel is not None
assert wheel.name == downloaded_wheel.name


@pytest.mark.parametrize("version", ["embed", "pinned"])
def test_get_wheel_download_not_called(for_py_version, session_app_data, downloaded_wheel, version):
distribution = "setuptools"
expected = get_embed_wheel(distribution, for_py_version)
if version == "pinned":
version = expected.version
wheel = get_wheel(distribution, version, for_py_version, [], True, session_app_data, False, os.environ)
assert wheel is not None
assert wheel.name == expected.name

0 comments on commit 61c065b

Please sign in to comment.