mirror of https://github.com/astral-sh/uv
Merge 73e68d119c into 0a83bf7dd5
This commit is contained in:
commit
af3ed7709f
|
|
@ -99,6 +99,29 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
|
|||
.map(Cow::Owned)
|
||||
.unwrap_or_else(|| Cow::Borrowed(&*CWD));
|
||||
|
||||
// Validate that the project directory exists if explicitly provided via --project.
|
||||
let skip_project_validation = matches!(
|
||||
&*cli.command,
|
||||
Commands::Project(command) if matches!(**command, ProjectCommand::Init(_))
|
||||
);
|
||||
|
||||
if !skip_project_validation {
|
||||
if let Some(project_path) = cli.top_level.global_args.project.as_ref() {
|
||||
if !project_dir.exists() {
|
||||
bail!(
|
||||
"Project directory `{}` does not exist",
|
||||
project_path.user_display()
|
||||
);
|
||||
}
|
||||
if !project_dir.is_dir() {
|
||||
bail!(
|
||||
"Project path `{}` is not a directory",
|
||||
project_path.user_display()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load environment variables not handled by Clap
|
||||
let environment = EnvironmentOptions::new()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -6092,3 +6092,39 @@ fn run_only_group_and_extra_conflict() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_project_not_found() {
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
// Using --project with a non-existent directory should error.
|
||||
uv_snapshot!(context.filters(), context.run().arg("--project").arg("/tmp/does-not-exist-uv-test").arg("python").arg("-c").arg("print('hello')"), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Project directory `/tmp/does-not-exist-uv-test` does not exist
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_project_is_file() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
// Create a file instead of a directory.
|
||||
let file_path = context.temp_dir.child("not-a-directory");
|
||||
file_path.write_str("")?;
|
||||
|
||||
// Using --project with a file path should error.
|
||||
uv_snapshot!(context.filters(), context.run().arg("--project").arg(file_path.path()).arg("python").arg("-c").arg("print('hello')"), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Project path `not-a-directory` is not a directory
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue