Skip to content

Commit 0c4cdf9

Browse files
committed
Break up different exceptions and report specific error
1 parent 9fd6b86 commit 0c4cdf9

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/pip/_internal/models/wheel.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ def __init__(self, filename: str) -> None:
3939
self.name = wheel_info.group("name").replace("_", "-")
4040
_version = wheel_info.group("ver")
4141
if "_" in _version:
42-
_version = _version.replace("_", "-")
43-
4442
try:
4543
parse_wheel_filename(filename)
46-
except (PackagingInvalidWheelName, InvalidVersion):
44+
except InvalidVersion as e:
4745
deprecated(
4846
reason=(
49-
f"Wheel filename {filename!r} uses an invalid filename format, "
50-
f"as the version part {_version!r} is not correctly "
51-
"normalised, and contains an underscore character. Future "
52-
"versions of pip will fail to recognise this wheel."
47+
f"Wheel filename version part {_version!r} is not correctly "
48+
"normalised, and contained an underscore character in the "
49+
"version part. Future versions of pip will fail to recognise "
50+
f"this wheel and report the error: {e.args[0]}."
5351
),
5452
replacement=(
5553
"rename the wheel to use a correctly normalised "
@@ -59,6 +57,23 @@ def __init__(self, filename: str) -> None:
5957
gone_in="25.1",
6058
issue=12938,
6159
)
60+
except PackagingInvalidWheelName as e:
61+
deprecated(
62+
reason=(
63+
f"The wheel filename {filename!r} is not correctly normalised. "
64+
"Future versions of pip will fail to recognise this wheel. "
65+
f"and report the error: {e.args[0]}."
66+
),
67+
replacement=(
68+
"rename the wheel to use a correctly normalised "
69+
"name (this may require updating the version in "
70+
"the project metadata)"
71+
),
72+
gone_in="25.1",
73+
issue=12938,
74+
)
75+
76+
_version = _version.replace("_", "-")
6277

6378
self.version = _version
6479
self.build_tag = wheel_info.group("build")

0 commit comments

Comments
 (0)