diff --git a/src/fromager/sdist.py b/src/fromager/sdist.py index 92861c1c..8d6a838d 100644 --- a/src/fromager/sdist.py +++ b/src/fromager/sdist.py @@ -311,7 +311,7 @@ def download_wheel( wheel_filename = output_directory / os.path.basename(urlparse(wheel_url).path) if not wheel_filename.exists(): logger.info(f"{req.name}: downloading pre-built wheel {wheel_url}") - wheel_filename = _download_wheel_check(output_directory, wheel_url, ctx) + wheel_filename = _download_wheel_check(ctx, output_directory, wheel_url) logger.info(f"{req.name}: saved wheel to {wheel_filename}") else: logger.info(f"{req.name}: have existing wheel {wheel_filename}") @@ -321,8 +321,8 @@ def download_wheel( # Helper method to check whether the .whl file is a zip file and has contents in it. # It will throw BadZipFile exception if any other file is encountered. Eg: index.html -def _download_wheel_check(destination_dir, wheel_url, ctx): - wheel_filename = sources.download_url(destination_dir, wheel_url, ctx) +def _download_wheel_check(ctx, destination_dir, wheel_url): + wheel_filename = sources.download_url(ctx, destination_dir, wheel_url) wheel_directory_contents = zipfile.ZipFile(wheel_filename).namelist() if not wheel_directory_contents: raise zipfile.BadZipFile(f"Empty zip file encountered: {wheel_filename}") diff --git a/src/fromager/sources.py b/src/fromager/sources.py index aec90ba6..0d8d0e56 100644 --- a/src/fromager/sources.py +++ b/src/fromager/sources.py @@ -164,7 +164,7 @@ def default_download_source( ) source_filename = _download_source_check( - ctx.sdists_downloads, url, ctx, destination_filename + ctx, ctx.sdists_downloads, url, destination_filename ) logger.debug( @@ -176,12 +176,12 @@ def default_download_source( # Helper method to check whether .zip /.tar / .tgz is able to extract and check its content. # It will throw exception if any other file is encountered. Eg: index.html def _download_source_check( + ctx: context.WorkContext, destination_dir: pathlib.Path, url: str, - ctx: context.WorkContext, destination_filename: str | None = None, ) -> str: - source_filename = download_url(destination_dir, url, ctx, destination_filename) + source_filename = download_url(ctx, destination_dir, url, destination_filename) if source_filename.suffix == ".zip": source_file_contents = zipfile.ZipFile(source_filename).namelist() if not source_file_contents: @@ -199,9 +199,9 @@ def _download_source_check( def download_url( + ctx: context.WorkContext, destination_dir: pathlib.Path, url: str, - ctx: context.WorkContext, destination_filename: str | None = None, ) -> pathlib.Path: basename = ( diff --git a/tests/test_sdist.py b/tests/test_sdist.py index f26a0646..91b5c2d0 100644 --- a/tests/test_sdist.py +++ b/tests/test_sdist.py @@ -59,4 +59,4 @@ def test_invalid_wheel_file_exception(mock_download_url, tmp_path: pathlib.Path) text_file = fake_dir / "fake_wheel.txt" text_file.write_text("This is a test file") with pytest.raises(zipfile.BadZipFile): - sdist._download_wheel_check(fake_dir, fake_url, tmp_context) + sdist._download_wheel_check(tmp_context, fake_dir, fake_url) diff --git a/tests/test_sources.py b/tests/test_sources.py index e5ca2b18..b7bb093e 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -18,7 +18,7 @@ def test_invalid_tarfile( text_file = fake_dir / "fake_wheel.txt" text_file.write_text("This is a test file") with pytest.raises(TypeError): - sources._download_source_check(fake_dir, fake_url, tmp_context) + sources._download_source_check(tmp_context, fake_dir, fake_url) @patch("fromager.sources.resolve_dist") @@ -43,7 +43,7 @@ def test_default_download_source_from_settings( resolve_dist.assert_called_with(tmp_context, req, sdist_server_url, True, False) download_source_check.assert_called_with( - tmp_context.sdists_downloads, "predefined_url-1.0", tmp_context, "foo-1.0" + tmp_context, tmp_context.sdists_downloads, "predefined_url-1.0", "foo-1.0" )