diff --git a/crates/uv-distribution/src/workspace.rs b/crates/uv-distribution/src/workspace.rs index e6106829c..b2bfaca54 100644 --- a/crates/uv-distribution/src/workspace.rs +++ b/crates/uv-distribution/src/workspace.rs @@ -7,7 +7,7 @@ use glob::{glob, GlobError, PatternError}; use rustc_hash::FxHashSet; use tracing::{debug, trace}; -use pep508_rs::VerbatimUrl; +use pep508_rs::{RequirementOrigin, VerbatimUrl}; use pypi_types::{Requirement, RequirementSource}; use uv_fs::{absolutize_path, Simplified}; use uv_normalize::PackageName; @@ -192,6 +192,38 @@ impl Workspace { .collect() } + /// Returns the set of overrides for the workspace. + pub fn overrides(&self) -> Vec { + let Some(workspace_package) = self + .packages + .values() + .find(|workspace_package| workspace_package.root() == self.root()) + else { + return vec![]; + }; + + let Some(overrides) = workspace_package + .pyproject_toml() + .tool + .as_ref() + .and_then(|tool| tool.uv.as_ref()) + .and_then(|uv| uv.override_dependencies.as_ref()) + else { + return vec![]; + }; + + overrides + .iter() + .map(|requirement| { + Requirement::from( + requirement + .clone() + .with_origin(RequirementOrigin::Workspace), + ) + }) + .collect() + } + /// The path to the workspace root, the directory containing the top level `pyproject.toml` with /// the `uv.tool.workspace`, or the `pyproject.toml` in an implicit single workspace project. pub fn root(&self) -> &PathBuf { diff --git a/crates/uv/src/commands/project/lock.rs b/crates/uv/src/commands/project/lock.rs index 17a8545d0..75c0f8be8 100644 --- a/crates/uv/src/commands/project/lock.rs +++ b/crates/uv/src/commands/project/lock.rs @@ -3,7 +3,6 @@ use std::collections::Bound; use anstream::eprint; use distribution_types::UnresolvedRequirementSpecification; -use pep508_rs::RequirementOrigin; use uv_cache::Cache; use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Reinstall, SetupPyStrategy}; @@ -113,33 +112,13 @@ pub(super) async fn do_lock( .into_iter() .map(UnresolvedRequirementSpecification::from) .collect(); + let overrides = workspace + .overrides() + .into_iter() + .map(UnresolvedRequirementSpecification::from) + .collect(); let constraints = vec![]; - - let mut overrides: Vec = vec![]; - for workspace_package in workspace.packages().values() { - if workspace_package.root() == workspace.root() { - if let Some(override_dependencies) = workspace_package - .pyproject_toml() - .tool - .as_ref() - .and_then(|tool| tool.uv.as_ref()) - .and_then(|uv| uv.override_dependencies.as_ref()) - { - for override_dependency in override_dependencies { - let req = pypi_types::Requirement::from( - override_dependency - .clone() - .with_origin(RequirementOrigin::Workspace), - ); - overrides.push(UnresolvedRequirementSpecification::from(req)); - } - } - break; - } - } - let dev = vec![DEV_DEPENDENCIES.clone()]; - let source_trees = vec![]; // Determine the supported Python range. If no range is defined, and warn and default to the