Skip to content

Commit

Permalink
Merge pull request #12918 from notatallshaw/depricate---in-version-of…
Browse files Browse the repository at this point in the history
…-wheel-filename

Deprecate wheel filenames that are not compliant with PEP 440
  • Loading branch information
sbidoul committed Aug 22, 2024
2 parents 4f4ae38 + 2c792b6 commit 81041f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/12918.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate wheel filenames that are not compliant with PEP 440.
23 changes: 20 additions & 3 deletions src/pip/_internal/models/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pip._vendor.packaging.tags import Tag

from pip._internal.exceptions import InvalidWheelFilename
from pip._internal.utils.deprecation import deprecated


class Wheel:
Expand All @@ -29,9 +30,25 @@ def __init__(self, filename: str) -> None:
raise InvalidWheelFilename(f"{filename} is not a valid wheel filename.")
self.filename = filename
self.name = wheel_info.group("name").replace("_", "-")
# we'll assume "_" means "-" due to wheel naming scheme
# (https://github.com/pypa/pip/issues/1150)
self.version = wheel_info.group("ver").replace("_", "-")
_version = wheel_info.group("ver")
if "_" in _version:
deprecated(
reason=(
f"Wheel filename {filename!r} uses an invalid filename format, "
f"as the version part {_version!r} is not correctly normalised, "
"and contains an underscore character. Future versions of pip may "
"fail to recognise this wheel."
),
replacement=(
"rename the wheel to use a correctly normalised version part "
"(this may require updating the version in the project metadata)"
),
gone_in="25.1",
issue=12914,
)
_version = _version.replace("_", "-")

self.version = _version
self.build_tag = wheel_info.group("build")
self.pyversions = wheel_info.group("pyver").split(".")
self.abis = wheel_info.group("abi").split(".")
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_models_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pip._internal.exceptions import InvalidWheelFilename
from pip._internal.models.wheel import Wheel
from pip._internal.utils import compatibility_tags
from pip._internal.utils import compatibility_tags, deprecation


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

0 comments on commit 81041f7

Please sign in to comment.