From cdf4225c689150010af8da1cc913e8f32bee06d2 Mon Sep 17 00:00:00 2001 From: schaap <cybermonktitan@gmail.com> Date: Sat, 8 Oct 2022 02:15:06 +0200 Subject: [PATCH] Allow empty string as version for `find_compatible_in_house` (#2430) The empty string is used in several locations to indicate the newest version. Interpret it as such instead of rejecting it as invalid. --- docs/changelog/2429.bugfix.rst | 1 + src/virtualenv/seed/wheels/acquire.py | 2 +- tests/unit/seed/wheels/test_acquire_find_wheel.py | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/2429.bugfix.rst diff --git a/docs/changelog/2429.bugfix.rst b/docs/changelog/2429.bugfix.rst new file mode 100644 index 000000000..7e79e3612 --- /dev/null +++ b/docs/changelog/2429.bugfix.rst @@ -0,0 +1 @@ +Fix fallback handling of downloading wheels for bundled packages - by :user:`schaap`. diff --git a/src/virtualenv/seed/wheels/acquire.py b/src/virtualenv/seed/wheels/acquire.py index d8e8d1e38..d1fb3f389 100644 --- a/src/virtualenv/seed/wheels/acquire.py +++ b/src/virtualenv/seed/wheels/acquire.py @@ -83,7 +83,7 @@ def _find_downloaded_wheel(distribution, version_spec, for_py_version, to_folder def find_compatible_in_house(distribution, version_spec, for_py_version, in_folder): wheels = discover_wheels(in_folder, distribution, None, for_py_version) start, end = 0, len(wheels) - if version_spec is not None: + if version_spec is not None and version_spec != "": if version_spec.startswith("<"): from_pos, op = 1, lt elif version_spec.startswith("=="): diff --git a/tests/unit/seed/wheels/test_acquire_find_wheel.py b/tests/unit/seed/wheels/test_acquire_find_wheel.py index a4a28de8b..6ca1f2276 100644 --- a/tests/unit/seed/wheels/test_acquire_find_wheel.py +++ b/tests/unit/seed/wheels/test_acquire_find_wheel.py @@ -4,12 +4,18 @@ from virtualenv.seed.wheels.embed import BUNDLE_FOLDER, MAX, get_embed_wheel -def test_find_latest(for_py_version): +def test_find_latest_none(for_py_version): result = find_compatible_in_house("setuptools", None, for_py_version, BUNDLE_FOLDER) expected = get_embed_wheel("setuptools", for_py_version) assert result.path == expected.path +def test_find_latest_string(for_py_version): + result = find_compatible_in_house("setuptools", "", for_py_version, BUNDLE_FOLDER) + expected = get_embed_wheel("setuptools", for_py_version) + assert result.path == expected.path + + def test_find_exact(for_py_version): expected = get_embed_wheel("setuptools", for_py_version) result = find_compatible_in_house("setuptools", f"=={expected.version}", for_py_version, BUNDLE_FOLDER)