Skip to content
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
6 changes: 4 additions & 2 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ impl RunCommand {

/// Return the directory containing the script, if any.
fn script_dir(&self) -> Option<&Path> {
match self {
let parent = match self {
Self::PythonScript(target, _)
| Self::PythonGuiScript(target, _)
| Self::PythonZipapp(target, _) => target.parent(),
Expand All @@ -1617,7 +1617,9 @@ impl RunCommand {
| Self::PythonRemote(..)
| Self::External(..)
| Self::Empty => None,
}
};
// The parent is `Some("")` for bare filenames.
parent.filter(|parent| !parent.as_os_str().is_empty())
}
}

Expand Down
28 changes: 28 additions & 0 deletions crates/uv/tests/it/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6220,3 +6220,31 @@ fn run_target_workspace_discovery() -> Result<()> {

Ok(())
}

/// Test that `--preview-features target-workspace-discovery` works with a bare script
/// filename (no directory component), which would otherwise cause `Path::parent()` to
/// return an empty path.
#[test]
fn run_target_workspace_discovery_bare_script() -> Result<()> {
let context = uv_test::test_context!("3.12");

context
.temp_dir
.child("script.py")
.write_str(r"print('success')")?;

// With the preview feature and a bare filename, the script should run without error.
uv_snapshot!(context.filters(), context.run()
.arg("--preview-features")
.arg("target-workspace-discovery")
.arg("script.py"), @"
success: true
exit_code: 0
----- stdout -----
success

----- stderr -----
");

Ok(())
}