feat: add get_build_system_dependencies global hook point#1271
Conversation
Allow downstream projects to register global hooks that post-process build-system dependencies for all packages. Hooks are chained so multiple can compose. This enables use cases like auto-capping setuptools without per-package plugins. Closes python-wheel-build#1263 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Vikash Shaw <vshaw@redhat.com>
📝 WalkthroughWalkthroughAdds a global Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/test_dependencies.py`:
- Around line 432-434: Strengthen the assertions in the dependency hook test
around the returned results so they verify a setuptools requirement excludes
version 82, rather than only checking that setuptools is present. Preserve the
existing requirements argument assertion and ensure the new check would fail if
the hook discarded the returned setuptools constraint.
🪄 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 Plus
Run ID: 4fdc1ee4-6f73-4d81-b707-e30713142a59
📒 Files selected for processing (4)
src/fromager/dependencies.pysrc/fromager/hooks.pytests/test_dependencies.pytests/test_hooks.py
| names = set(r.name for r in results) | ||
| assert "setuptools" in names | ||
| assert called_with["requirements"] == ["setuptools>=40.0"] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert that the hook’s returned constraint affects the result.
"setuptools" is already present before the hook runs, so this passes even if setuptools<82 is discarded. Assert that at least one returned setuptools requirement excludes version 82.
Suggested assertion
names = set(r.name for r in results)
assert "setuptools" in names
+ assert any(
+ r.name == "setuptools" and Version("82") not in r.specifier
+ for r in results
+ )
assert called_with["requirements"] == ["setuptools>=40.0"]As per path instructions, “Verify test actually tests the intended behavior.”
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| names = set(r.name for r in results) | |
| assert "setuptools" in names | |
| assert called_with["requirements"] == ["setuptools>=40.0"] | |
| names = set(r.name for r in results) | |
| assert "setuptools" in names | |
| assert any( | |
| r.name == "setuptools" and Version("82") not in r.specifier | |
| for r in results | |
| ) | |
| assert called_with["requirements"] == ["setuptools>=40.0"] |
🤖 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_dependencies.py` around lines 432 - 434, Strengthen the assertions
in the dependency hook test around the returned results so they verify a
setuptools requirement excludes version 82, rather than only checking that
setuptools is present. Preserve the existing requirements argument assertion and
ensure the new check would fail if the hook discarded the returned setuptools
constraint.
Source: Path instructions
a181bfa to
8782533
Compare
8782533 to
2ffbe2d
Compare
Summary
Adds
get_build_system_dependenciesas a new global hook point infromager.hooks. This lets downstream projects register hooks that post-process build-system dependencies for all packages, without needing per-package plugins.Motivation: In the AIPCC/fondue builder we have 22+ identical per-package plugins that exist solely to cap setuptools for packages whose
setup.pyuses removed APIs (pkg_resources,dry_run). With this hook point, we can replace all of them with a single global hook.Changes
src/fromager/hooks.py: Addedget_build_system_dependenciestoGLOBAL_HOOK_NAMESand implementedrun_get_build_system_dependencies_hooks()which chains hooks so each receives the (possibly modified) requirements list from the previous one.src/fromager/dependencies.py: Afteroverrides.find_and_invoke()returns build-system deps and before_filter_requirements(), the global hooks are now called to allow post-processing.tests/test_hooks.py: Tests for the new hook: basic invocation, chaining behavior, no-op when no hooks registered, exception propagation.tests/test_dependencies.py: Integration test verifyingget_build_system_dependencies()calls the global hooks.Hook signature
Registered via entry points under
fromager.hooks:How it fits
The hook runs after per-package overrides (
overrides.find_and_invoke) and before marker filtering (_filter_requirements). This means per-package plugins still take full precedence, and global hooks only augment the result.Closes #1263