Skip to content

Commit e6a801d

Browse files
committed
feat: add support for .exe and absolute path python
1 parent 0cb2d5e commit e6a801d

File tree

1 file changed

+19
-5
lines changed
  • crates/uv/src/commands/project

1 file changed

+19
-5
lines changed

crates/uv/src/commands/project/run.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -1579,17 +1579,28 @@ fn read_recursion_depth_from_environment_variable() -> anyhow::Result<u32> {
15791579

15801580
/// Matches valid Python executable names and returns the version part if valid:
15811581
/// - ✅ "python" -> Some("")
1582-
/// - ✅ "python39" -> Some("39")
1582+
/// - ✅ "/usr/bin/python3.9" -> Some("3.9")
1583+
/// - ✅ "/path/to/python39" -> Some("39")
15831584
/// - ✅ "python3" -> Some("3")
1584-
/// - ✅ "python3.9" -> Some("3.9")
1585+
/// - ✅ "python3.exe" -> Some("3")
1586+
/// - ✅ "python3.9.exe" -> Some("3.9")
15851587
/// - ❌ "python3abc" -> None
15861588
/// - ❌ "python3.12b3" -> None
15871589
/// - ❌ "" -> None
15881590
/// - ❌ "python-foo" -> None
1591+
/// - ❌ "Python" -> None // Case-sensitive
15891592
fn python_executable_version(executable_command: &str) -> Option<&str> {
1590-
executable_command
1591-
.strip_prefix("python")
1592-
.filter(|version| version.is_empty() || validate_python_version(version).is_ok())
1593+
const PYTHON_MARKER: &str = "python";
1594+
1595+
// Strip suffix for windows .exe
1596+
let command = executable_command
1597+
.strip_suffix(".exe")
1598+
.unwrap_or(executable_command);
1599+
let version_start = command.rfind(PYTHON_MARKER)? + PYTHON_MARKER.len();
1600+
// Retrieve python version string. E.g. "python3.12" -> "3.12"
1601+
let version = command.get(version_start..)?;
1602+
1603+
Some(version).filter(|&v| v.is_empty() || validate_python_version(v).is_ok())
15931604
}
15941605

15951606
/// Validates if a version string is a valid Python major.minor.patch version.
@@ -1628,6 +1639,9 @@ mod tests {
16281639
("python3", Some("3")),
16291640
("python3.9", Some("3.9")),
16301641
("python3.10", Some("3.10")),
1642+
("/usr/bin/python3.9", Some("3.9")),
1643+
("python3.9.exe", Some("3.9")),
1644+
("python3.9.exe", Some("3.9")),
16311645
("python4", Some("4")),
16321646
("python", Some("")),
16331647
("python3.11.3", Some("3.11.3")),

0 commit comments

Comments
 (0)