From db8cd40751c646dc9a75873cff1376c0d7720825 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 22:41:02 +1000 Subject: [PATCH 01/10] Resolve with paths not just exe --- crates/pet/src/resolve.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/pet/src/resolve.rs b/crates/pet/src/resolve.rs index c99c1675..673f48a6 100644 --- a/crates/pet/src/resolve.rs +++ b/crates/pet/src/resolve.rs @@ -12,7 +12,7 @@ use pet_core::{ Locator, }; use pet_env_var_path::get_search_paths_from_env_variables; -use pet_python_utils::env::ResolvedPythonEnv; +use pet_python_utils::{env::ResolvedPythonEnv, executable::find_executable}; use crate::locators::identify_python_environment_using_locators; @@ -27,6 +27,17 @@ pub fn resolve_environment( locators: &Arc>>, os_environment: &dyn Environment, ) -> Option { + // First check if executable is actually a file or a path. + let mut executable = executable.to_owned(); + if executable.is_dir() { + executable = match find_executable(&executable) { + Some(exe) => exe, + None => { + warn!("Could not find Python executable in {:?}", executable); + executable + } + }; + } // First check if this is a known environment let env = PythonEnv::new(executable.to_owned(), None, None); let global_env_search_paths: Vec = get_search_paths_from_env_variables(os_environment); From 6c0c1d6d4008852de9c8e3206e1d81963c155743 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 22:57:14 +1000 Subject: [PATCH 02/10] Fix testes --- crates/pet/tests/ci_homebrew_container.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index 54fa0bc1..f0ddbba4 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -60,6 +60,8 @@ fn verify_python_in_homebrew_contaner() { PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3/bin/python3.12"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3.12/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3.12/bin/python3.12"), + PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3"), + PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3.12"), // On CI the Python version can change with minor updates, so we don't check the full version. // PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.4/bin/python3.12"), ]), From ca81b0eed1e9159e479501700fc6d35d7a017ba0 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:06:51 +1000 Subject: [PATCH 03/10] Log versions --- .github/workflows/pr-check.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index a1cbdfb4..3bd52432 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -134,6 +134,10 @@ jobs: run: | pyenv install --list pyenv install 3.12.4 3.8.19 + pyenv local 3.12.4 + pyenv exec python --version + pyenv local 3.8.19 + pyenv exec python --version shell: bash # pyenv-win install list has not updated for a while From f6c944065942931f22151f0621042e38fc620c0e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:08:48 +1000 Subject: [PATCH 04/10] Fix tests --- crates/pet/tests/ci_homebrew_container.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index f0ddbba4..1249707a 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -52,6 +52,8 @@ fn verify_python_in_homebrew_contaner() { executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3")), version: Some("3.12.4".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ + PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3"), + PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3.12"), PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.12"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python3/bin/python3"), @@ -60,8 +62,6 @@ fn verify_python_in_homebrew_contaner() { PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3/bin/python3.12"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3.12/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3.12/bin/python3.12"), - PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3"), - PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3.12"), // On CI the Python version can change with minor updates, so we don't check the full version. // PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.4/bin/python3.12"), ]), From 87301b81aff42ac490908cfd48b98b9797ae0935 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:24:46 +1000 Subject: [PATCH 05/10] Log version of pyenv environments extracted --- crates/pet-pyenv/src/environments.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/pet-pyenv/src/environments.rs b/crates/pet-pyenv/src/environments.rs index 0f2fb51d..cc74274b 100644 --- a/crates/pet-pyenv/src/environments.rs +++ b/crates/pet-pyenv/src/environments.rs @@ -2,6 +2,7 @@ // Licensed under the MIT License. use lazy_static::lazy_static; +use log::trace; use pet_core::{ arch::Architecture, manager::EnvManager, @@ -34,7 +35,21 @@ pub fn get_generic_python_environment( ) -> Option { let file_name = path.file_name()?.to_string_lossy().to_string(); // If we can get the version from the header files, thats more accurate. - let version = version::from_header_files(path).or_else(|| get_version(&file_name)); + let mut version = version::from_header_files(path); + if version.is_none() { + version = get_version(&file_name); + trace!( + "Version (from file path) of pyenv env for {:?} is {:?}", + path, + version + ); + } else { + trace!( + "Version (from header) of pyenv env for {:?} is {:?}", + path, + version + ); + } let arch = if file_name.ends_with("-win32") { Some(Architecture::X86) From 12f4e49fa8ccfb04811a3cada9ad5561fd58f63f Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:27:29 +1000 Subject: [PATCH 06/10] Ignore Pyenv 3.12.4 --- crates/pet/tests/ci_test.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index 306afa75..aca826cd 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -321,13 +321,20 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { } if let Some(version) = environment.clone().version { let expected_version = &interpreter_info.clone().sys_version; - assert!( - does_version_match(&version, expected_version), - "Version mismatch for (expected {:?} to start with {:?}) for {:?}", - expected_version, - version, - environment.clone() - ); + // Ignore Pyenv 3.12.4, known issue here https://github.com/microsoft/python-environment-tools/issues/141 + if environment.executable + != Some(PathBuf::from( + "/home/runner/.pyenv/versions/3.12.4/bin/python", + )) + { + assert!( + does_version_match(&version, expected_version), + "Version mismatch for (expected {:?} to start with {:?}) for {:?}", + expected_version, + version, + environment.clone() + ); + } } } From 0f1058884191f6e4dcc7cb689f2de276b51de2af Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:31:15 +1000 Subject: [PATCH 07/10] Fixes --- .github/workflows/pr-check.yml | 4 ++-- crates/pet/tests/ci_homebrew_container.rs | 4 ++-- crates/pet/tests/ci_test.rs | 21 +++++++-------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 3bd52432..a6a75556 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -133,8 +133,8 @@ jobs: if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos') run: | pyenv install --list - pyenv install 3.12.4 3.8.19 - pyenv local 3.12.4 + pyenv install 3.12.5 3.8.19 + pyenv local 3.12.5 pyenv exec python --version pyenv local 3.8.19 pyenv exec python --version diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index 1249707a..a2ef7ade 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -50,7 +50,7 @@ fn verify_python_in_homebrew_contaner() { let python3_12 = PythonEnvironment { kind: Some(PythonEnvironmentKind::Homebrew), executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3")), - version: Some("3.12.4".to_string()), // This can change on CI, so we don't check it + version: Some("3.12.5".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3.12"), @@ -63,7 +63,7 @@ fn verify_python_in_homebrew_contaner() { PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3.12/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3.12/bin/python3.12"), // On CI the Python version can change with minor updates, so we don't check the full version. - // PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.4/bin/python3.12"), + // PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3.12"), ]), ..Default::default() }; diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index aca826cd..306afa75 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -321,20 +321,13 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { } if let Some(version) = environment.clone().version { let expected_version = &interpreter_info.clone().sys_version; - // Ignore Pyenv 3.12.4, known issue here https://github.com/microsoft/python-environment-tools/issues/141 - if environment.executable - != Some(PathBuf::from( - "/home/runner/.pyenv/versions/3.12.4/bin/python", - )) - { - assert!( - does_version_match(&version, expected_version), - "Version mismatch for (expected {:?} to start with {:?}) for {:?}", - expected_version, - version, - environment.clone() - ); - } + assert!( + does_version_match(&version, expected_version), + "Version mismatch for (expected {:?} to start with {:?}) for {:?}", + expected_version, + version, + environment.clone() + ); } } From 04d8c41f69cc07715d563005e383e517eba2a0cb Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:32:11 +1000 Subject: [PATCH 08/10] Revert --- crates/pet-pyenv/src/environments.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/crates/pet-pyenv/src/environments.rs b/crates/pet-pyenv/src/environments.rs index cc74274b..0f2fb51d 100644 --- a/crates/pet-pyenv/src/environments.rs +++ b/crates/pet-pyenv/src/environments.rs @@ -2,7 +2,6 @@ // Licensed under the MIT License. use lazy_static::lazy_static; -use log::trace; use pet_core::{ arch::Architecture, manager::EnvManager, @@ -35,21 +34,7 @@ pub fn get_generic_python_environment( ) -> Option { let file_name = path.file_name()?.to_string_lossy().to_string(); // If we can get the version from the header files, thats more accurate. - let mut version = version::from_header_files(path); - if version.is_none() { - version = get_version(&file_name); - trace!( - "Version (from file path) of pyenv env for {:?} is {:?}", - path, - version - ); - } else { - trace!( - "Version (from header) of pyenv env for {:?} is {:?}", - path, - version - ); - } + let version = version::from_header_files(path).or_else(|| get_version(&file_name)); let arch = if file_name.ends_with("-win32") { Some(Architecture::X86) From 35c9776afdcb918df9716a85b8b44e462285b59c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:39:16 +1000 Subject: [PATCH 09/10] fix tests --- crates/pet/tests/ci_homebrew_container.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index a2ef7ade..b7032623 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -52,8 +52,6 @@ fn verify_python_in_homebrew_contaner() { executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3")), version: Some("3.12.5".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ - PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3"), - PathBuf::from("/home/linuxbrew/.linuxbrew/Cellar/python@3.12/3.12.5/bin/python3.12"), PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.12"), PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python3/bin/python3"), From 6ca0c5d09183025a7e0eb22154aea8e4fb1377f6 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 21 Aug 2024 23:39:53 +1000 Subject: [PATCH 10/10] revert --- .github/workflows/pr-check.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index a6a75556..0ba26d7c 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -134,10 +134,6 @@ jobs: run: | pyenv install --list pyenv install 3.12.5 3.8.19 - pyenv local 3.12.5 - pyenv exec python --version - pyenv local 3.8.19 - pyenv exec python --version shell: bash # pyenv-win install list has not updated for a while