Skip to content

Commit 12f5cb1

Browse files
authored
Resolve with paths not just exe (#140)
For microsoft/vscode-python#23982
1 parent 8ea2f30 commit 12f5cb1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/pr-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos')
134134
run: |
135135
pyenv install --list
136-
pyenv install 3.12.4 3.8.19
136+
pyenv install 3.12.5 3.8.19
137137
shell: bash
138138

139139
# pyenv-win install list has not updated for a while

crates/pet/src/resolve.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pet_core::{
1212
Locator,
1313
};
1414
use pet_env_var_path::get_search_paths_from_env_variables;
15-
use pet_python_utils::env::ResolvedPythonEnv;
15+
use pet_python_utils::{env::ResolvedPythonEnv, executable::find_executable};
1616

1717
use crate::locators::identify_python_environment_using_locators;
1818

@@ -27,6 +27,17 @@ pub fn resolve_environment(
2727
locators: &Arc<Vec<Arc<dyn Locator>>>,
2828
os_environment: &dyn Environment,
2929
) -> Option<ResolvedEnvironment> {
30+
// First check if executable is actually a file or a path.
31+
let mut executable = executable.to_owned();
32+
if executable.is_dir() {
33+
executable = match find_executable(&executable) {
34+
Some(exe) => exe,
35+
None => {
36+
warn!("Could not find Python executable in {:?}", executable);
37+
executable
38+
}
39+
};
40+
}
3041
// First check if this is a known environment
3142
let env = PythonEnv::new(executable.to_owned(), None, None);
3243
let global_env_search_paths: Vec<PathBuf> = get_search_paths_from_env_variables(os_environment);

crates/pet/tests/ci_homebrew_container.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn verify_python_in_homebrew_contaner() {
5050
let python3_12 = PythonEnvironment {
5151
kind: Some(PythonEnvironmentKind::Homebrew),
5252
executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3")),
53-
version: Some("3.12.4".to_string()), // This can change on CI, so we don't check it
53+
version: Some("3.12.5".to_string()), // This can change on CI, so we don't check it
5454
symlinks: Some(vec![
5555
PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3"),
5656
PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.12"),
@@ -61,7 +61,7 @@ fn verify_python_in_homebrew_contaner() {
6161
PathBuf::from("/home/linuxbrew/.linuxbrew/opt/[email protected]/bin/python3"),
6262
PathBuf::from("/home/linuxbrew/.linuxbrew/opt/[email protected]/bin/python3.12"),
6363
// On CI the Python version can change with minor updates, so we don't check the full version.
64-
// PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.12.4/bin/python3.12"),
64+
// PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.12.5/bin/python3.12"),
6565
]),
6666
..Default::default()
6767
};

0 commit comments

Comments
 (0)