Skip to content

Commit 81041f7

Browse files
authored
Merge pull request #12918 from notatallshaw/depricate---in-version-of-wheel-filename
Deprecate wheel filenames that are not compliant with PEP 440
2 parents 4f4ae38 + 2c792b6 commit 81041f7

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

news/12918.removal.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate wheel filenames that are not compliant with PEP 440.

src/pip/_internal/models/wheel.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pip._vendor.packaging.tags import Tag
99

1010
from pip._internal.exceptions import InvalidWheelFilename
11+
from pip._internal.utils.deprecation import deprecated
1112

1213

1314
class Wheel:
@@ -29,9 +30,25 @@ def __init__(self, filename: str) -> None:
2930
raise InvalidWheelFilename(f"{filename} is not a valid wheel filename.")
3031
self.filename = filename
3132
self.name = wheel_info.group("name").replace("_", "-")
32-
# we'll assume "_" means "-" due to wheel naming scheme
33-
# (https://github.com/pypa/pip/issues/1150)
34-
self.version = wheel_info.group("ver").replace("_", "-")
33+
_version = wheel_info.group("ver")
34+
if "_" in _version:
35+
deprecated(
36+
reason=(
37+
f"Wheel filename {filename!r} uses an invalid filename format, "
38+
f"as the version part {_version!r} is not correctly normalised, "
39+
"and contains an underscore character. Future versions of pip may "
40+
"fail to recognise this wheel."
41+
),
42+
replacement=(
43+
"rename the wheel to use a correctly normalised version part "
44+
"(this may require updating the version in the project metadata)"
45+
),
46+
gone_in="25.1",
47+
issue=12914,
48+
)
49+
_version = _version.replace("_", "-")
50+
51+
self.version = _version
3552
self.build_tag = wheel_info.group("build")
3653
self.pyversions = wheel_info.group("pyver").split(".")
3754
self.abis = wheel_info.group("abi").split(".")

tests/unit/test_models_wheel.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pip._internal.exceptions import InvalidWheelFilename
55
from pip._internal.models.wheel import Wheel
6-
from pip._internal.utils import compatibility_tags
6+
from pip._internal.utils import compatibility_tags, deprecation
77

88

99
class TestWheelFile:
@@ -175,5 +175,6 @@ def test_version_underscore_conversion(self) -> None:
175175
Test that we convert '_' to '-' for versions parsed out of wheel
176176
filenames
177177
"""
178-
w = Wheel("simple-0.1_1-py2-none-any.whl")
178+
with pytest.warns(deprecation.PipDeprecationWarning):
179+
w = Wheel("simple-0.1_1-py2-none-any.whl")
179180
assert w.version == "0.1-1"

0 commit comments

Comments
 (0)