Skip to content

Commit

Permalink
Moving position of ctx parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rd4398 committed Aug 7, 2024
1 parent dd3080f commit c3e7436
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/fromager/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}")
Expand Down
8 changes: 4 additions & 4 deletions src/fromager/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
)


Expand Down

0 comments on commit c3e7436

Please sign in to comment.