Allow uv init in unmanaged projects (#5372)

## Summary

Closes https://github.com/astral-sh/uv/issues/5368.
This commit is contained in:
Charlie Marsh 2024-07-23 16:51:30 -04:00 committed by GitHub
parent c271eda6b6
commit 4863ec8b5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 0 deletions

View file

@ -94,6 +94,7 @@ pub(crate) async fn init(
{
Ok(workspace) => Some(workspace),
Err(WorkspaceError::MissingPyprojectToml) => None,
Err(WorkspaceError::NonWorkspace(_)) => None,
Err(err) => return Err(err.into()),
}
};

View file

@ -1043,3 +1043,41 @@ fn init_requires_python_specifiers() -> Result<()> {
Ok(())
}
/// Run `uv init` from within an unmanaged project.
#[test]
fn init_unmanaged() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {
r"
[tool.uv]
managed = false
",
})?;
uv_snapshot!(context.filters(), context.init().arg("foo"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv init` is experimental and may change without warning
Initialized project `foo` at `[TEMP_DIR]/foo`
"###);
let workspace = fs_err::read_to_string(context.temp_dir.join("pyproject.toml"))?;
insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
workspace, @r###"
[tool.uv]
managed = false
"###
);
});
Ok(())
}