Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit project name from workspace errors #4299

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -53,15 +53,7 @@ pub(crate) async fn add(
let upgrade = Upgrade::default();

// 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(),
upgrade,
Expand Down
30 changes: 3 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, PreReleaseMode, RequiresPython,
Expand Down Expand Up @@ -52,15 +51,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,
upgrade,
Expand Down Expand Up @@ -97,7 +88,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,
upgrade: Upgrade,
Expand Down Expand Up @@ -136,27 +126,13 @@ 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 workspace `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 in the workspace. Defaulting to `{default}`.");
default
};

Expand Down Expand Up @@ -230,7 +206,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
Expand Up @@ -55,15 +55,7 @@ pub(crate) async fn remove(
let upgrade = Upgrade::default();

// 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(),
upgrade,
Expand Down
7 changes: 0 additions & 7 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,7 @@ pub(crate) async fn run(
project::init_environment(project.workspace(), python.as_deref(), cache, printer)?;

// 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(),
upgrade,
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ fn lock_requires_python() -> Result<()> {
pygls>1.3.0
cannot be used, we can conclude that pygls>=1.1.0 cannot be used.
And because project==0.1.0 depends on pygls>=1.1.0, we can conclude that project==0.1.0 cannot be used.
And because only project==0.1.0 is available and project depends on project, we can conclude that the requirements are unsatisfiable.
And because only project==0.1.0 is available and you require project, we can conclude that the requirements are unsatisfiable.

hint: The `Requires-Python` requirement (>=3.7) defined in your `pyproject.toml` includes Python versions that are not supported by your dependencies (e.g., pygls>=1.1.0,<=1.2.1 only supports >=3.7.9, <4). Consider using a more restrictive `Requires-Python` requirement (like >=3.7.9, <4).
"###);
Expand Down Expand Up @@ -2149,7 +2149,7 @@ fn lock_requires_python_unbounded() -> Result<()> {

----- stderr -----
warning: `uv lock` is experimental and may change without warning.
warning: The `requires-python` field found in `project` does not contain a lower bound: `<=3.12`. Set a lower bound to indicate the minimum compatible Python version (e.g., `>=3.11`).
warning: The workspace `requires-python` field does not contain a lower bound: `<=3.12`. Set a lower bound to indicate the minimum compatible Python version (e.g., `>=3.11`).
Resolved 2 packages in [TIME]
"###);

Expand Down
6 changes: 3 additions & 3 deletions crates/uv/tests/lock_scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fn fork_marker_disjoint() -> Result<()> {
warning: `uv lock` is experimental and may change without warning.
× No solution found when resolving dependencies:
╰─▶ Because project==0.1.0 depends on package-a{sys_platform == 'linux'}>=2 and package-a{sys_platform == 'linux'}<2, we can conclude that project==0.1.0 cannot be used.
And because only project==0.1.0 is available and project depends on project, we can conclude that the requirements are unsatisfiable.
And because only project==0.1.0 is available and you require project, we can conclude that the requirements are unsatisfiable.
"###
);

Expand Down Expand Up @@ -795,7 +795,7 @@ fn fork_non_local_fork_marker_direct() -> Result<()> {
× No solution found when resolving dependencies:
╰─▶ Because package-b{sys_platform == 'darwin'}==1.0.0 depends on package-c>=2.0.0 and package-a{sys_platform == 'linux'}==1.0.0 depends on package-c<2.0.0, we can conclude that package-a{sys_platform == 'linux'}==1.0.0 and package-b{sys_platform == 'darwin'}==1.0.0 are incompatible.
And because project==0.1.0 depends on package-a{sys_platform == 'linux'}==1.0.0 and package-b{sys_platform == 'darwin'}==1.0.0, we can conclude that project==0.1.0 cannot be used.
And because only project==0.1.0 is available and project depends on project, we can conclude that the requirements are unsatisfiable.
And because only project==0.1.0 is available and you require project, we can conclude that the requirements are unsatisfiable.
"###
);

Expand Down Expand Up @@ -873,7 +873,7 @@ fn fork_non_local_fork_marker_transitive() -> Result<()> {
package-c{sys_platform == 'linux'}>=2.0.0
and package-a==1.0.0 depends on package-c{sys_platform == 'linux'}<2.0.0, we can conclude that package-a==1.0.0 and package-b==1.0.0 are incompatible.
And because project==0.1.0 depends on package-a==1.0.0 and package-b==1.0.0, we can conclude that project==0.1.0 cannot be used.
And because only project==0.1.0 is available and project depends on project, we can conclude that the requirements are unsatisfiable.
And because only project==0.1.0 is available and you require project, we can conclude that the requirements are unsatisfiable.
"###
);

Expand Down
Loading