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. diff --git a/src/pip/_internal/models/wheel.py b/src/pip/_internal/models/wheel.py index 63db978f1f5..67318ae55a8 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,20 +39,40 @@ 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, - ) + try: + parse_wheel_filename(filename) + except InvalidVersion as e: + deprecated( + reason=( + 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 " + "version part (this may require updating the version " + "in the project metadata)" + ), + 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