Make overrides a workspace method (#4491)

## Summary

No functional changes; just encapsulating the logic within the workspace
module.
This commit is contained in:
Charlie Marsh 2024-06-25 00:09:23 +03:00 committed by GitHub
parent 7d3fb4330f
commit 7221514136
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 27 deletions

View File

@ -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<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 `uv.tool.workspace`, or the `pyproject.toml` in an implicit single workspace project.
pub fn root(&self) -> &PathBuf {

View File

@ -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<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 source_trees = vec![];
// Determine the supported Python range. If no range is defined, and warn and default to the