-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
uv init
should not create nested workspace
#5293
Changes from all commits
e87625b
8984216
b0211f5
d999306
9a98eeb
5e2ef84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,13 @@ use std::path::PathBuf; | |
|
||
use anyhow::Result; | ||
use owo_colors::OwoColorize; | ||
|
||
use pep508_rs::PackageName; | ||
use uv_configuration::PreviewMode; | ||
use uv_fs::Simplified; | ||
use uv_warnings::warn_user_once; | ||
use uv_workspace::pyproject_mut::PyProjectTomlMut; | ||
use uv_workspace::{ProjectWorkspace, WorkspaceError}; | ||
use uv_workspace::{Workspace, WorkspaceError}; | ||
|
||
use crate::commands::ExitStatus; | ||
use crate::printer::Printer; | ||
|
@@ -53,7 +54,7 @@ pub(crate) async fn init( | |
.unwrap_or_else(|_| path.simplified().to_path_buf()); | ||
|
||
anyhow::bail!( | ||
"Project is already initialized in {}", | ||
"Project is already initialized in `{}`", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I'm not sure about backticks around the inner colored text. I don't think we have a consistent style-guide for this, but is the color not sufficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do, actually #5209 covers use of backticks in these cases. We want the output to be readable in colorless contexts too. |
||
path.display().cyan() | ||
); | ||
} | ||
|
@@ -69,8 +70,9 @@ pub(crate) async fn init( | |
let workspace = if isolated { | ||
None | ||
} else { | ||
match ProjectWorkspace::discover(&path, None).await { | ||
Ok(project) => Some(project), | ||
// Attempt to find a workspace root. | ||
match Workspace::discover(&path, None).await { | ||
Ok(workspace) => Some(workspace), | ||
Err(WorkspaceError::MissingPyprojectToml) => None, | ||
Err(err) => return Err(err.into()), | ||
} | ||
|
@@ -114,25 +116,20 @@ pub(crate) async fn init( | |
|
||
if let Some(workspace) = workspace { | ||
// Add the package to the workspace. | ||
let mut pyproject = | ||
PyProjectTomlMut::from_toml(workspace.current_project().pyproject_toml())?; | ||
pyproject.add_workspace(path.strip_prefix(workspace.project_root())?)?; | ||
let mut pyproject = PyProjectTomlMut::from_toml(workspace.pyproject_toml())?; | ||
pyproject.add_workspace(path.strip_prefix(workspace.install_path())?)?; | ||
|
||
// Save the modified `pyproject.toml`. | ||
fs_err::write( | ||
workspace.current_project().root().join("pyproject.toml"), | ||
workspace.install_path().join("pyproject.toml"), | ||
pyproject.to_string(), | ||
)?; | ||
|
||
writeln!( | ||
printer.stderr(), | ||
"Adding {} as member of workspace {}", | ||
"Adding `{}` as member of workspace `{}`", | ||
name.cyan(), | ||
workspace | ||
.workspace() | ||
.install_path() | ||
.simplified_display() | ||
.cyan() | ||
workspace.install_path().simplified_display().cyan() | ||
)?; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@konstin - Any reason not to include this? It could be the same as the root member, but for virtual workspaces I can't see another way to get it.