Skip to content

feat(sdist): add helpers to normalize git clones and tarballs into va…#1169

Open
jlarkin09 wants to merge 1 commit into
python-wheel-build:mainfrom
jlarkin09:feat/sdist-helpers-554
Open

feat(sdist): add helpers to normalize git clones and tarballs into va…#1169
jlarkin09 wants to merge 1 commit into
python-wheel-build:mainfrom
jlarkin09:feat/sdist-helpers-554

Conversation

@jlarkin09
Copy link
Copy Markdown
Contributor

Add sdist.make_sdist_directory() and sdist.repack_as_sdist() helpers that normalize git clones and non-standard tarballs into valid sdist layouts. Bump stub PKG-INFO from Metadata-Version 1.0 to 2.2 and integrate into the git clone prepare_source path and default_build_sdist.

Git clones and GitHub release tarballs lack PKG-INFO, causing setuptools-scm failures when PEP 517 hooks run during PREPARE_BUILD. Today ensure_pkg_info only runs during build_sdist -- one step too late. These helpers create a valid-enough sdist layout earlier in the pipeline using only (name, version).

Closes #554

@jlarkin09 jlarkin09 self-assigned this May 26, 2026
@jlarkin09 jlarkin09 requested a review from a team as a code owner May 26, 2026 14:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 40f0cc05-fd03-41f2-a86c-7f494964b893

📥 Commits

Reviewing files that changed from the base of the PR and between 4c2965f and a1060b7.

📒 Files selected for processing (3)
  • src/fromager/sdist.py
  • src/fromager/sources.py
  • tests/test_sdist.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/test_sdist.py
  • src/fromager/sdist.py
  • src/fromager/sources.py

📝 Walkthrough

Walkthrough

Adds src/fromager/sdist.py with PKG_INFO_TEMPLATE, _write_pkg_info(), make_sdist_directory(), and repack_as_sdist() to normalize source dirs to {name}-{version}, ensure PKG-INFO (including optional build_dir placement), rebase build_dir when renames occur, and create deterministic {name}-{version}.tar.gz archives. Integrates these helpers into sources.py (prepare_source and default_build_sdist) and refactors ensure_pkg_info to delegate stub creation. A new tests/test_sdist.py verifies directory normalization, PKG-INFO behavior, build_dir rebasing, tar contents, filename normalization, and archive replacement.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title correctly identifies the main feature (sdist helpers) and indicates normalization of git clones and tarballs, though it's truncated mid-phrase.
Description check ✅ Passed The description accurately explains the helpers' purpose, metadata bumps, integration points, and the rationale for addressing the setuptools-scm failure issue.
Linked Issues check ✅ Passed The code fully implements all requirements from #554: make_sdist_directory normalizes naming/structure, repack_as_sdist creates {name}-{version}.tar.gz tarballs, PKG-INFO uses Metadata-Version 2.2 with required fields, and build_dir PKG-INFO placement is handled.
Out of Scope Changes check ✅ Passed All changes are within scope: sdist module addition, integration into sources.py/default_build_sdist, and comprehensive test coverage directly address #554 requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mergify mergify Bot added the ci label May 26, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_sdist.py (1)

66-82: ⚡ Quick win

Add regression test for rename + build_dir path rebasing

Current tests validate build_dir only when no rename happens. Please add a case where source_dir name is changed and build_dir is inside it, then assert PKG-INFO/tar creation still succeeds from the rebased path.

As per coding guidelines tests/**: Verify test actually tests the intended behavior. Check for missing edge cases.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_sdist.py` around lines 66 - 82, Add a regression test that
exercises the rename + build_dir rebasing path: create a source directory whose
basename differs from the package name passed to sdist.make_sdist_directory
(e.g., src = tmp_path / "pkg-1.0" but call make_sdist_directory(...,
"pkg-renamed", Version("1.0"), build_dir=build_dir)), ensure build_dir is inside
the source (build_dir = src / "src"), call sdist.make_sdist_directory and then
assert that PKG-INFO exists both in the returned result path and inside the
rebased build_dir (and that a tar/sdist was created if your test harness checks
archives), so the test covers the case where source_dir is renamed and build_dir
must be rebased correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fromager/sdist.py`:
- Around line 81-100: After renaming source_dir (the shutil.move call) rebase
any build_dir that points into the old source_dir so it isn't a stale path:
capture the old_source_dir before the move, then after setting source_dir =
desired compute if build_dir is not None and build_dir is within old_source_dir
(use build_dir.relative_to(old_source_dir] in a try/except) and if so set
build_dir = desired / relative; keep existing behavior for _write_pkg_info and
the later tar logic; apply the same rebasing fix to the analogous block around
lines 132-143.

---

Nitpick comments:
In `@tests/test_sdist.py`:
- Around line 66-82: Add a regression test that exercises the rename + build_dir
rebasing path: create a source directory whose basename differs from the package
name passed to sdist.make_sdist_directory (e.g., src = tmp_path / "pkg-1.0" but
call make_sdist_directory(..., "pkg-renamed", Version("1.0"),
build_dir=build_dir)), ensure build_dir is inside the source (build_dir = src /
"src"), call sdist.make_sdist_directory and then assert that PKG-INFO exists
both in the returned result path and inside the rebased build_dir (and that a
tar/sdist was created if your test harness checks archives), so the test covers
the case where source_dir is renamed and build_dir must be rebased correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dbc0f19f-c545-48f8-bd7c-35ff1b31a9c9

📥 Commits

Reviewing files that changed from the base of the PR and between b10d2e4 and 4c2965f.

📒 Files selected for processing (3)
  • src/fromager/sdist.py
  • src/fromager/sources.py
  • tests/test_sdist.py

Comment thread src/fromager/sdist.py
Copy link
Copy Markdown
Collaborator

@tiran tiran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this approach is not going to work. We have several packages that have a non-standard package layout and do not support Python sdist format.

Comment thread src/fromager/sdist.py
logger = logging.getLogger(__name__)

PKG_INFO_TEMPLATE = """\
Metadata-Version: 2.2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to bump the metadata version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LalatenduMohanty mentioned it in the issue #554 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which packages are affected and do they use custom build_sdist plugin overrides?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlarkin09 you should be able to run fromager+ with this PR against downstream bootstrap and build. We should atleast run an analysis to see if this will break some packages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiran You asked to bump to 2.2 meta data version in you original issue description.

Copy link
Copy Markdown
Contributor Author

@jlarkin09 jlarkin09 Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LalatenduMohanty @tiran ran the non-accelerated/cpu-ubi9 collection on walkerpass against thisbranch. All packages bootstrapped and built successfully

@jlarkin09 jlarkin09 force-pushed the feat/sdist-helpers-554 branch from 4c2965f to 845a282 Compare May 26, 2026 15:23
Comment thread src/fromager/sources.py
req.name,
version,
build_dir=build_dir,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are discarding return value. If the directory is renamed (source directory name doesn't match
{normalized_name}-{version}), both sdist_root_dir and build_dir still point to the old, now-nonexistent paths.

…lid sdists

Git clones and non-standard tarballs (e.g. GitHub release assets) lack
PKG-INFO and standardized directory naming that PEP 517 build backends
expect. This causes setuptools-scm failures during the PREPARE_BUILD
phase when get_requires_for_build_wheel is invoked.

Add a new sdist module with make_sdist_directory() and repack_as_sdist()
that normalize source directories before build dependency resolution.
Bump stub PKG-INFO from Metadata-Version 1.0 to 2.2 and integrate into
the git clone prepare_source path and default_build_sdist.

Closes: python-wheel-build#554
Signed-off-by: James Larkin <jlarkin@redhat.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@jlarkin09 jlarkin09 force-pushed the feat/sdist-helpers-554 branch from 845a282 to a1060b7 Compare June 3, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add helpers to turn git checkout / tar ball into valid sdist

3 participants