diff --git a/src/lightwell_python/config.py b/src/lightwell_python/config.py index 57bfba8..0bc64a6 100644 --- a/src/lightwell_python/config.py +++ b/src/lightwell_python/config.py @@ -105,7 +105,12 @@ def render_settings(self, path: Path, package: Package, computed: str) -> None: """Write per-package Fromager YAML for this build. PURL metadata records both upstream and computed versions. A changelog entry - forces a rebuild. The stored config settings are copied before modification. + forces a rebuild. The download_source destination filename is pinned to the + name create_sdist() already writes into the pre-placed sdist cache, so Fromager + finds our version-rewritten archive instead of deriving a cache filename from + the upstream index URL's extension (which may not be .tar.gz, e.g. zip-sdist + packages such as h11 <= 0.7.0 -- see LWLP-5506). The stored config settings are + copied before modification. Args: path: YAML destination; missing parent directories are created. @@ -113,13 +118,20 @@ def render_settings(self, path: Path, package: Package, computed: str) -> None: computed: Expected version of the built wheel. Raises: - TaskError: PURL/changelog settings have incompatible types. + TaskError: PURL/changelog/download_source settings have incompatible types. """ settings = copy.deepcopy(self.settings) purl = settings.setdefault("purl", {}) changelog = settings.setdefault("changelog", {}) - if not isinstance(purl, dict) or not isinstance(changelog, dict): - raise TaskError("Fromager purl and changelog settings must be mappings") + download_source = settings.setdefault("download_source", {}) + if ( + not isinstance(purl, dict) + or not isinstance(changelog, dict) + or not isinstance(download_source, dict) + ): + raise TaskError( + "Fromager purl, changelog, and download_source settings must be mappings" + ) purl.update( version=computed, upstream=f"pkg:pypi/{package.name}@{quote(package.version, safe='')}" ) @@ -127,6 +139,9 @@ def render_settings(self, path: Path, package: Package, computed: str) -> None: if not isinstance(entries, list): raise TaskError("Fromager changelog entries must be lists") entries.append(f"Lightwell build for {package.requirement}") + download_source.setdefault( + "destination_filename", "${canonicalized_name}-${version}.tar.gz" + ) path.parent.mkdir(parents=True, exist_ok=True) path.write_text(yaml.safe_dump(settings, sort_keys=False), encoding="utf-8") diff --git a/tests/unit/test_tasks.py b/tests/unit/test_tasks.py index 80bbfc5..28e704a 100644 --- a/tests/unit/test_tasks.py +++ b/tests/unit/test_tasks.py @@ -491,3 +491,74 @@ def test_canonical_source_version_match_without_override_falls_back_to_package_d write_json(path, package_config) config = BuildConfig.load(path, Package("demo", "1.0")) assert config.canonical_source == {"type": "pypi-sdist"} + + +def test_render_settings_pins_download_source_destination_filename(tmp_path, package_config): + """LWLP-5506: force Fromager onto the pre-placed sdist regardless of the + + upstream index's advertised extension (e.g. zip-sdist packages like h11 <= 0.7.0), + instead of deriving a cache filename from the resolved download URL. + """ + import yaml + + from lightwell_python.config import BuildConfig + + path = tmp_path / "demo.json" + write_json(path, package_config) + config = BuildConfig.load(path, Package("demo", "1.0")) + + settings_path = tmp_path / "demo.yaml" + config.render_settings(settings_path, Package("demo", "1.0"), "1.0+rhlw.1") + + rendered = yaml.safe_load(settings_path.read_text()) + assert rendered["download_source"] == { + "destination_filename": "${canonicalized_name}-${version}.tar.gz" + } + + +def test_render_settings_respects_existing_download_source_override(tmp_path, package_config): + """A build config that already overrides download_source (e.g. for a package + + fetched from an alternate source such as a GitHub release) keeps its own + settings rather than being clobbered by the LWLP-5506 default. + """ + import yaml + + from lightwell_python.config import BuildConfig + + package_config["version_configs"] = { + "1.0": { + "fromager_settings": { + "download_source": { + "url": "https://example.test/demo-1.0.tar.gz", + "destination_filename": "demo-custom.tar.gz", + } + } + } + } + path = tmp_path / "demo.json" + write_json(path, package_config) + config = BuildConfig.load(path, Package("demo", "1.0")) + + settings_path = tmp_path / "demo.yaml" + config.render_settings(settings_path, Package("demo", "1.0"), "1.0+rhlw.1") + + rendered = yaml.safe_load(settings_path.read_text()) + assert rendered["download_source"] == { + "url": "https://example.test/demo-1.0.tar.gz", + "destination_filename": "demo-custom.tar.gz", + } + + +def test_render_settings_rejects_non_mapping_download_source(tmp_path, package_config): + from lightwell_python.config import BuildConfig + + package_config["version_configs"] = { + "1.0": {"fromager_settings": {"download_source": "not-a-mapping"}} + } + path = tmp_path / "demo.json" + write_json(path, package_config) + config = BuildConfig.load(path, Package("demo", "1.0")) + + with pytest.raises(TaskError, match="download_source"): + config.render_settings(tmp_path / "demo.yaml", Package("demo", "1.0"), "1.0+rhlw.1")