Skip to content

Python: Improve dependency recipe lock file handling and version normalization#6752

Merged
knutwannheden merged 4 commits intomainfrom
calm-robin
Feb 17, 2026
Merged

Python: Improve dependency recipe lock file handling and version normalization#6752
knutwannheden merged 4 commits intomainfrom
calm-robin

Conversation

@knutwannheden
Copy link
Contributor

@knutwannheden knutwannheden commented Feb 17, 2026

Summary

  • Normalize bare version constraints (e.g. 2.28.0>=2.28.0) across all dependency recipes to produce valid PEP 508 specs
  • Parse uv.lock files via the standard TomlParser so lock files are included in the source set and can be updated by dependency recipes
  • Seed uv lock regeneration with existing lock file content for minimal, deterministic updates instead of full re-resolution
  • Share lock file state across recipes via PythonDependencyExecutionContextView, so sequential recipes in a CompositeRecipe correctly build on each other's lock regeneration results
  • Extract maybeUpdateUvLock helper for idempotent uv.lock updates with content normalization for round-trip stability across recipe cycles

Test plan

  • AddDependencyTestaddDependencyWithBareVersion, uvLockRegenerationWorks, twoAddDependenciesInSequence (CompositeRecipe with shared lock state)
  • ChangeDependencyTestbareVersionNormalized
  • UpgradeDependencyVersionTestbareVersionNormalized
  • UpgradeTransitiveDependencyVersionTestbareVersionNormalizedInConstraint, bareVersionNormalizedInFallback
  • Verified end-to-end via Moderne CLI against astral-sh/pyx-auth-action — both pyproject.toml and uv.lock correctly updated
  • All existing tests continue to pass

Bare version strings like `2.28.0` passed to `AddDependency`,
`UpgradeDependencyVersion`, `UpgradeTransitiveDependencyVersion`, and
`ChangeDependency` were concatenated directly with the package name,
producing invalid PEP 508 specs such as `requests2.28.0`. A shared
`PyProjectHelper.normalizeVersionConstraint()` now prefixes `>=` when
no comparison operator is present.

Also parse `uv.lock` in `PythonRewriteRpc.parseProject()` via the
standard `TomlParser` so that lock files are included in the source set
and can be updated by dependency-management recipes.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Feb 17, 2026
@knutwannheden knutwannheden changed the title Normalize bare version constraints in Python dependency recipes Python: Normalize bare version constraints in dependency recipes Feb 17, 2026
The Python RPC server's handle_parse_project extracted relative_to from
the request but never forwarded it, producing absolute source paths.
Now defaults to project_path (matching the JS implementation) and passes
it through so source paths are relative.

Also strengthened ParseProjectIntegTest to assert full relative paths.
When regenerating uv.lock after dependency changes, seed the temp
directory with the existing lock file so `uv lock` performs a minimal
update rather than re-resolving every dependency from scratch.

Also extend TomlParser to accept uv.lock files, allowing the scanner
phase of dependency recipes to capture existing lock contents.
Move lock file maps (updatedLockFiles, existingLockContents) from
per-recipe accumulators into a shared PythonDependencyExecutionContextView.
This allows sequential recipes in a CompositeRecipe to correctly build on
each other's lock regeneration results.

Also extract maybeUpdateUvLock helper in PyProjectHelper that handles
idempotent uv.lock updates with content normalization for round-trip
stability across recipe cycles.
@knutwannheden knutwannheden changed the title Python: Normalize bare version constraints in dependency recipes Python: Improve dependency recipe lock file handling and version normalization Feb 17, 2026
@knutwannheden knutwannheden merged commit 9da74df into main Feb 17, 2026
1 check passed
@knutwannheden knutwannheden deleted the calm-robin branch February 17, 2026 14:03
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant

Comments