Skip to content

Commit 8def63a

Browse files
jlarkin09claude
authored andcommitted
fix(finders): filter find_wheel glob to .whl files only
find_wheel() used glob("*") which could match non-wheel files like .tar.gz or .metadata, causing InvalidWheelFilename crashes downstream in extract_info_from_wheel_file. Narrow the glob to "*.whl" so only wheel files are considered. Closes: #1067 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Justin Larkin <jlarkin@redhat.com> Made-with: Cursor
1 parent ae65fdb commit 8def63a

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/fromager/finders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def find_wheel(
138138
# comparison.
139139
for base in candidate_bases:
140140
logger.debug('looking for wheel as "%s"', base)
141-
for filename in downloads_dir.glob("*"):
141+
for filename in downloads_dir.glob("*.whl"):
142142
if str(filename.name).lower().startswith(base.lower()):
143143
return filename
144144

tests/test_finders.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ def test_find_wheel(
5858
assert str(wheel) == str(actual)
5959

6060

61+
def test_find_wheel_ignores_non_wheel_files(tmp_path: pathlib.Path) -> None:
62+
downloads = tmp_path / "downloads"
63+
downloads.mkdir()
64+
wheel = downloads / "mypkg-1.2-py3-none-any.whl"
65+
wheel.write_text("not-empty")
66+
(downloads / "mypkg-1.2-py3-none-any.tar.gz").write_text("not-a-wheel")
67+
(downloads / "mypkg-1.2.metadata").write_text("not-a-wheel")
68+
69+
req = Requirement("mypkg")
70+
actual = finders.find_wheel(downloads, req, "1.2", ())
71+
assert str(wheel) == str(actual)
72+
73+
74+
def test_find_wheel_returns_none_when_only_non_wheel_files(
75+
tmp_path: pathlib.Path,
76+
) -> None:
77+
downloads = tmp_path / "downloads"
78+
downloads.mkdir()
79+
(downloads / "mypkg-1.2-py3-none-any.tar.gz").write_text("not-a-wheel")
80+
(downloads / "mypkg-1.2.metadata").write_text("not-a-wheel")
81+
82+
req = Requirement("mypkg")
83+
assert finders.find_wheel(downloads, req, "1.2", ()) is None
84+
85+
6186
@pytest.mark.parametrize(
6287
"dist_name,version_string,unpack_base,source_base",
6388
[

0 commit comments

Comments
 (0)