feat: add settings-driven build_system_dependencies_hook - #1271
Conversation
📝 WalkthroughWalkthroughThe change adds an optional Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: 🔵 Low · up to The PR adds a global hook for post-processing build-system dependencies. It is mergeable with owner awareness that the integration tests should use the same source directory for the build environment and dependency resolution to avoid masking localized regressions. 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 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
Add a configurable hook in the global settings file that post-processes build-system dependencies after the per-package override (or default) runs and before marker filtering. The hook is specified as a dotted import path and loaded via Pydantic ImportString, following the same pattern as the proposed build_tag_hook. This enables downstream projects to implement cross-cutting concerns (such as setuptools version capping) as a single callable instead of duplicating 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>
2ffbe2d to
3d7b57b
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/test_dependencies.py (1)
193-205: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winUse the same sdist root for
BuildEnvironmentand dependency resolution.Both tests create
BuildEnvironmentwith an empty temporary directory, but resolve dependencies from_fromager_root. This can hide regressions that depend on the build environment source tree.Proposed fix
- sdist_root = tmp_path / "fromager-1.0.0" - sdist_root.mkdir() + sdist_root = _fromager_root ... - sdist_root_dir=_fromager_root, + sdist_root_dir=sdist_root,Apply the same change in both tests. As per path instructions, “Verify test actually tests the intended behavior.”
Also applies to: 257-269
🤖 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 193 - 205, Update both tests around BuildEnvironment and get_build_system_dependencies to use the same sdist root path for construction and dependency resolution. Replace the empty temporary sdist_root directory passed to BuildEnvironment with the existing _fromager_root value, while preserving the dependency-resolution arguments and verifying both tests exercise the source-tree behavior.Source: Path instructions
🤖 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.
Outside diff comments:
In `@tests/test_dependencies.py`:
- Around line 193-205: Update both tests around BuildEnvironment and
get_build_system_dependencies to use the same sdist root path for construction
and dependency resolution. Replace the empty temporary sdist_root directory
passed to BuildEnvironment with the existing _fromager_root value, while
preserving the dependency-resolution arguments and verifying both tests exercise
the source-tree behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 856d72f8-574a-4c53-9def-0cff8df0c872
📒 Files selected for processing (3)
src/fromager/dependencies.pysrc/fromager/packagesettings/_settings.pytests/test_dependencies.py
Summary
Adds a configurable
build_system_dependencies_hookin the globalsettings.yamlthat post-processes build-system dependencies for allpackages. The hook is specified as a dotted import path and loaded via
Pydantic
ImportString, following the same pattern as the proposedbuild_tag_hook.Motivation: In downstream projects, many identical per-package
plugins exist solely to cap setuptools for packages whose
setup.pyuses removed APIs (
pkg_resources,dry_run). With this hook, theycan all be replaced by a single callable.
Changes
src/fromager/packagesettings/_settings.py: Addedbuild_system_dependencies_hookfield toSettingsFile(PydanticImportString | None) and a@propertyonSettingsto expose it.src/fromager/dependencies.py: Afteroverrides.find_and_invoke()returns and before
_filter_requirements(), the hook is called ifconfigured.
tests/test_dependencies.py: Tests for the hook integration,settings field defaults, and property access.
Configuration
Hook signature
How it fits
The hook runs after per-package overrides (
overrides.find_and_invoke)and before marker filtering (
_filter_requirements). Per-packageplugins still take full precedence, and the hook only augments the result.
Proposal: #1272
Closes #1263