Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/fromager/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ def default_download_source(
url = pbi.download_source_url(version=version, default=download_url)
if url is None:
raise ValueError(f"Could not determine download URL for {req}")
if destination_filename is None:
url_filename = resolver.extract_filename_from_url(url)
if url_filename.endswith(".zip"):
destination_filename = f"{pbi.override_module_name}-{version}.zip"
else:
destination_filename = f"{pbi.override_module_name}-{version}.tar.gz"
logger.debug(
"config has no destination_filename, use default %r", destination_filename
)
source_filename = _download_source_check(
req=req,
destination_dir=sdists_downloads_dir,
Expand Down
42 changes: 42 additions & 0 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,48 @@ def test_patch_sources_apply_only_unversioned(
apply_patch.assert_called_once_with(req, unversioned_patch_file, source_root_dir)


@pytest.mark.parametrize(
"pkg,version_str,url,expected_filename",
[
(
"mlserver-sklearn==1.6.0",
"1.6.0",
"https://github.test/SeldonIO/MLServer/archive/refs/tags/1.6.0.tar.gz",
"mlserver_sklearn-1.6.0.tar.gz",
),
(
"some-pkg==2.0",
"2.0",
"https://github.test/owner/repo/archive/refs/tags/v2.0.zip",
"some_pkg-2.0.zip",
),
],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
)
@patch("fromager.sources._download_source_check")
def test_default_download_source_no_destination_filename(
download_source_check: Mock,
tmp_context: context.WorkContext,
pkg: str,
version_str: str,
url: str,
expected_filename: str,
) -> None:
"""When no destination_filename is configured, use PEP 625 normalized name."""
req = Requirement(pkg)
version = Version(version_str)

sources.default_download_source(
tmp_context, req, version, url, tmp_context.sdists_downloads
)

download_source_check.assert_called_with(
req=req,
destination_dir=tmp_context.sdists_downloads,
url=url,
destination_filename=expected_filename,
)


@patch("fromager.sources.vendor_rust.vendor_rust")
@patch("fromager.sources.pyproject.apply_project_override")
@patch("fromager.sources.patch_source")
Expand Down
Loading