Skip to content

Commit 787f2a7

Browse files
authored
Always invoke found interpreter when uv run python is used (#6363)
Alternative to #6362 Resolves the error mentioned in #6361
1 parent fa0c20d commit 787f2a7

File tree

1 file changed

+24
-7
lines changed
  • crates/uv/src/commands/project

1 file changed

+24
-7
lines changed

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ pub(crate) async fn parse_script(
659659
// Parse the input command.
660660
let command = RunCommand::from(command);
661661

662-
let RunCommand::Python(target, _) = &command else {
662+
let RunCommand::PythonScript(target, _) = &command else {
663663
return Ok(None);
664664
};
665665

@@ -716,8 +716,10 @@ fn can_skip_ephemeral(
716716

717717
#[derive(Debug)]
718718
enum RunCommand {
719+
/// Execute `python`.
720+
Python(Vec<OsString>),
719721
/// Execute a `python` script.
720-
Python(PathBuf, Vec<OsString>),
722+
PythonScript(PathBuf, Vec<OsString>),
721723
/// Execute an external command.
722724
External(OsString, Vec<OsString>),
723725
/// Execute an empty command (in practice, `python` with no arguments).
@@ -728,15 +730,21 @@ impl RunCommand {
728730
/// Return the name of the target executable, for display purposes.
729731
fn display_executable(&self) -> Cow<'_, str> {
730732
match self {
731-
Self::Python(_, _) | Self::Empty => Cow::Borrowed("python"),
733+
Self::Python(_) => Cow::Borrowed("python"),
734+
Self::PythonScript(_, _) | Self::Empty => Cow::Borrowed("python"),
732735
Self::External(executable, _) => executable.to_string_lossy(),
733736
}
734737
}
735738

736739
/// Convert a [`RunCommand`] into a [`Command`].
737740
fn as_command(&self, interpreter: &Interpreter) -> Command {
738741
match self {
739-
Self::Python(target, args) => {
742+
Self::Python(args) => {
743+
let mut process = Command::new(interpreter.sys_executable());
744+
process.args(args);
745+
process
746+
}
747+
Self::PythonScript(target, args) => {
740748
let mut process = Command::new(interpreter.sys_executable());
741749
process.arg(target);
742750
process.args(args);
@@ -755,7 +763,14 @@ impl RunCommand {
755763
impl std::fmt::Display for RunCommand {
756764
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
757765
match self {
758-
Self::Python(target, args) => {
766+
Self::Python(args) => {
767+
write!(f, "python")?;
768+
for arg in args {
769+
write!(f, " {}", arg.to_string_lossy())?;
770+
}
771+
Ok(())
772+
}
773+
Self::PythonScript(target, args) => {
759774
write!(f, "python {}", target.display())?;
760775
for arg in args {
761776
write!(f, " {}", arg.to_string_lossy())?;
@@ -786,12 +801,14 @@ impl From<&ExternalCommand> for RunCommand {
786801
};
787802

788803
let target_path = PathBuf::from(&target);
789-
if target_path
804+
if target.eq_ignore_ascii_case("python") {
805+
Self::Python(args.to_vec())
806+
} else if target_path
790807
.extension()
791808
.is_some_and(|ext| ext.eq_ignore_ascii_case("py"))
792809
&& target_path.exists()
793810
{
794-
Self::Python(target_path, args.to_vec())
811+
Self::PythonScript(target_path, args.to_vec())
795812
} else {
796813
Self::External(
797814
target.clone(),

0 commit comments

Comments
 (0)