Skip to content

Commit

Permalink
Omit project name from workspace errors
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 13, 2024
1 parent ef3bc16 commit 48cb017
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 57 deletions.
7 changes: 0 additions & 7 deletions crates/uv-distribution/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ impl Workspace {
.collect()
}

/// If there is a package at the workspace root, return it.
pub fn root_member(&self) -> Option<&WorkspaceMember> {
self.packages
.values()
.find(|package| package.root == self.root)
}

/// 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 {
Expand Down
8 changes: 0 additions & 8 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ pub(crate) async fn add(
let exclude_newer = None;

// Lock and sync the environment.
let root_project_name = project
.current_project()
.pyproject_toml()
.project
.as_ref()
.map(|project| project.name.clone());

let lock = project::lock::do_lock(
root_project_name,
project.workspace(),
venv.interpreter(),
&index_locations,
Expand Down
32 changes: 5 additions & 27 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use uv_configuration::{
use uv_dispatch::BuildDispatch;
use uv_distribution::{Workspace, DEV_DEPENDENCIES};
use uv_git::GitResolver;
use uv_normalize::PackageName;
use uv_requirements::upgrade::{read_lockfile, LockedRequirements};
use uv_resolver::{ExcludeNewer, FlatIndex, InMemoryIndex, Lock, OptionsBuilder, RequiresPython};
use uv_toolchain::Interpreter;
Expand Down Expand Up @@ -46,15 +45,7 @@ pub(crate) async fn lock(
let interpreter = project::find_interpreter(&workspace, python.as_deref(), cache, printer)?;

// Perform the lock operation.
let root_project_name = workspace.root_member().and_then(|member| {
member
.pyproject_toml()
.project
.as_ref()
.map(|project| project.name.clone())
});
match do_lock(
root_project_name,
&workspace,
&interpreter,
&index_locations,
Expand Down Expand Up @@ -82,7 +73,6 @@ pub(crate) async fn lock(
/// Lock the project requirements into a lockfile.
#[allow(clippy::too_many_arguments)]
pub(super) async fn do_lock(
root_project_name: Option<PackageName>,
workspace: &Workspace,
interpreter: &Interpreter,
index_locations: &IndexLocations,
Expand Down Expand Up @@ -122,27 +112,15 @@ pub(super) async fn do_lock(
if matches!(requires_python.bound(), Bound::Unbounded) {
let default =
RequiresPython::greater_than_equal_version(interpreter.python_minor_version());
if let Some(root_project_name) = root_project_name.as_ref() {
warn_user!(
"The `requires-python` field found in `{root_project_name}` does not contain a lower bound: `{requires_python}`. Set a lower bound to indicate the minimum compatible Python version (e.g., `{default}`).",
);
} else {
warn_user!(
"The `requires-python` field does not contain a lower bound: `{requires_python}`. Set a lower bound to indicate the minimum compatible Python version (e.g., `{default}`).",
);
}
warn_user!(
"The `requires-python` field does not contain a lower bound: `{requires_python}`. Set a lower bound to indicate the minimum compatible Python version (e.g., `{default}`).",
);
}
requires_python
} else {
let default =
RequiresPython::greater_than_equal_version(interpreter.python_minor_version());
if let Some(root_project_name) = root_project_name.as_ref() {
warn_user!(
"No `requires-python` field found in `{root_project_name}`. Defaulting to `{default}`.",
);
} else {
warn_user!("No `requires-python` field found in workspace. Defaulting to `{default}`.",);
}
warn_user!("No `requires-python` field found. Defaulting to `{default}`.",);
default
};

Expand Down Expand Up @@ -208,7 +186,7 @@ pub(super) async fn do_lock(
overrides,
dev,
source_trees,
root_project_name,
None,
&extras,
preferences,
EmptyInstalledPackages,
Expand Down
8 changes: 0 additions & 8 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change