Skip to content

Commit

Permalink
Hint at --no-workspace in uv init failures
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 29, 2024
1 parent 3be4fe5 commit 2e8099f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crates/uv-workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Workspace {
workspace
} else if pyproject_toml.project.is_none() {
// Without a project, it can't be an implicit root
return Err(WorkspaceError::MissingProject(project_path));
return Err(WorkspaceError::MissingProject(pyproject_path));
} else if let Some(workspace) = find_workspace(&project_path, options).await? {
// We have found an explicit root above.
workspace
Expand Down Expand Up @@ -610,7 +610,7 @@ impl Workspace {
};

let pyproject_toml = PyProjectToml::from_string(contents)
.map_err(|err| WorkspaceError::Toml(pyproject_path, Box::new(err)))?;
.map_err(|err| WorkspaceError::Toml(pyproject_path.clone(), Box::new(err)))?;

// Check if the current project is explicitly marked as unmanaged.
if pyproject_toml
Expand All @@ -629,7 +629,7 @@ impl Workspace {

// Extract the package name.
let Some(project) = pyproject_toml.project.clone() else {
return Err(WorkspaceError::MissingProject(member_root));
return Err(WorkspaceError::MissingProject(pyproject_path));
};

debug!(
Expand Down Expand Up @@ -825,7 +825,7 @@ impl ProjectWorkspace {
let project = pyproject_toml
.project
.clone()
.ok_or_else(|| WorkspaceError::MissingProject(pyproject_path.clone()))?;
.ok_or_else(|| WorkspaceError::MissingProject(pyproject_path))?;

Self::from_project(project_root, &project, &pyproject_toml, options).await
}
Expand Down
5 changes: 4 additions & 1 deletion crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ async fn init_project(
warn!("Ignoring workspace discovery error due to `--no-workspace`: {err}");
None
} else {
return Err(err.into());
return Err(anyhow::Error::from(err).context(format!(
"Failed to discover parent workspace; use `{}` to ignore",
"uv init --no-workspace".green()
)));
}
}
}
Expand Down

0 comments on commit 2e8099f

Please sign in to comment.