mirror of https://github.com/astral-sh/uv
Make overrides a workspace method (#4491)
## Summary No functional changes; just encapsulating the logic within the workspace module.
This commit is contained in:
parent
7d3fb4330f
commit
7221514136
|
|
@ -7,7 +7,7 @@ use glob::{glob, GlobError, PatternError};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
|
|
||||||
use pep508_rs::VerbatimUrl;
|
use pep508_rs::{RequirementOrigin, VerbatimUrl};
|
||||||
use pypi_types::{Requirement, RequirementSource};
|
use pypi_types::{Requirement, RequirementSource};
|
||||||
use uv_fs::{absolutize_path, Simplified};
|
use uv_fs::{absolutize_path, Simplified};
|
||||||
use uv_normalize::PackageName;
|
use uv_normalize::PackageName;
|
||||||
|
|
@ -192,6 +192,38 @@ impl Workspace {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the set of overrides for the workspace.
|
||||||
|
pub fn overrides(&self) -> Vec<Requirement> {
|
||||||
|
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 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.
|
/// the `uv.tool.workspace`, or the `pyproject.toml` in an implicit single workspace project.
|
||||||
pub fn root(&self) -> &PathBuf {
|
pub fn root(&self) -> &PathBuf {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ use std::collections::Bound;
|
||||||
use anstream::eprint;
|
use anstream::eprint;
|
||||||
|
|
||||||
use distribution_types::UnresolvedRequirementSpecification;
|
use distribution_types::UnresolvedRequirementSpecification;
|
||||||
use pep508_rs::RequirementOrigin;
|
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Reinstall, SetupPyStrategy};
|
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Reinstall, SetupPyStrategy};
|
||||||
|
|
@ -113,33 +112,13 @@ pub(super) async fn do_lock(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(UnresolvedRequirementSpecification::from)
|
.map(UnresolvedRequirementSpecification::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
let overrides = workspace
|
||||||
|
.overrides()
|
||||||
|
.into_iter()
|
||||||
|
.map(UnresolvedRequirementSpecification::from)
|
||||||
|
.collect();
|
||||||
let constraints = vec![];
|
let constraints = vec![];
|
||||||
|
|
||||||
let mut overrides: Vec<UnresolvedRequirementSpecification> = 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 dev = vec![DEV_DEPENDENCIES.clone()];
|
||||||
|
|
||||||
let source_trees = vec![];
|
let source_trees = vec![];
|
||||||
|
|
||||||
// Determine the supported Python range. If no range is defined, and warn and default to the
|
// Determine the supported Python range. If no range is defined, and warn and default to the
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue