From aa25c97732825d3f9adf22e3f319e439e807863d Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 25 Aug 2024 14:59:13 -0400 Subject: [PATCH 1/3] Update non PEP 440 wheel filename deprecation notice --- src/pip/_internal/models/wheel.py | 40 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/pip/_internal/models/wheel.py b/src/pip/_internal/models/wheel.py index 63db978f1f5..27a80e92e27 100644 --- a/src/pip/_internal/models/wheel.py +++ b/src/pip/_internal/models/wheel.py @@ -6,6 +6,13 @@ from typing import Dict, Iterable, List from pip._vendor.packaging.tags import Tag +from pip._vendor.packaging.utils import ( + InvalidVersion, + parse_wheel_filename, +) +from pip._vendor.packaging.utils import ( + InvalidWheelFilename as PackagingInvalidWheelName, +) from pip._internal.exceptions import InvalidWheelFilename from pip._internal.utils.deprecation import deprecated @@ -32,22 +39,27 @@ def __init__(self, filename: str) -> None: self.name = wheel_info.group("name").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("_", "-") + try: + parse_wheel_filename(filename) + except (PackagingInvalidWheelName, InvalidVersion): + 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 will 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=12938, + ) + self.version = _version self.build_tag = wheel_info.group("build") self.pyversions = wheel_info.group("pyver").split(".") From fbe7924ad45bd8de4f8b662741d50da678ff511e Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 25 Aug 2024 15:06:26 -0400 Subject: [PATCH 2/3] NEWS ENTRY --- news/12939.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/12939.trivial.rst diff --git a/news/12939.trivial.rst b/news/12939.trivial.rst new file mode 100644 index 00000000000..c9acd4f8c54 --- /dev/null +++ b/news/12939.trivial.rst @@ -0,0 +1 @@ +Update non PEP 440 wheel filename deprecation notice. From 0c4cdf93fa514ecdfe2ee8dd8b3c304c195accbe Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sat, 12 Oct 2024 11:24:42 -0400 Subject: [PATCH 3/3] Break up different exceptions and report specific error --- src/pip/_internal/models/wheel.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/models/wheel.py b/src/pip/_internal/models/wheel.py index 27a80e92e27..67318ae55a8 100644 --- a/src/pip/_internal/models/wheel.py +++ b/src/pip/_internal/models/wheel.py @@ -39,17 +39,15 @@ def __init__(self, filename: str) -> None: self.name = wheel_info.group("name").replace("_", "-") _version = wheel_info.group("ver") if "_" in _version: - _version = _version.replace("_", "-") - try: parse_wheel_filename(filename) - except (PackagingInvalidWheelName, InvalidVersion): + except InvalidVersion as e: 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 will fail to recognise this wheel." + f"Wheel filename version part {_version!r} is not correctly " + "normalised, and contained an underscore character in the " + "version part. Future versions of pip will fail to recognise " + f"this wheel and report the error: {e.args[0]}." ), replacement=( "rename the wheel to use a correctly normalised " @@ -59,6 +57,23 @@ def __init__(self, filename: str) -> None: gone_in="25.1", issue=12938, ) + except PackagingInvalidWheelName as e: + deprecated( + reason=( + f"The wheel filename {filename!r} is not correctly normalised. " + "Future versions of pip will fail to recognise this wheel. " + f"and report the error: {e.args[0]}." + ), + replacement=( + "rename the wheel to use a correctly normalised " + "name (this may require updating the version in " + "the project metadata)" + ), + gone_in="25.1", + issue=12938, + ) + + _version = _version.replace("_", "-") self.version = _version self.build_tag = wheel_info.group("build")