Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Consolidate locked dependency selection APIs - #19982

#19982
Merged
zsol merged 2 commits into
mainastral-sh/uv:mainfrom
zsol/uv-lock-dependency-selection-api-v2astral-sh/uv:zsol/uv-lock-dependency-selection-api-v2Copy head branch name to clipboard
Jun 26, 2026
Merged

Consolidate locked dependency selection APIs#19982
zsol merged 2 commits into
mainastral-sh/uv:mainfrom
zsol/uv-lock-dependency-selection-api-v2astral-sh/uv:zsol/uv-lock-dependency-selection-api-v2Copy head branch name to clipboard

Conversation

@zsol

@zsol zsol commented Jun 24, 2026

Copy link
Copy Markdown
Member

project::toolchain currently uses three separate Lock APIs to select a preferred dependency-group package, fall back to a production dependency, and determine whether the exact package is already selected by the enabled groups. This spreads one query across the resolver and command code and can discover the same locked package more than once.

This replaces those methods with Lock::dependency_selection, which resolves the production and dependency-group packages for a marker environment once. The returned DependencySelection supports direct production and group lookups and iteration over group selections. Any ambiguity encountered while materializing the selection fails the operation.

This is a followup to #19884

@zsol
zsol requested a review from zanieb June 24, 2026 20:46
@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the latest main baseline.

  • Added tests: 2
  • Removed tests: 7
  • Changed suites: 3
uv-resolver: +2 / -0

Added:

  • uv-resolver::lock::tests::dependency_selection_resolves_included_groups_to_same_package
  • uv-resolver::lock::tests::dependency_selection_returns_any_selection_error

Removed: none

uv::lock: +0 / -6

Added: none

Removed:

  • uv::lock::lock::lock_project_with_conflicting_scoped_overrides
  • uv::lock::lock::lock_project_with_scoped_override_index
  • uv::lock::lock::lock_project_with_scoped_override_prerelease
  • uv::lock::lock::lock_project_with_scoped_override_url
  • uv::lock::lock::lock_project_with_scoped_override_yank
  • uv::lock::lock::lock_project_with_scoped_overrides
uv::pip_compile: +0 / -1

Added: none

Removed:

  • uv::pip_compile::pip_compile::scoped_override_dependency_from_pyproject

@zsol
zsol marked this pull request as ready for review June 25, 2026 08:25
Comment thread crates/uv/src/commands/project/toolchain.rs Outdated
@zsol
zsol force-pushed the zsol/uv-lock-dependency-selection-api-v2 branch from 71fa7bd to 7db8448 Compare June 25, 2026 14:52
Comment thread crates/uv/tests/project/check.rs Outdated

@zanieb zanieb left a comment

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 still think something is a little off here but think I'd have to poke at it myself to give constructive feedback — seems like a nice improvement.

@zsol

zsol commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

I still think something is a little off here but think I'd have to poke at it myself to give constructive feedback

If/when you do get to this, let me know. Happy to own following up, and am interested in how this can be improved - seems like an important API going forward

@zsol
zsol force-pushed the zsol/uv-lock-dependency-selection-api-v2 branch from 2ce9c30 to b332bc1 Compare June 26, 2026 13:20
@zsol
zsol enabled auto-merge (squash) June 26, 2026 13:21
@zsol zsol added the internal A refactor or improvement that is not user-facing label Jun 26, 2026
@zsol
zsol merged commit 92df2c6 into main Jun 26, 2026
54 checks passed
@zsol
zsol deleted the zsol/uv-lock-dependency-selection-api-v2 branch June 26, 2026 13:26
zsol added a commit that referenced this pull request Jun 26, 2026
`uv check --script` currently ignores a direct `ty` dependency from PEP
723 metadata when choosing the checker. The script environment contains
the locked package, but uv still selects a standalone `ty` from its
built-in compatible range, so the checker can differ from the script’s
dependency graph.

This extends `Lock::dependency_selection` to include applicable
lock-manifest requirements. When a script directly declares `ty`, `uv
check` now runs the marker-selected locked package from the script
environment, preserving its source and transitive dependencies without
another resolution.

This is a followup to #19884 and it depends on #19982.
zsol added a commit that referenced this pull request Jul 9, 2026
…#20078)

`Lock::dependency_selection` selects the exact locked package for a
direct project dependency, but the result currently discards
information, like selected extras or dependency-group conflict context
(used to select conflict forks). This isn't critical for our current use
cases (ruff and ty), but it's worth fixing to avoid future confusion.

For a relatively contrived example, a workspace may use a local build of
`ty` that depends on `a`, with two mutually exclusive groups pinning
`a==1` and `a==2`. With `uv check --no-sync`, uv selects the correct
locked `ty` for the enabled group, but previously discarded that group
context when building the cached environment. The marker on `ty`’s
dependency still referred to the project conflict outside the synthetic
tool subgraph, so materialization failed instead of selecting the
corresponding `a` fork.

This PR returns a `SelectedDependency` containing the exact package, the
union of extras from applicable direct edges, and the production or
dependency-group context. `Lock::to_resolution_from_dependency` passes
that information into the existing locked-subgraph traversal, activating
selected extras and resolving project conflict items even though the
project itself is outside the cached subgraph.

This is a follow-up to #19982 and #19989.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.