mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-28 10:50:29 +00:00
Always invoke found interpreter when uv run python is used (#6363)
Alternative to https://github.com/astral-sh/uv/pull/6362 Resolves the error mentioned in #6361
This commit is contained in:
parent
fa0c20d5b1
commit
787f2a7bca
1 changed files with 24 additions and 7 deletions
|
|
@ -659,7 +659,7 @@ pub(crate) async fn parse_script(
|
||||||
// Parse the input command.
|
// Parse the input command.
|
||||||
let command = RunCommand::from(command);
|
let command = RunCommand::from(command);
|
||||||
|
|
||||||
let RunCommand::Python(target, _) = &command else {
|
let RunCommand::PythonScript(target, _) = &command else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -716,8 +716,10 @@ fn can_skip_ephemeral(
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum RunCommand {
|
enum RunCommand {
|
||||||
|
/// Execute `python`.
|
||||||
|
Python(Vec<OsString>),
|
||||||
/// Execute a `python` script.
|
/// Execute a `python` script.
|
||||||
Python(PathBuf, Vec<OsString>),
|
PythonScript(PathBuf, Vec<OsString>),
|
||||||
/// Execute an external command.
|
/// Execute an external command.
|
||||||
External(OsString, Vec<OsString>),
|
External(OsString, Vec<OsString>),
|
||||||
/// Execute an empty command (in practice, `python` with no arguments).
|
/// Execute an empty command (in practice, `python` with no arguments).
|
||||||
|
|
@ -728,7 +730,8 @@ impl RunCommand {
|
||||||
/// Return the name of the target executable, for display purposes.
|
/// Return the name of the target executable, for display purposes.
|
||||||
fn display_executable(&self) -> Cow<'_, str> {
|
fn display_executable(&self) -> Cow<'_, str> {
|
||||||
match self {
|
match self {
|
||||||
Self::Python(_, _) | Self::Empty => Cow::Borrowed("python"),
|
Self::Python(_) => Cow::Borrowed("python"),
|
||||||
|
Self::PythonScript(_, _) | Self::Empty => Cow::Borrowed("python"),
|
||||||
Self::External(executable, _) => executable.to_string_lossy(),
|
Self::External(executable, _) => executable.to_string_lossy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -736,7 +739,12 @@ impl RunCommand {
|
||||||
/// Convert a [`RunCommand`] into a [`Command`].
|
/// Convert a [`RunCommand`] into a [`Command`].
|
||||||
fn as_command(&self, interpreter: &Interpreter) -> Command {
|
fn as_command(&self, interpreter: &Interpreter) -> Command {
|
||||||
match self {
|
match self {
|
||||||
Self::Python(target, args) => {
|
Self::Python(args) => {
|
||||||
|
let mut process = Command::new(interpreter.sys_executable());
|
||||||
|
process.args(args);
|
||||||
|
process
|
||||||
|
}
|
||||||
|
Self::PythonScript(target, args) => {
|
||||||
let mut process = Command::new(interpreter.sys_executable());
|
let mut process = Command::new(interpreter.sys_executable());
|
||||||
process.arg(target);
|
process.arg(target);
|
||||||
process.args(args);
|
process.args(args);
|
||||||
|
|
@ -755,7 +763,14 @@ impl RunCommand {
|
||||||
impl std::fmt::Display for RunCommand {
|
impl std::fmt::Display for RunCommand {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Python(target, args) => {
|
Self::Python(args) => {
|
||||||
|
write!(f, "python")?;
|
||||||
|
for arg in args {
|
||||||
|
write!(f, " {}", arg.to_string_lossy())?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Self::PythonScript(target, args) => {
|
||||||
write!(f, "python {}", target.display())?;
|
write!(f, "python {}", target.display())?;
|
||||||
for arg in args {
|
for arg in args {
|
||||||
write!(f, " {}", arg.to_string_lossy())?;
|
write!(f, " {}", arg.to_string_lossy())?;
|
||||||
|
|
@ -786,12 +801,14 @@ impl From<&ExternalCommand> for RunCommand {
|
||||||
};
|
};
|
||||||
|
|
||||||
let target_path = PathBuf::from(&target);
|
let target_path = PathBuf::from(&target);
|
||||||
if target_path
|
if target.eq_ignore_ascii_case("python") {
|
||||||
|
Self::Python(args.to_vec())
|
||||||
|
} else if target_path
|
||||||
.extension()
|
.extension()
|
||||||
.is_some_and(|ext| ext.eq_ignore_ascii_case("py"))
|
.is_some_and(|ext| ext.eq_ignore_ascii_case("py"))
|
||||||
&& target_path.exists()
|
&& target_path.exists()
|
||||||
{
|
{
|
||||||
Self::Python(target_path, args.to_vec())
|
Self::PythonScript(target_path, args.to_vec())
|
||||||
} else {
|
} else {
|
||||||
Self::External(
|
Self::External(
|
||||||
target.clone(),
|
target.clone(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue