Skip to content

Python: Extend dependency recipes with scope support and package-manager-aware transitive pinning#6715

Merged
knutwannheden merged 4 commits intomainfrom
more-py-deps-recipes
Feb 11, 2026
Merged

Python: Extend dependency recipes with scope support and package-manager-aware transitive pinning#6715
knutwannheden merged 4 commits intomainfrom
more-py-deps-recipes

Conversation

@knutwannheden
Copy link
Contributor

@knutwannheden knutwannheden commented Feb 11, 2026

Summary

  • Add scope and groupName options to AddDependency, RemoveDependency, and UpgradeDependencyVersion so they can target project.optional-dependencies, dependency-groups, tool.uv.constraint-dependencies, tool.uv.override-dependencies, and tool.pdm.overrides in addition to project.dependencies
  • Introduce ChangeDependency recipe to rename packages (with optional version change) across all dependency scopes
  • Introduce UpgradeTransitiveDependencyVersion recipe that pins transitive dependencies using the appropriate strategy per package manager: uv uses constraint-dependencies, PDM uses tool.pdm.overrides, unknown managers fall back to adding a direct dependency
  • Add constraintDependencies and overrideDependencies fields to PythonResolutionResult marker (overrideDependencies is shared by uv and PDM, disambiguated by the PackageManager enum), with package manager detection from pyproject.toml table names

Test plan

  • AddDependencyTest — new tests for optional-dependencies, dependency-groups, constraint-dependencies scopes
  • RemoveDependencyTest — new tests for optional-dependencies, dependency-groups, override-dependencies scopes
  • UpgradeDependencyVersionTest — new tests for optional-dependencies, dependency-groups, constraint-dependencies scopes
  • ChangeDependencyTest — rename, rename with version, preserve extras/markers, skip when not found, rename across scopes
  • UpgradeTransitiveDependencyVersionTest — uv constraint add/upgrade/skip tests, PDM override add/upgrade/skip tests, unknown manager fallback tests
  • DependencyInsightTest — updated scope naming, constraint/override/pdm scope coverage
  • PythonResolutionResultTest — updated constructor calls for new fields

Extend AddDependency, RemoveDependency, and UpgradeDependencyVersion with
scope and groupName options to target project.optional-dependencies and
dependency-groups in addition to project.dependencies. Generalize
PyProjectHelper with isInsideDependencyArray and findDependencyInScope.

Rename DependencyInsight scope values to TOML dotted-path convention
(e.g. "buildRequires" -> "build-system.requires").

Add ChangeDependency recipe that renames a package across all dependency
arrays in pyproject.toml, optionally setting a new version.
…ersion

Add constraintDependencies and overrideDependencies fields to
PythonResolutionResult for uv constraint-dependencies and
override-dependencies sections. Extract these from pyproject.toml
via PythonDependencyParser and link to resolved deps.

Extend all dependency recipes (Add, Remove, Upgrade, DependencyInsight)
with tool.uv.constraint-dependencies and tool.uv.override-dependencies
scope values.

Introduce UpgradeTransitiveDependencyVersion recipe that pins a
transitive dependency by adding or upgrading a constraint in the
[tool.uv].constraint-dependencies array.
Add pdmOverrides field to PythonResolutionResult and detect package
manager from pyproject.toml table names (tool.uv → Uv, tool.pdm → Pdm).
UpgradeTransitiveDependencyVersion now branches by package manager:
uv uses constraint-dependencies, PDM uses tool.pdm.overrides, and
unknown managers fall back to adding a direct dependency.
@knutwannheden knutwannheden added recipe Requested Recipe python labels Feb 11, 2026
@knutwannheden knutwannheden changed the title Extend Python dependency recipes with scope support and package-manager-aware transitive pinning Python: Extend dependency recipes with scope support and package-manager-aware transitive pinning Feb 11, 2026
@knutwannheden knutwannheden merged commit e910c1d into main Feb 11, 2026
1 check passed
@knutwannheden knutwannheden deleted the more-py-deps-recipes branch February 11, 2026 10:09
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python recipe Requested Recipe

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant