Skip to content

Commit 1a691ee

Browse files
committed
fix: require sorted tags in strict mode
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent 997c5a8 commit 1a691ee

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

docs/filenames.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Filenames
33

44
Tools to work with filenames for SDists and wheels.
55

6+
.. versionadded:: 26.1
7+
68
Reference
79
---------
810

src/packaging/filenames.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,17 @@ def from_filename(cls, filename: str, /, *, strict: bool) -> WheelFilename:
383383
inner = f"non-normalized project name {self.original_name!r}"
384384
msg = f"Invalid wheel filename ({inner}): {filename!r}"
385385
raise InvalidWheelFilename(msg)
386+
386387
if self.original_version != str(self.version):
387388
inner = f"non-normalized version {self.original_version!r}"
388389
msg = f"Invalid wheel filename ({inner}): {filename!r}"
389390
raise InvalidWheelFilename(msg)
390391

392+
if self.compressed_tags != parts[-1]:
393+
inner = f"non-normalized tags {parts[-1]!r}"
394+
msg = f"Invalid wheel filename ({inner}): {filename!r}"
395+
raise InvalidWheelFilename(msg)
396+
391397
return self
392398

393399

tests/test_filenames.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ def test_sdist_from_filename_invalid(filename: str, error_message: str) -> None:
131131
(1000, "abc"),
132132
{Tag("py3", "none", "any")},
133133
),
134+
(
135+
"foo-1.0-py2.py3-none-any.whl", # Sorted multiple interpreter tags
136+
"foo",
137+
Version("1.0"),
138+
(),
139+
{Tag("py2", "none", "any"), Tag("py3", "none", "any")},
140+
),
141+
( # Sorted multiple platform tags
142+
"numpy-1.23.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
143+
"numpy",
144+
Version("1.23.3"),
145+
(),
146+
{
147+
Tag("cp310", "cp310", "manylinux2014_x86_64"),
148+
Tag("cp310", "cp310", "manylinux_2_17_x86_64"),
149+
},
150+
),
134151
],
135152
)
136153
def test_wheel_from_filename(
@@ -183,6 +200,16 @@ def test_wheel_from_filename(
183200
"foo-01.0-py3-none-any.whl", # Non-normalized version
184201
"Invalid wheel filename (non-normalized version '01.0')",
185202
),
203+
( # Unsorted interpreter tags (py3 before py2)
204+
"foo-1.0-py3.py2-none-any.whl",
205+
"Invalid wheel filename (non-normalized tags 'py3.py2-none-any')",
206+
),
207+
(
208+
# Unsorted platform tags (manylinux_ before manylinux2014)
209+
"numpy-1.23.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
210+
"Invalid wheel filename (non-normalized tags "
211+
"'cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64')",
212+
),
186213
],
187214
)
188215
def test_wheel_from_filename_invalid(filename: str, error_message: str) -> None:

0 commit comments

Comments
 (0)