Skip to content

Commit eb69a95

Browse files
authored
Merge pull request #514 from shubhbapna/validate-wheel
check whether downloaded wheel is valid or not
2 parents 48a51df + 1a51d11 commit eb69a95

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/fromager/wheels.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import elfdeps
1717
import tomlkit
18+
import wheel.wheelfile # type: ignore
1819
from packaging.requirements import Requirement
1920
from packaging.tags import Tag
2021
from packaging.utils import BuildTag, canonicalize_name, parse_wheel_filename
@@ -361,14 +362,10 @@ def download_wheel(
361362
return wheel_filename
362363

363364

364-
# Helper method to check whether the .whl file is a zip file and has contents in it.
365-
# It will throw BadZipFile exception if any other file is encountered. Eg: index.html
366365
def _download_wheel_check(destination_dir, wheel_url):
367366
wheel_filename = sources.download_url(destination_dir, wheel_url)
368-
wheel_directory_contents = zipfile.ZipFile(wheel_filename).namelist()
369-
if not wheel_directory_contents:
370-
raise zipfile.BadZipFile(f"Empty zip file encountered: {wheel_filename}")
371-
367+
# validates whether the wheel is correct or not. will raise an error in the wheel is invalid
368+
wheel.wheelfile.WheelFile(wheel_filename)
372369
return wheel_filename
373370

374371

tests/test_wheels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pathlib
2-
import zipfile
32
from unittest.mock import patch
43

54
import pytest
5+
import wheel.cli # type: ignore
66

77
from fromager import wheels
88

@@ -15,5 +15,5 @@ def test_invalid_wheel_file_exception(mock_download_url, tmp_path: pathlib.Path)
1515
fake_dir.mkdir()
1616
text_file = fake_dir / "fake_wheel.txt"
1717
text_file.write_text("This is a test file")
18-
with pytest.raises(zipfile.BadZipFile):
18+
with pytest.raises(wheel.cli.WheelError):
1919
wheels._download_wheel_check(fake_dir, fake_url)

0 commit comments

Comments
 (0)