From 59311c1e7aa792000587afaca4272acbe80915f7 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 20 Nov 2026 10:11:14 +0100 Subject: [PATCH] feat(sources): add explicit tarball sdist-base strategies Replace the ambiguous `build_sdist: tarball` with `tarball-build-dir` (pack the wheel build directory) and `tarball-root-dir` (pack the whole source tree). Keep `tarball` as a deprecated alias of `tarball-build-dir`, normalized with a warning during settings validation. Fixes: #1478 Co-Authored-By: Claude Signed-off-by: Christian Heimes --- docs/concepts/resolver-architecture.rst | 19 ++- docs/reference/config-reference.rst | 16 ++- docs/reference/hooks.rst | 2 +- e2e/source_settings_hook_sdist/stevedore.yaml | 2 +- src/fromager/packagesettings/_models.py | 5 +- src/fromager/packagesettings/_resolver.py | 49 ++++++- src/fromager/sources.py | 42 +++++- tests/test_commands.py | 5 +- tests/test_packagesettings.py | 12 ++ tests/test_packagesettings_resolver.py | 35 +++-- tests/test_sources.py | 126 ++++++++++++++++-- 11 files changed, 269 insertions(+), 44 deletions(-) diff --git a/docs/concepts/resolver-architecture.rst b/docs/concepts/resolver-architecture.rst index 72a1ab28..de56a60e 100644 --- a/docs/concepts/resolver-architecture.rst +++ b/docs/concepts/resolver-architecture.rst @@ -212,22 +212,31 @@ Building the Sdist Git checkouts can be prepared directly. Configured source resolvers also select the sdist build method. -For source builds, ``source.build_sdist`` selects one of three methods: +For source builds, ``source.build_sdist`` selects one of four methods: - ``pep517`` builds the sdist with the package's build backend. Git checkout resolvers default to it. -- ``tarball`` repacks the prepared source without VCS metadata such as - ``.git``. ``pypi-sdist`` and ``pypi-download`` default to it. +- ``tarball-build-dir`` repacks the wheel build directory without VCS + metadata such as ``.git``. ``pypi-sdist`` and ``pypi-download`` default + to it. This is the behaviour of the deprecated ``tarball`` value. +- ``tarball-root-dir`` repacks the whole prepared source tree without VCS + metadata such as ``.git``. Use it when the wheel builds from a + subdirectory but the sdist must ship the full tree, as with a native + library at the repository root. - ``hook`` runs the package's ``build_sdist`` override hook, which can generate files or choose which directory to pack. +``tarball`` remains a deprecated alias of ``tarball-build-dir``. Settings +loading normalizes it to ``tarball-build-dir`` and logs a warning. It will +be removed in the future. + The choice follows these rules: - ``hook`` requires an installed, callable hook. If it is missing, the build fails before downloading the source. A cached wheel needs no hook, so it is used without the check. -- A configured ``pep517`` or ``tarball`` skips an installed hook with a - warning. +- A configured ``pep517`` or ``tarball-*`` strategy skips an installed + hook with a warning. - Without ``source:``, the hook runs when present; otherwise the default method is used. - ``hook-sdist`` has no default and always needs an explicit setting. diff --git a/docs/reference/config-reference.rst b/docs/reference/config-reference.rst index 24ce5cb0..43b0e45f 100644 --- a/docs/reference/config-reference.rst +++ b/docs/reference/config-reference.rst @@ -85,14 +85,26 @@ Source Resolver .. autoclass:: BuildSDist .. autoattribute:: pep517 + .. autoattribute:: tarball_build_dir + .. autoattribute:: tarball_root_dir .. autoattribute:: tarball .. autoattribute:: hook .. versionchanged:: 0.104.0 ``pypi-sdist`` and ``pypi-download`` accept an explicit - ``build_sdist: pep517``. Their default remains ``tarball`` because some - build backends require VCS metadata that source archives do not contain. + ``build_sdist: pep517``. Their default remains tarball repacking because + some build backends require VCS metadata that source archives do not + contain. + +.. versionchanged:: 0.105.0 + + ``tarball`` is split into ``tarball-build-dir`` (pack the wheel build + directory, the previous behaviour) and ``tarball-root-dir`` (pack the + whole source tree). ``tarball`` remains a deprecated alias of + ``tarball-build-dir`` and is normalized with a warning when settings + load. It will be removed in the future. ``pypi-sdist`` and + ``pypi-download`` now default to ``tarball-build-dir``. .. autoclass:: DownloadedSource :members: path, kind diff --git a/docs/reference/hooks.rst b/docs/reference/hooks.rst index acee8ac4..0bec8e79 100644 --- a/docs/reference/hooks.rst +++ b/docs/reference/hooks.rst @@ -391,7 +391,7 @@ Source hooks build_sdist: hook The hook must be installed. Without it, the build fails before - downloading the source. ``pep517`` and ``tarball`` ignore the hook and log a + downloading the source. ``pep517`` and ``tarball-*`` ignore the hook and log a warning. Packages without ``source:`` use the hook when it exists. Any profile that builds from source can select ``hook``. diff --git a/e2e/source_settings_hook_sdist/stevedore.yaml b/e2e/source_settings_hook_sdist/stevedore.yaml index 0e95dd12..b976f3e7 100644 --- a/e2e/source_settings_hook_sdist/stevedore.yaml +++ b/e2e/source_settings_hook_sdist/stevedore.yaml @@ -1,6 +1,6 @@ source: provider: hook-sdist - build_sdist: tarball + build_sdist: tarball-build-dir # GitHub archives have no git metadata for pbr to determine the version. env: PBR_VERSION: "${__version__}" diff --git a/src/fromager/packagesettings/_models.py b/src/fromager/packagesettings/_models.py index 33991505..961137e9 100644 --- a/src/fromager/packagesettings/_models.py +++ b/src/fromager/packagesettings/_models.py @@ -770,7 +770,10 @@ def from_mapping( """Load from a dict""" package = Package(canonicalize_name(package, validate=True)) try: - return cls(name=package, has_config=has_config, **parsed) + return cls.model_validate( + {**parsed, "name": package, "has_config": has_config}, + context={"package": package, "source": source}, + ) except Exception as err: raise RuntimeError( f"{package}: failed to load settings (source: {source!r}): {err}" diff --git a/src/fromager/packagesettings/_resolver.py b/src/fromager/packagesettings/_resolver.py index 402fb7d4..07dcd3f6 100644 --- a/src/fromager/packagesettings/_resolver.py +++ b/src/fromager/packagesettings/_resolver.py @@ -31,7 +31,24 @@ class BuildSDist(enum.StrEnum): """Source distribution build method.""" pep517 = "pep517" + tarball_build_dir = "tarball-build-dir" + """Repack the package's wheel build directory. + + .. versionadded:: 0.105.0 + """ + tarball_root_dir = "tarball-root-dir" + """Repack the whole prepared source tree without VCS metadata such as + ``.git``. + + .. versionadded:: 0.105.0 + """ tarball = "tarball" + """Deprecated alias of ``tarball-build-dir``. + + .. deprecated:: 0.105.0 + Use ``tarball-build-dir`` or ``tarball-root-dir``. This value will be + removed in the future. + """ hook = "hook" """Call the package's ``build_sdist`` override hook. @@ -93,6 +110,25 @@ class AbstractResolver(pydantic.BaseModel): resolves_prebuilt_wheel: typing.ClassVar[bool] = False """Does resolver return pre-built wheels?""" + @pydantic.field_validator("build_sdist", mode="after") + @classmethod + def _normalize_deprecated_tarball( + cls, value: BuildSDist | None, info: pydantic.ValidationInfo + ) -> BuildSDist | None: + """Replace the deprecated ``tarball`` alias and log a warning.""" + if value is not BuildSDist.tarball: + return value + context = info.context or {} + package = context.get("package", "") + logger.warning( + "%s: source.build_sdist 'tarball' is deprecated and will be " + "removed in the future; use 'tarball-build-dir' to repack the " + "build directory or 'tarball-root-dir' to repack the whole " + "source tree", + package, + ) + return BuildSDist.tarball_build_dir + def resolver_provider( self, ctx: context.WorkContext, @@ -261,7 +297,7 @@ class PyPISDistResolver(AbstractPyPIResolver): # Tarball repacking is the safe default because some PEP 517 backends # require VCS metadata to generate a correct sdist. - build_sdist: BuildSDist = BuildSDist.tarball + build_sdist: BuildSDist = BuildSDist.tarball_build_dir download_kinds: typing.ClassVar[DownloadKindSet] = frozenset({DownloadKind.sdist}) def resolver_provider( @@ -373,7 +409,7 @@ class PyPIDownloadResolver(AbstractPyPIResolver): URL must contain '{version}' template string. """ - build_sdist: BuildSDist = BuildSDist.tarball + build_sdist: BuildSDist = BuildSDist.tarball_build_dir download_kinds: typing.ClassVar[DownloadKindSet] = frozenset( {DownloadKind.sdist, DownloadKind.tarball} ) @@ -963,15 +999,16 @@ class HookSDistResolver(AbstractHookResolver): return ``DownloadedSource`` with a concrete kind, or a legacy archive ``Path`` treated as an sdist. Without a download hook, the resolved URL is downloaded as an sdist. - Specify ``build_sdist`` explicitly: ``tarball`` to repack an existing - sdist, ``pep517`` to build from a git checkout, or ``hook`` to call - the package's ``build_sdist`` override. + Specify ``build_sdist`` explicitly: ``tarball-build-dir`` to repack an + existing sdist, ``tarball-root-dir`` to repack the whole source tree, + ``pep517`` to build from a git checkout, or ``hook`` to call the + package's ``build_sdist`` override. Example:: provider: hook-sdist index_url: https://pypi.test/simple - build_sdist: tarball + build_sdist: tarball-build-dir """ provider: typing.Literal["hook-sdist"] diff --git a/src/fromager/sources.py b/src/fromager/sources.py index 7846720f..98f9cc97 100644 --- a/src/fromager/sources.py +++ b/src/fromager/sources.py @@ -649,10 +649,17 @@ def build_sdist( """Build a source distribution using the configured strategy or legacy hook. ``source.build_sdist: hook`` requires a package override. Configured - ``pep517`` and ``tarball`` strategies take precedence over overrides. + ``pep517`` and ``tarball-*`` strategies take precedence over overrides. + ``tarball`` is a deprecated alias of ``tarball-build-dir`` and will be + removed in the future. .. versionchanged:: 0.104.0 Configured source profiles can select the ``build_sdist`` override. + + .. versionchanged:: 0.105.0 + ``tarball-build-dir`` and ``tarball-root-dir`` select the packed + directory. ``tarball`` is normalized to ``tarball-build-dir`` with a + deprecation warning when settings load. """ pbi = ctx.package_build_info(req) source_resolver = pbi.source_resolver @@ -702,7 +709,11 @@ def build_sdist( sdist_root_dir=sdist_root_dir, build_env=build_env, ) - elif strategy is packagesettings.BuildSDist.tarball: + elif strategy in ( + packagesettings.BuildSDist.tarball_build_dir, + # deprecated alias, in case a resolver bypassed settings validation + packagesettings.BuildSDist.tarball, + ): sdist_file = default_build_sdist( ctx=ctx, extra_environ=extra_environ, @@ -712,6 +723,17 @@ def build_sdist( build_dir=build_dir, build_env=build_env, ) + elif strategy is packagesettings.BuildSDist.tarball_root_dir: + sdist_file = default_build_sdist( + ctx=ctx, + extra_environ=extra_environ, + req=req, + version=version, + sdist_root_dir=sdist_root_dir, + build_dir=build_dir, + build_env=build_env, + sdist_base_dir=sdist_root_dir, + ) else: raise ValueError( f"{req.name}: unsupported source.build_sdist strategy {strategy!r}" @@ -740,9 +762,14 @@ def default_build_sdist( build_env: build_environment.BuildEnvironment, build_dir: pathlib.Path, *, + sdist_base_dir: pathlib.Path | None = None, exclude_vcs: bool | None = None, ) -> pathlib.Path: - """Repack *build_dir* as an sdist. + """Repack *sdist_base_dir* as an sdist. + + *sdist_base_dir* defaults to *build_dir*. Pass *sdist_root_dir* to pack + the whole source tree while still adding ``PKG-INFO`` to the wheel build + directory. With *exclude_vcs*, VCS metadata such as ``.git`` is left out. By default, exclude it when ``source:`` is configured, and retain it otherwise. @@ -751,7 +778,12 @@ def default_build_sdist( .. versionchanged:: 0.104.0 With ``exclude_vcs=None``, exclude VCS metadata when the effective package or variant has ``source:`` configured; retain it otherwise. + + .. versionchanged:: 0.105.0 + Added *sdist_base_dir* to select the packed directory. """ + if sdist_base_dir is None: + sdist_base_dir = build_dir if exclude_vcs is None: exclude_vcs = ctx.package_build_info(req).source_resolver is not None # It seems like the "correct" way to do this would be to run the @@ -780,8 +812,8 @@ def default_build_sdist( with tarfile.open(sdist_filename, "x:gz", format=tarfile.PAX_FORMAT) as sdist: tarballs.tar_reproducible( tar=sdist, - basedir=build_dir, - prefix=build_dir.parent, + basedir=sdist_base_dir, + prefix=sdist_base_dir.parent, exclude_vcs=exclude_vcs, arcname_root=f"{dist_name}-{version}", ) diff --git a/tests/test_commands.py b/tests/test_commands.py index d722c8d0..77518b69 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -414,7 +414,8 @@ def test_download_sequence_calls_configured_hook_download( ) -> None: """A hook source uses its normal download result during sequence replay.""" _configure_package( - tmp_context, "source:\n provider: hook-sdist\n build_sdist: tarball\n" + tmp_context, + "source:\n provider: hook-sdist\n build_sdist: tarball-build-dir\n", ) url = "https://pkg.test/pkg-1.0.tar.gz" build_order = tmp_path / "build-order.json" @@ -1232,7 +1233,7 @@ def test_step_prepare_source_defaults_to_tarball_for_download_provider( "source_yaml", [ "source:\n provider: pypi-sdist\n", - "source:\n provider: hook-sdist\n build_sdist: tarball\n", + "source:\n provider: hook-sdist\n build_sdist: tarball-build-dir\n", "source:\n provider: pypi-download\n" " download_url: https://pkg.test/pkg-{version}.tar.gz\n" " download_kind: tarball\n", diff --git a/tests/test_packagesettings.py b/tests/test_packagesettings.py index 3baec86b..e8d24780 100644 --- a/tests/test_packagesettings.py +++ b/tests/test_packagesettings.py @@ -1201,6 +1201,18 @@ def test_variant_info_with_source() -> None: assert isinstance(vi.source, PyPIPrebuiltResolver) +def test_package_settings_deprecated_tarball_alias( + caplog: pytest.LogCaptureFixture, +) -> None: + """Normalize the deprecated alias and name the package in the warning.""" + yaml_str = "source:\n provider: pypi-sdist\n build_sdist: tarball\n" + ps = PackageSettings.from_string("test-source-pkg", yaml_str) + + assert ps.source is not None + assert ps.source.build_sdist is BuildSDist.tarball_build_dir + assert "test-source-pkg: source.build_sdist 'tarball' is deprecated" in caplog.text + + def test_package_settings_without_source() -> None: """``PackageSettings`` without ``source:`` has ``source=None``.""" ps = PackageSettings.from_default("test-pkg") diff --git a/tests/test_packagesettings_resolver.py b/tests/test_packagesettings_resolver.py index 5773c5c0..803f9989 100644 --- a/tests/test_packagesettings_resolver.py +++ b/tests/test_packagesettings_resolver.py @@ -127,7 +127,7 @@ def test_parse(self) -> None: assert isinstance(r, PyPISDistResolver) assert r.provider == "pypi-sdist" assert str(r.index_url) == "https://pypi.test/simple" - assert r.build_sdist == BuildSDist.tarball + assert r.build_sdist is BuildSDist.tarball_build_dir assert r.min_release_age is None assert r.supports_override_hooks is False assert r.resolves_prebuilt_wheel is False @@ -245,7 +245,7 @@ def test_parse(self) -> None: assert r.provider == "pypi-download" assert str(r.index_url) == "https://pypi.test/simple" assert "%7Bversion%7D" in str(r.download_url) - assert r.build_sdist == BuildSDist.tarball + assert r.build_sdist is BuildSDist.tarball_build_dir assert r.min_release_age is None assert r.supports_override_hooks is False assert r.resolves_prebuilt_wheel is False @@ -888,7 +888,7 @@ class TestHookSDistResolver: source: provider: hook-sdist index_url: https://index.test/simple - build_sdist: tarball + build_sdist: tarball-build-dir """ def test_parse(self) -> None: @@ -896,14 +896,22 @@ def test_parse(self) -> None: assert isinstance(r, HookSDistResolver) assert r.provider == "hook-sdist" assert str(r.index_url) == "https://index.test/simple" - assert r.build_sdist is BuildSDist.tarball + assert r.build_sdist is BuildSDist.tarball_build_dir assert r.supports_override_hooks is True assert r.resolves_prebuilt_wheel is False assert r.download_kinds == frozenset( {DownloadKind.sdist, DownloadKind.tarball, DownloadKind.git_checkout} ) - @pytest.mark.parametrize("build_method", list(BuildSDist)) + @pytest.mark.parametrize( + "build_method", + [ + BuildSDist.pep517, + BuildSDist.tarball_build_dir, + BuildSDist.tarball_root_dir, + BuildSDist.hook, + ], + ) def test_build_sdist_method(self, build_method: BuildSDist) -> None: """Load the hook sdist build method from YAML.""" r = _parse( @@ -912,6 +920,15 @@ def test_build_sdist_method(self, build_method: BuildSDist) -> None: assert r.build_sdist is build_method + def test_build_sdist_deprecated_tarball_alias( + self, caplog: pytest.LogCaptureFixture + ) -> None: + """Normalize the deprecated tarball alias and log a warning.""" + r = _parse("source:\n provider: hook-sdist\n build_sdist: tarball\n") + + assert r.build_sdist is BuildSDist.tarball_build_dir + assert ": source.build_sdist 'tarball' is deprecated" in caplog.text + def test_build_sdist_method_required(self) -> None: """Require a build method because hook artifacts need different strategies.""" with pytest.raises(pydantic.ValidationError, match="build_sdist"): @@ -919,7 +936,9 @@ def test_build_sdist_method_required(self) -> None: def test_default_index_url(self) -> None: """Source hook profiles may use the standard PyPI index.""" - r = _parse("source:\n provider: hook-sdist\n build_sdist: tarball\n") + r = _parse( + "source:\n provider: hook-sdist\n build_sdist: tarball-build-dir\n" + ) assert isinstance(r, HookSDistResolver) assert str(r.index_url) == "https://pypi.org/simple/" @@ -1453,7 +1472,7 @@ def legacy_hook( find_override_method.return_value = legacy_hook resolver_model = HookSDistResolver( - provider="hook-sdist", build_sdist=BuildSDist.tarball + provider="hook-sdist", build_sdist=BuildSDist.tarball_build_dir ) result = resolver_model.resolver_provider(tmp_context, _REQ, _REQ_TYPE) @@ -1620,7 +1639,7 @@ def hook( find_override_method.return_value = hook resolver_model = HookSDistResolver( - provider="hook-sdist", build_sdist=BuildSDist.tarball + provider="hook-sdist", build_sdist=BuildSDist.tarball_build_dir ) with pytest.raises(RuntimeError, match="hook-sdist") as exc_info: diff --git a/tests/test_sources.py b/tests/test_sources.py index 5ad7542b..d8e33f68 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -152,7 +152,7 @@ def hook( tmp_context.cooldown = Cooldown(min_age=datetime.timedelta(days=7)) source_resolver = packagesettings.HookSDistResolver( provider="hook-sdist", - build_sdist=packagesettings.BuildSDist.tarball, + build_sdist=packagesettings.BuildSDist.tarball_build_dir, index_url=pydantic.HttpUrl("https://profile.test/simple"), min_release_age=14, ) @@ -202,7 +202,7 @@ def download_source() -> pathlib.Path: tmp_context.cooldown = Cooldown(min_age=datetime.timedelta(days=7)) source_resolver = packagesettings.HookSDistResolver( provider="hook-sdist", - build_sdist=packagesettings.BuildSDist.tarball, + build_sdist=packagesettings.BuildSDist.tarball_build_dir, index_url=pydantic.HttpUrl("https://profile.test/simple"), min_release_age=14, ) @@ -1914,34 +1914,34 @@ def test_build_sdist_uses_pep517_for_configured_source( "source:\n provider: pypi-sdist\n", True, False, id="pypi-sdist-override" ), pytest.param( - "source:\n provider: hook-sdist\n build_sdist: tarball\n", + "source:\n provider: hook-sdist\n build_sdist: tarball-build-dir\n", False, False, - id="hook-sdist-tarball", + id="hook-sdist-build-dir", ), pytest.param( - "source:\n provider: hook-sdist\n build_sdist: tarball\n", + "source:\n provider: hook-sdist\n build_sdist: tarball-build-dir\n", True, False, - id="hook-sdist-tarball-override", + id="hook-sdist-build-dir-override", ), pytest.param( "source:\n" " provider: github-tag-git\n" " project_url: https://github.test/org/pkg\n" - " build_sdist: tarball\n", + " build_sdist: tarball-build-dir\n", False, False, - id="git-tarball", + id="git-build-dir", ), pytest.param( "source:\n" " provider: github-tag-git\n" " project_url: https://github.test/org/pkg\n" - " build_sdist: tarball\n", + " build_sdist: tarball-build-dir\n", True, False, - id="git-tarball-override", + id="git-build-dir-override", ), pytest.param( "source:\n provider: pypi-sdist\n build_sdist: hook\n", @@ -1987,7 +1987,7 @@ def test_build_sdist_uses_pep517_for_configured_source( "variants:\n cpu:\n source:\n provider: pypi-sdist\n", True, False, - id="variant-tarball", + id="variant-build-dir", ), ], ) @@ -2062,10 +2062,80 @@ def test_build_sdist_uses_configured_strategy_or_legacy_hook( override.assert_not_called() else: find_override.assert_not_called() - warning = "ignoring build_sdist override because source.build_sdist is tarball" + warning = ( + "ignoring build_sdist override because source.build_sdist is tarball-build-dir" + ) assert (warning in caplog.text) is (not uses_hook and has_override) +@pytest.mark.parametrize( + ("build_sdist", "sdist_base", "deprecated"), + [ + pytest.param("tarball-build-dir", "build", False, id="build-dir"), + pytest.param("tarball-root-dir", "root", False, id="root-dir"), + pytest.param("tarball", "build", True, id="deprecated-tarball"), + ], +) +def test_build_sdist_selects_tarball_base( + build_sdist: str, + sdist_base: str, + deprecated: bool, + tmp_context: context.WorkContext, + tmp_path: pathlib.Path, + caplog: pytest.LogCaptureFixture, +) -> None: + """Pack the configured directory and warn about the deprecated alias.""" + # Arrange + ps = packagesettings.PackageSettings.from_string( + "pkg", + "build_dir: python\n" + "source:\n" + " provider: pypi-sdist\n" + f" build_sdist: {build_sdist}\n", + ) + tmp_context.settings._package_settings[ps.name] = ps + req = Requirement("pkg==1.0") + version = Version("1.0") + sdist_root_dir = tmp_path / "pkg-1.0" + build_dir = sdist_root_dir / "python" + build_dir.mkdir(parents=True) + sdist_file = tmp_context.sdists_builds / "pkg-1.0.tar.gz" + sdist_file.write_text("fake sdist") + build_env = Mock() + expected_kwargs: dict[str, object] = dict( + ctx=tmp_context, + extra_environ={}, + req=req, + version=version, + sdist_root_dir=sdist_root_dir, + build_dir=build_dir, + build_env=build_env, + ) + if sdist_base == "root": + expected_kwargs["sdist_base_dir"] = sdist_root_dir + + # Act + with ( + patch( + "fromager.sources.default_build_sdist", return_value=sdist_file + ) as default, + patch("fromager.packagesettings.get_extra_environ", return_value={}), + ): + result = sources.build_sdist( + ctx=tmp_context, + req=req, + version=version, + sdist_root_dir=sdist_root_dir, + build_env=build_env, + ) + + # Assert + assert result == sdist_file.resolve() + default.assert_called_once_with(**expected_kwargs) + deprecation = "source.build_sdist 'tarball' is deprecated" + assert (deprecation in caplog.text) is deprecated + + @pytest.mark.parametrize( "source_config", [ @@ -2227,7 +2297,7 @@ def test_require_build_sdist_hook_rejects_unusable_hook( "source_config", [ pytest.param("", id="legacy"), - pytest.param("source:\n provider: pypi-sdist\n", id="tarball"), + pytest.param("source:\n provider: pypi-sdist\n", id="pypi-sdist"), pytest.param( "source:\n provider: pypi-sdist\n build_sdist: hook\n" "variants:\n cpu:\n source:\n provider: pypi-sdist\n", @@ -2482,6 +2552,36 @@ def test_default_build_sdist_normalizes_name_and_root( assert "foo_bar-1.0/setup.py" in names +def test_default_build_sdist_root_dir_packs_full_tree( + tmp_context: context.WorkContext, + tmp_path: pathlib.Path, +) -> None: + """Pack the source root while adding PKG-INFO to the wheel build directory.""" + sdist_root = tmp_path / "Foo.Bar-1.0" + build_dir = sdist_root / "python" + build_dir.mkdir(parents=True) + (build_dir / "setup.py").write_text("from setuptools import setup; setup()\n") + (sdist_root / "native.c").write_text("int value(void) { return 1; }\n") + + sdist_file = sources.default_build_sdist( + ctx=tmp_context, + extra_environ={}, + req=Requirement("Foo.Bar==1.0"), + version=Version("1.0"), + sdist_root_dir=sdist_root, + build_env=Mock(), + build_dir=build_dir, + sdist_base_dir=sdist_root, + ) + + with tarfile.open(sdist_file, "r:gz") as tar: + names = tar.getnames() + assert "foo_bar-1.0/native.c" in names + assert "foo_bar-1.0/python/setup.py" in names + assert "foo_bar-1.0/PKG-INFO" in names + assert "foo_bar-1.0/python/PKG-INFO" in names + + @pytest.mark.parametrize( "source_config", [