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

Add --no-workspace and --no-project in lieu of --isolated #5465

Merged
merged 1 commit into from
Jul 30, 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
12 changes: 11 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,11 @@ pub struct InitArgs {
#[arg(long)]
pub no_readme: bool,

/// Avoid discovering the workspace in the current directory or any parent directory. Instead,
/// create a standalone project.
#[arg(long, alias = "no_project")]
pub no_workspace: bool,

/// The Python interpreter to use to determine the minimum supported Python version.
///
/// By default, uv uses the virtual environment in the current working directory or any parent
Expand Down Expand Up @@ -1916,9 +1921,14 @@ pub struct RunArgs {
pub refresh: RefreshArgs,

/// Run the command in a specific package in the workspace.
#[arg(long, conflicts_with = "isolated")]
#[arg(long)]
pub package: Option<PackageName>,

/// Avoid discovering the project or workspace in the current directory or any parent directory.
/// Instead, run in an isolated, ephemeral environment populated by the `--with` requirements.
#[arg(long, alias = "no_workspace", conflicts_with = "package")]
pub no_project: bool,

/// The Python interpreter to use to build the run environment.
///
/// By default, uv uses the virtual environment in the current working directory or any parent
Expand Down
14 changes: 7 additions & 7 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) async fn init(
r#virtual: bool,
no_readme: bool,
python: Option<String>,
isolated: bool,
no_workspace: bool,
preview: PreviewMode,
python_preference: PythonPreference,
python_fetch: PythonFetch,
Expand Down Expand Up @@ -76,14 +76,14 @@ pub(crate) async fn init(
};

if r#virtual {
init_virtual_workspace(&path, isolated)?;
init_virtual_workspace(&path, no_workspace)?;
} else {
init_project(
&path,
&name,
no_readme,
python,
isolated,
no_workspace,
python_preference,
python_fetch,
connectivity,
Expand Down Expand Up @@ -133,9 +133,9 @@ pub(crate) async fn init(
}

/// Initialize a virtual workspace at the given path.
fn init_virtual_workspace(path: &Path, isolated: bool) -> Result<()> {
fn init_virtual_workspace(path: &Path, no_workspace: bool) -> Result<()> {
// Ensure that we aren't creating a nested workspace.
if !isolated {
if !no_workspace {
check_nested_workspaces(path, &DiscoveryOptions::default());
}

Expand All @@ -157,7 +157,7 @@ async fn init_project(
name: &PackageName,
no_readme: bool,
python: Option<String>,
isolated: bool,
no_workspace: bool,
python_preference: PythonPreference,
python_fetch: PythonFetch,
connectivity: Connectivity,
Expand All @@ -166,7 +166,7 @@ async fn init_project(
printer: Printer,
) -> Result<()> {
// Discover the current workspace, if it exists.
let workspace = if isolated {
let workspace = if no_workspace {
None
} else {
// Attempt to find a workspace root.
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) async fn run(
dev: bool,
python: Option<String>,
settings: ResolverInstallerSettings,
isolated: bool,
no_project: bool,
preview: PreviewMode,
python_preference: PythonPreference,
python_fetch: PythonFetch,
Expand Down Expand Up @@ -159,8 +159,8 @@ pub(crate) async fn run(
// Discover and sync the base environment.
let base_interpreter = if let Some(script_interpreter) = script_interpreter {
Some(script_interpreter)
} else if isolated {
// package is `None`, isolated and package are marked as conflicting in clap.
} else if no_project {
// package is `None` (`--no-project` and `--package` are marked as conflicting in Clap).
None
} else {
let project = if let Some(package) = package {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ async fn run_project(
args.r#virtual,
args.no_readme,
args.python,
globals.isolated,
args.no_workspace || globals.isolated,
globals.preview,
globals.python_preference,
globals.python_fetch,
Expand Down Expand Up @@ -917,7 +917,7 @@ async fn run_project(
args.dev,
args.python,
args.settings,
globals.isolated,
args.no_project || globals.isolated,
globals.preview,
globals.python_preference,
globals.python_fetch,
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub(crate) struct InitSettings {
pub(crate) name: Option<PackageName>,
pub(crate) r#virtual: bool,
pub(crate) no_readme: bool,
pub(crate) no_workspace: bool,
pub(crate) python: Option<String>,
}

Expand All @@ -167,6 +168,7 @@ impl InitSettings {
name,
r#virtual,
no_readme,
no_workspace,
python,
} = args;

Expand All @@ -175,6 +177,7 @@ impl InitSettings {
name,
r#virtual,
no_readme,
no_workspace,
python,
}
}
Expand All @@ -192,6 +195,7 @@ pub(crate) struct RunSettings {
pub(crate) with: Vec<String>,
pub(crate) with_requirements: Vec<PathBuf>,
pub(crate) package: Option<PackageName>,
pub(crate) no_project: bool,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverInstallerSettings,
Expand All @@ -216,6 +220,7 @@ impl RunSettings {
build,
refresh,
package,
no_project,
python,
} = args;

Expand All @@ -234,6 +239,7 @@ impl RunSettings {
.filter_map(Maybe::into_option)
.collect(),
package,
no_project,
python,
refresh: Refresh::from(refresh),
settings: ResolverInstallerSettings::combine(
Expand Down
47 changes: 46 additions & 1 deletion crates/uv/tests/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ fn init_invalid_names() -> Result<()> {
}

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

let pyproject_toml = context.temp_dir.child("pyproject.toml");
Expand Down Expand Up @@ -634,6 +634,51 @@ fn init_workspace_isolated() -> Result<()> {
Ok(())
}

#[test]
fn init_no_workspace() -> 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("--no-workspace"), @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(())
}

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