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

uv init ignores workspace when --isolated flag is used #5290

Merged
merged 2 commits into from
Jul 22, 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
17 changes: 10 additions & 7 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ pub(crate) async fn init(
explicit_path: Option<String>,
name: Option<PackageName>,
no_readme: bool,
isolated: bool,
preview: PreviewMode,
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user_once!("`uv init` is experimental and may change without warning");
}

let current_dir = std::env::current_dir()?.canonicalize()?;

// Default to the current directory if a path was not provided.
let path = match explicit_path {
None => current_dir.clone(),
None => std::env::current_dir()?.canonicalize()?,
Some(ref path) => PathBuf::from(path),
};

Expand Down Expand Up @@ -67,10 +66,14 @@ pub(crate) async fn init(
let path = path.canonicalize()?;

// Discover the current workspace, if it exists.
let workspace = match ProjectWorkspace::discover(&path, None).await {
Ok(project) => Some(project),
Err(WorkspaceError::MissingPyprojectToml) => None,
Err(err) => return Err(err.into()),
let workspace = if isolated {
None
} else {
match ProjectWorkspace::discover(&path, None).await {
Ok(project) => Some(project),
Err(WorkspaceError::MissingPyprojectToml) => None,
Err(err) => return Err(err.into()),
}
};

// Create the `pyproject.toml`.
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ async fn run_project(
args.path,
args.name,
args.no_readme,
globals.isolated,
globals.preview,
printer,
)
Expand Down
45 changes: 45 additions & 0 deletions crates/uv/tests/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,48 @@ fn init_invalid_names() -> Result<()> {

Ok(())
}

#[test]
fn init_workspace_isolated() -> Result<()> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
"#,
})?;

let child = context.temp_dir.join("foo");
fs_err::create_dir(&child)?;

uv_snapshot!(context.filters(), context.init().current_dir(&child).arg("--isolated"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `uv init` is experimental and may change without warning
Initialized project foo
"###);

let workspace = fs_err::read_to_string(context.temp_dir.join("pyproject.toml"))?;

insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
workspace, @r###"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
"###
);
});

Ok(())
}
Loading