Skip to content

Allow uv upgrade to update multiple declarations of the same package - #20335

Merged
zsol merged 7 commits into
mainfrom
zsol/upgrade-01-declarations
Jul 22, 2026
Merged

zsol merged 7 commits into
mainfrom
zsol/upgrade-01-declarations

Conversation

@zsol

@zsol zsol commented Jul 13, 2026

Copy link
Copy Markdown
Member

uv upgrade currently rejects multiple declarations for the same dependency. For example:

dependencies = [
    "bar<1 ; sys_platform == 'linux'",
    "bar<2 ; sys_platform != 'linux'",
]

This updates every matching declaration using the versions resolved for its marker, including exact duplicates, instead of rejecting the upgrade.

Declarations excluded by requires-python or configured environments now fail before resolution, avoiding partial upgrades. Requirement replacement and source validation retain the declaration type so subsequent workspace, optional-dependency, and dependency-group support can reuse the same path.

@zsol
zsol force-pushed the zsol/upgrade-01-declarations branch 4 times, most recently from 86a953b to 6526d23 Compare July 13, 2026 12:27
@astral-sh-bot

ghost commented Jul 13, 2026 •

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 33
  • Removed tests: 15
  • Changed suites: 10
uv: +12 / -11

Added:

  • uv::commands::project::upgrade::tests::propose_specifiers_expands_exclusive_upper_bounds_at_existing_precision
  • uv::commands::project::upgrade::tests::propose_specifiers_expands_upper_bound_for_multiple_versions
  • uv::commands::project::upgrade::tests::propose_specifiers_only_rewrites_blocking_specifiers
  • uv::commands::project::upgrade::tests::propose_specifiers_preserves_compatible_release_suffixes
  • uv::commands::project::upgrade::tests::propose_specifiers_preserves_lower_bounds_and_exclusions
  • uv::commands::project::upgrade::tests::propose_specifiers_preserves_operator_style
  • uv::commands::project::upgrade::tests::propose_specifiers_preserves_satisfied_constraints
  • uv::commands::project::upgrade::tests::propose_specifiers_rejects_constraint_that_still_excludes_resolved_version
  • uv::commands::project::upgrade::tests::propose_specifiers_rejects_unrepresentable_multiple_versions
  • uv::commands::project::upgrade::tests::propose_specifiers_returns_none_without_resolved_versions
  • uv::commands::project::upgrade::tests::propose_specifiers_strips_local_version_from_inclusive_upper_bound
  • uv::commands::project::upgrade::tests::propose_specifiers_uses_lowest_compatible_version_for_multiple_versions

Removed:

  • uv::commands::project::upgrade::tests::propose_requirement_expands_exclusive_upper_bounds_at_existing_precision
  • uv::commands::project::upgrade::tests::propose_requirement_expands_upper_bound_for_multiple_versions
  • uv::commands::project::upgrade::tests::propose_requirement_only_rewrites_blocking_specifiers
  • uv::commands::project::upgrade::tests::propose_requirement_preserves_compatible_release_suffixes
  • uv::commands::project::upgrade::tests::propose_requirement_preserves_metadata_lower_bounds_and_exclusions
  • uv::commands::project::upgrade::tests::propose_requirement_preserves_operator_style
  • uv::commands::project::upgrade::tests::propose_requirement_preserves_satisfied_constraints
  • uv::commands::project::upgrade::tests::propose_requirement_rejects_constraint_that_still_excludes_resolved_version
  • uv::commands::project::upgrade::tests::propose_requirement_rejects_unrepresentable_multiple_versions
  • uv::commands::project::upgrade::tests::propose_requirement_strips_local_version_from_inclusive_upper_bound
  • uv::commands::project::upgrade::tests::propose_requirement_uses_lowest_compatible_version_for_multiple_versions
uv-fs: +1 / -0

Added:

  • uv-fs::path::tests::test_path_escape_for_python

Removed: none

uv-pypi-types: +1 / -0

Added:

  • uv-pypi-types::conflicts::tests::expand_transitive_group_includes_preserves_original_sets

Removed: none

uv-workspace: +2 / -1

Added:

  • uv-workspace::pyproject_mut::test::replace_dependency_declaration_updates_selected_type
  • uv-workspace::pyproject_mut::test::replace_dependency_updates_every_exact_match

Removed:

  • uv-workspace::pyproject_mut::test::replace_dependency_preserves_source
uv::it: +8 / -3

Added:

  • uv::it::upgrade::upgrade_ignores_unrelated_path_package_when_attributing_versions
  • uv::it::upgrade::upgrade_rejects_conflicting_extra_declarations
  • uv::it::upgrade::upgrade_skips_excluded_declarations_and_updates_applicable_requirement
  • uv::it::upgrade::upgrade_skips_inapplicable_marked_dependency
  • uv::it::upgrade::upgrade_skips_non_registry_source_for_undefined_extra
  • uv::it::upgrade::upgrade_skips_undefined_extra
  • uv::it::upgrade::upgrade_updates_multiple_marked_production_dependencies
  • uv::it::upgrade::upgrade_warns_for_skipped_requirement_before_validation_error

Removed:

  • uv::it::upgrade::upgrade_preserves_inapplicable_marked_dependency
  • uv::it::upgrade::upgrade_rejects_duplicate_marked_production_dependencies
  • uv::it::upgrade::upgrade_rejects_non_registry_source_for_top_level_extra
uv::lock: +5 / -0

Added:

  • uv::lock::lock::lock_external_workspace_source
  • uv::lock::lock::lock_index_hash_algorithm
  • uv::lock::lock::lock_index_hash_algorithm_missing
  • uv::lock::lock::lock_unused_external_workspace_source
  • uv::lock::lock::lock_workspace_member_with_external_workspace_source

Removed: none

uv::pip_compile: +1 / -0

Added:

  • uv::pip_compile::pip_compile::emit_options_unsupported

Removed: none

uv::project: +1 / -0

Added:

  • uv::project::run::run_centralized_environment_path_file

Removed: none

uv::python: +1 / -0

Added:

  • uv::python::venv::create_centralized_project_environment_path_file

Removed: none

uv::sync: +1 / -0

Added:

  • uv::sync::centralized_project_envs::sync_recovers_from_centralized_environment_path_file

Removed: none

@zsol
zsol marked this pull request as ready for review July 13, 2026 12:54
@zsol
zsol requested a review from konstin July 13, 2026 12:54
@konstin konstin added the preview Experimental behavior label Jul 21, 2026
Comment thread crates/uv/tests/it/upgrade.rs Resolved
Comment thread crates/uv/tests/it/upgrade.rs Resolved
relaxed_requirements
.iter()
.map(|(package, dependency_type, existing, replacement)| {
(package, dependency_type, existing, replacement)

ghost Jul 21, 2026

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.

What does this do?

ghost Jul 21, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It relaxes each selected requirement in a temporary manifest so the resolver can select newer versions. I’ve clarified the comment and replaced the tuple mapping with RequirementUpdate, which also makes the helper input explicit.

LMK if that's clear enough

ghost Jul 21, 2026

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.

I meant on a more low level, why are we having (package, dependency_type, existing, replacement) twice?

.contains(project.project_name(), extra.as_ref())
{
let package = &selected.package;
bail!(

ghost Jul 21, 2026

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.

Do we have a GitHub issue tracking these gaps?

There is a related question where conflicts may put different constraints on a package indirectly, which we should ensure we handle correctly before stabilization.

ghost Jul 21, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I made #20574 for this, but in general I have local changes to address some of these gaps, so I'm hestitant to open issues for all of them (to avoid churn).

ghost Jul 21, 2026

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.

I usually open one tracking issue with checkboxes. That's the easiest way to keep track of all the TODOs in a single place an also supports cross-linking issues and PRs.

let existing =
into_verbatim_requirement(selected.requirement.clone(), &selected.package)?;
let replacement = into_verbatim_requirement(proposed_requirement, &selected.package)?;
if !updated_requirements

ghost Jul 21, 2026

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.

How does this check compare to using a BTreeSet?

ghost Jul 21, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How would we use BTreeSet here, I don't think I understand?

ghost Jul 21, 2026

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.

Currently, we're running a manually deduplication check by comparing struct fields. What if updated_requirements was a BTreeSet instead, and we didn't do manual deduplication?

ghost Jul 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The problem with a BTreeSet-based deduplication is that we must ignore original_text for dedupe purposes. I've changed this to a BTreeMap instead in f8b39da but I'm not sure it's significantly better tbh

Zsolt Dollenstein added 5 commits July 21, 2026 17:36
Select upgrade declarations with their effective project marker before validating sources or relaxing the temporary manifest. Reject declarations excluded by the project's Python or environment constraints, since they cannot contribute a resolved version and a partial upgrade would be misleading.

Reject current-project conflict-extra declarations before fork attribution, since resolved packages cannot yet be mapped back to those declarations safely.
Carry package and DependencyType through selected declarations and requirement updates while preserving the current production-only selection behavior.

Route exact replacements through DependencyType-aware pyproject mutation helpers so later optional, group, and workspace slices can reuse the same one-resolve path.

Keep source applicability origin-aware for future declaration kinds, and avoid inspecting unrelated locked packages through registry-specific APIs during attribution.
@zsol
zsol force-pushed the zsol/upgrade-01-declarations branch from 6526d23 to 0b69abf Compare July 21, 2026 16:45
@zsol
zsol temporarily deployed to automations July 21, 2026 16:46 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
automations — f8b39da8 Deployed Jul 22, 2026 by zsol via review / security review #43037
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants