Skip to content

Commit

Permalink
refactor: use which to find the correct python executable (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra authored Feb 18, 2024
1 parent 8c301ba commit 85f1142
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rattler_installs_packages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async-recursion = "1.0.5"
fs-err = "2.11.0"
fs_extra = "1.3.0"
async_http_range_reader = "0.6.0"
which = "6.0.0"

[dev-dependencies]
anyhow = "1.0.79"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ pub fn system_python_executable() -> Result<&'static PathBuf, FindPythonError> {
// When installed with homebrew on macOS, the python3 executable is called `python3` instead
// Also on some ubuntu installs this is the case
// For windows it should just be python
let output = match std::process::Command::new("python3")
let path = which::which("python3")
.or_else(|_| which::which("python"))
.map_err(|_| FindPythonError::NotFound)?;

// The found binary may not actually refer to the actual python executable,
// this can be because its symlinked, or it's actually a script that invokes python.
//
// Execute the binary itself to determine where the interpreter is located.
let output = match std::process::Command::new(path)
.arg("-c")
.arg("import sys; print(sys.executable, end='')")
.output()
Expand Down

0 comments on commit 85f1142

Please sign in to comment.