diff --git a/crates/pet-conda/tests/ci_test.rs b/crates/pet-conda/tests/ci_test.rs index 03cb4d33..258ade25 100644 --- a/crates/pet-conda/tests/ci_test.rs +++ b/crates/pet-conda/tests/ci_test.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] use serde::Deserialize; use std::path::PathBuf; @@ -387,7 +388,7 @@ fn create_conda_env(mode: &CondaCreateEnvNameOrPath, python_version: Option String { +fn get_version(value: &str) -> String { // Regex to extract just the d.d.d version from the full version string let re = regex::Regex::new(r"\d+\.\d+\.\d+").unwrap(); let captures = re.captures(value).unwrap(); diff --git a/crates/pet-conda/tests/common.rs b/crates/pet-conda/tests/common.rs index 1a282083..fdc752c2 100644 --- a/crates/pet-conda/tests/common.rs +++ b/crates/pet-conda/tests/common.rs @@ -46,6 +46,22 @@ pub struct TestEnvironment { root: Option, globals_locations: Vec, } + +impl Environment for TestEnvironment { + fn get_env_var(&self, key: String) -> Option { + self.vars.get(&key).cloned() + } + fn get_root(&self) -> Option { + self.root.clone() + } + fn get_user_home(&self) -> Option { + self.home.clone() + } + fn get_know_global_search_locations(&self) -> Vec { + self.globals_locations.clone() + } +} + #[allow(dead_code)] pub fn create_test_environment( vars: HashMap, @@ -53,20 +69,6 @@ pub fn create_test_environment( globals_locations: Vec, root: Option, ) -> TestEnvironment { - impl Environment for TestEnvironment { - fn get_env_var(&self, key: String) -> Option { - self.vars.get(&key).cloned() - } - fn get_root(&self) -> Option { - self.root.clone() - } - fn get_user_home(&self) -> Option { - self.home.clone() - } - fn get_know_global_search_locations(&self) -> Vec { - self.globals_locations.clone() - } - } TestEnvironment { vars, home, diff --git a/crates/pet-conda/tests/environments_test.rs b/crates/pet-conda/tests/environments_test.rs index 020c545a..e48ed08d 100644 --- a/crates/pet-conda/tests/environments_test.rs +++ b/crates/pet-conda/tests/environments_test.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] mod common; use common::resolve_test_path; diff --git a/crates/pet-conda/tests/package_test.rs b/crates/pet-conda/tests/package_test.rs index 0dd83cc5..b2dd3d53 100644 --- a/crates/pet-conda/tests/package_test.rs +++ b/crates/pet-conda/tests/package_test.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] mod common; use pet_conda::package::{self, CondaPackageInfo}; diff --git a/crates/pet-conda/tests/utils_test.rs b/crates/pet-conda/tests/utils_test.rs index db56247c..963636b7 100644 --- a/crates/pet-conda/tests/utils_test.rs +++ b/crates/pet-conda/tests/utils_test.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] mod common; use common::resolve_test_path; diff --git a/crates/pet-core/src/python_environment.rs b/crates/pet-core/src/python_environment.rs index 9531a70a..a611ced8 100644 --- a/crates/pet-core/src/python_environment.rs +++ b/crates/pet-core/src/python_environment.rs @@ -416,7 +416,10 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option { #[cfg(test)] mod tests { - use super::*; + #[cfg(windows)] + use super::{get_shortest_executable, PythonEnvironmentKind}; + #[cfg(windows)] + use std::path::PathBuf; #[test] #[cfg(windows)] diff --git a/crates/pet-homebrew/src/environments.rs b/crates/pet-homebrew/src/environments.rs index 4aa82ae0..9e6326ed 100644 --- a/crates/pet-homebrew/src/environments.rs +++ b/crates/pet-homebrew/src/environments.rs @@ -147,12 +147,11 @@ fn get_prefix(_resolved_file: &Path) -> Option { None } -#[cfg(test)] +#[cfg(all(test, unix))] mod tests { use super::*; #[test] - #[cfg(unix)] fn extract_version() { assert_eq!( get_version(&PathBuf::from( diff --git a/crates/pet-poetry/Cargo.toml b/crates/pet-poetry/Cargo.toml index 2a6b4ded..9cf2577f 100644 --- a/crates/pet-poetry/Cargo.toml +++ b/crates/pet-poetry/Cargo.toml @@ -21,3 +21,6 @@ regex = "1.10.4" sha2 = "0.10.6" base64 = "0.22.0" toml = "0.8.14" + +[features] +ci = [] diff --git a/crates/pet-poetry/tests/common.rs b/crates/pet-poetry/tests/common.rs index 4432561b..85676686 100644 --- a/crates/pet-poetry/tests/common.rs +++ b/crates/pet-poetry/tests/common.rs @@ -35,25 +35,27 @@ pub struct TestEnvironment { home: Option, root: Option, } + +impl Environment for TestEnvironment { + fn get_env_var(&self, key: String) -> Option { + self.vars.get(&key).cloned() + } + fn get_root(&self) -> Option { + self.root.clone() + } + fn get_user_home(&self) -> Option { + self.home.clone() + } + fn get_know_global_search_locations(&self) -> Vec { + vec![] + } +} + #[allow(dead_code)] pub fn create_test_environment( vars: HashMap, home: Option, root: Option, ) -> TestEnvironment { - impl Environment for TestEnvironment { - fn get_env_var(&self, key: String) -> Option { - self.vars.get(&key).cloned() - } - fn get_root(&self) -> Option { - self.root.clone() - } - fn get_user_home(&self) -> Option { - self.home.clone() - } - fn get_know_global_search_locations(&self) -> Vec { - vec![] - } - } TestEnvironment { vars, home, root } } diff --git a/crates/pet-poetry/tests/config_test.rs b/crates/pet-poetry/tests/config_test.rs index 92172b6c..ab424c56 100644 --- a/crates/pet-poetry/tests/config_test.rs +++ b/crates/pet-poetry/tests/config_test.rs @@ -83,7 +83,6 @@ fn global_config_with_specific_values() { #[cfg(unix)] #[cfg_attr(any(feature = "ci",), test)] #[allow(dead_code)] - fn local_config_with_specific_values() { use std::path::PathBuf; diff --git a/crates/pet-pyenv/tests/common.rs b/crates/pet-pyenv/tests/common.rs index a6ab9d79..69ed9883 100644 --- a/crates/pet-pyenv/tests/common.rs +++ b/crates/pet-pyenv/tests/common.rs @@ -34,6 +34,22 @@ pub struct TestEnvironment { root: Option, globals_locations: Vec, } + +impl Environment for TestEnvironment { + fn get_env_var(&self, key: String) -> Option { + self.vars.get(&key).cloned() + } + fn get_root(&self) -> Option { + self.root.clone() + } + fn get_user_home(&self) -> Option { + self.home.clone() + } + fn get_know_global_search_locations(&self) -> Vec { + self.globals_locations.clone() + } +} + #[allow(dead_code)] pub fn create_test_environment( vars: HashMap, @@ -41,20 +57,6 @@ pub fn create_test_environment( globals_locations: Vec, root: Option, ) -> TestEnvironment { - impl Environment for TestEnvironment { - fn get_env_var(&self, key: String) -> Option { - self.vars.get(&key).cloned() - } - fn get_root(&self) -> Option { - self.root.clone() - } - fn get_user_home(&self) -> Option { - self.home.clone() - } - fn get_know_global_search_locations(&self) -> Vec { - self.globals_locations.clone() - } - } TestEnvironment { vars, home, diff --git a/crates/pet-pyenv/tests/pyenv_test.rs b/crates/pet-pyenv/tests/pyenv_test.rs index 210d42e3..33b461c7 100644 --- a/crates/pet-pyenv/tests/pyenv_test.rs +++ b/crates/pet-pyenv/tests/pyenv_test.rs @@ -164,7 +164,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.9.9/bin/python", ])]), - ..Default::default() }; let expected_virtual_env = PythonEnvironment { display_name: None, @@ -186,7 +185,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/my-virtual-env/bin/python", ])]), - ..Default::default() }; let expected_3_12_1 = PythonEnvironment { display_name: None, @@ -208,7 +206,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.12.1/bin/python", ])]), - ..Default::default() }; let expected_3_13_dev = PythonEnvironment { display_name: None, @@ -230,7 +227,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.13-dev/bin/python", ])]), - ..Default::default() }; let expected_3_12_1a3 = PythonEnvironment { display_name: None, @@ -252,7 +248,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.12.1a3/bin/python", ])]), - ..Default::default() }; let expected_no_gil = PythonEnvironment { display_name: None, @@ -274,7 +269,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/nogil-3.9.10-1/bin/python", ])]), - ..Default::default() }; let expected_pypy = PythonEnvironment { display_name: None, @@ -296,7 +290,6 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/pypy3.9-7.3.15/bin/python", ])]), - ..Default::default() }; let expected_conda_root = PythonEnvironment { @@ -310,7 +303,6 @@ fn find_pyenv_envs() { manager: Some(expected_conda_manager.clone()), arch: Some(Architecture::X64), symlinks: Some(vec![conda_dir.join("bin").join("python")]), - ..Default::default() }; let expected_conda_one = PythonEnvironment { display_name: None, @@ -323,7 +315,6 @@ fn find_pyenv_envs() { manager: Some(expected_conda_manager.clone()), arch: None, symlinks: Some(vec![conda_dir.join("envs").join("one").join("python")]), - ..Default::default() }; let expected_conda_two = PythonEnvironment { display_name: None, @@ -336,7 +327,6 @@ fn find_pyenv_envs() { manager: Some(expected_conda_manager.clone()), symlinks: Some(vec![conda_dir.join("envs").join("two").join("python")]), arch: None, - ..Default::default() }; let mut expected_envs = vec![ @@ -406,7 +396,6 @@ fn resolve_pyenv_environment() { manager: Some(expected_manager.clone()), arch: None, symlinks: Some(vec![executable]), - ..Default::default() }; let expected_virtual_env = PythonEnvironment { display_name: None, @@ -428,7 +417,6 @@ fn resolve_pyenv_environment() { home.to_str().unwrap(), ".pyenv/versions/my-virtual-env/bin/python", ])]), - ..Default::default() }; // Resolve regular Python installs in Pyenv diff --git a/crates/pet-python-utils/tests/executable_test.rs b/crates/pet-python-utils/tests/executable_test.rs index a578142c..9f3d377d 100644 --- a/crates/pet-python-utils/tests/executable_test.rs +++ b/crates/pet-python-utils/tests/executable_test.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] mod common; use pet_python_utils::executable; diff --git a/crates/pet-python-utils/tests/sys_prefix_test.rs b/crates/pet-python-utils/tests/sys_prefix_test.rs index ba5c5f71..a8eae121 100644 --- a/crates/pet-python-utils/tests/sys_prefix_test.rs +++ b/crates/pet-python-utils/tests/sys_prefix_test.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] mod common; use pet_python_utils::version; diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index 3777d453..52e9bf2a 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] use std::sync::Once; diff --git a/crates/pet/tests/ci_jupyter_container.rs b/crates/pet/tests/ci_jupyter_container.rs index 0e61efd2..f99189fa 100644 --- a/crates/pet/tests/ci_jupyter_container.rs +++ b/crates/pet/tests/ci_jupyter_container.rs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#![cfg(unix)] use std::sync::Once; diff --git a/crates/pet/tests/ci_poetry.rs b/crates/pet/tests/ci_poetry.rs index 8c14d3b0..277c07a0 100644 --- a/crates/pet/tests/ci_poetry.rs +++ b/crates/pet/tests/ci_poetry.rs @@ -40,8 +40,10 @@ fn verify_ci_poetry_global() { let environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&environment)); let poetry_locator = Arc::new(Poetry::from(&environment)); - let mut config = Configuration::default(); - config.workspace_directories = Some(vec![workspace_dir.clone()]); + let config = Configuration { + workspace_directories: Some(vec![workspace_dir.clone()]), + ..Default::default() + }; let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { locator.configure(&config); @@ -110,8 +112,10 @@ fn verify_ci_poetry_project() { let environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&environment)); let poetry_locator = Arc::new(Poetry::from(&environment)); - let mut config = Configuration::default(); - config.workspace_directories = Some(vec![workspace_dir.clone()]); + let config = Configuration { + workspace_directories: Some(vec![workspace_dir.clone()]), + ..Default::default() + }; let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { locator.configure(&config); diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index 7c315efa..7c2a27fa 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -75,8 +75,10 @@ fn verify_validity_of_discovered_envs() { let environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&environment)); let poetry_locator = Arc::new(Poetry::from(&environment)); - let mut config = Configuration::default(); - config.workspace_directories = Some(vec![workspace_dir.clone()]); + let config = Configuration { + workspace_directories: Some(vec![workspace_dir.clone()]), + ..Default::default() + }; let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { locator.configure(&config); @@ -283,19 +285,16 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { } } if let Some(prefix) = environment.clone().prefix { - if interpreter_info.clone().executable == "/usr/local/python/current/bin/python" + if (interpreter_info.clone().executable == "/usr/local/python/current/bin/python" && (prefix.to_str().unwrap() == "/usr/local/python/current" && interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13") || (prefix.to_str().unwrap() == "/usr/local/python/3.10.13" - && interpreter_info.clone().sys_prefix == "/usr/local/python/current") - { - // known issue https://github.com/microsoft/python-environment-tools/issues/64 - } else if interpreter_info.clone().executable - == "/home/codespace/.python/current/bin/python" - && (prefix.to_str().unwrap() == "/home/codespace/.python/current" - && interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13") - || (prefix.to_str().unwrap() == "/usr/local/python/3.10.13" - && interpreter_info.clone().sys_prefix == "/home/codespace/.python/current") + && interpreter_info.clone().sys_prefix == "/usr/local/python/current")) + || (interpreter_info.clone().executable == "/home/codespace/.python/current/bin/python" + && (prefix.to_str().unwrap() == "/home/codespace/.python/current" + && interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13") + || (prefix.to_str().unwrap() == "/usr/local/python/3.10.13" + && interpreter_info.clone().sys_prefix == "/home/codespace/.python/current")) { // known issue https://github.com/microsoft/python-environment-tools/issues/64 } else { @@ -487,20 +486,19 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment, actual.version = expected.clone().version; if let Some(prefix) = expected.clone().prefix { - if actual.clone().executable == Some(PathBuf::from("/usr/local/python/current/bin/python")) + if (actual.clone().executable + == Some(PathBuf::from("/usr/local/python/current/bin/python")) && (prefix.to_str().unwrap() == "/usr/local/python/current" && actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13"))) || (prefix.to_str().unwrap() == "/usr/local/python/3.10.13" - && actual.clone().prefix == Some(PathBuf::from("/usr/local/python/current"))) - { - // known issue https://github.com/microsoft/python-environment-tools/issues/64 - actual.prefix = expected.clone().prefix; - } else if actual.clone().executable - == Some(PathBuf::from("/home/codespace/.python/current/bin/python")) - && (prefix.to_str().unwrap() == "/home/codespace/.python/current" - && actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13"))) - || (prefix.to_str().unwrap() == "/usr/local/python/3.10.13" - && actual.clone().prefix == Some(PathBuf::from("/home/codespace/.python/current"))) + && actual.clone().prefix == Some(PathBuf::from("/usr/local/python/current")))) + || (actual.clone().executable + == Some(PathBuf::from("/home/codespace/.python/current/bin/python")) + && (prefix.to_str().unwrap() == "/home/codespace/.python/current" + && actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13"))) + || (prefix.to_str().unwrap() == "/usr/local/python/3.10.13" + && actual.clone().prefix + == Some(PathBuf::from("/home/codespace/.python/current")))) { // known issue https://github.com/microsoft/python-environment-tools/issues/64 actual.prefix = expected.clone().prefix; @@ -591,8 +589,10 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe( let os_environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&os_environment)); let poetry_locator = Arc::new(Poetry::from(&os_environment)); - let mut config = Configuration::default(); - config.workspace_directories = Some(vec![workspace_dir.clone()]); + let config = Configuration { + workspace_directories: Some(vec![workspace_dir.clone()]), + ..Default::default() + }; let locators = create_locators( conda_locator.clone(), poetry_locator.clone(), @@ -720,13 +720,13 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec { "python".to_string(), ] } else if let Some(prefix) = env.prefix.clone() { - return vec![ + vec![ conda_exe, "run".to_string(), "-p".to_string(), prefix.to_str().unwrap_or_default().to_string(), "python".to_string(), - ]; + ] } else { panic!("Conda environment without name or prefix") } @@ -741,8 +741,8 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec { } } -fn get_python_interpreter_info(cli: &Vec) -> InterpreterInfo { - let mut cli = cli.clone(); +fn get_python_interpreter_info(cli: &[String]) -> InterpreterInfo { + let mut cli = cli.to_owned(); cli.push( resolve_test_path(&["interpreterInfo.py"]) .to_str() diff --git a/crates/pet/tests/common.rs b/crates/pet/tests/common.rs index 634fc59d..07d15da9 100644 --- a/crates/pet/tests/common.rs +++ b/crates/pet/tests/common.rs @@ -22,12 +22,12 @@ pub fn resolve_test_path(paths: &[&str]) -> PathBuf { } #[allow(dead_code)] -pub fn does_version_match(version: &String, expected_version: &String) -> bool { +pub fn does_version_match(version: &str, expected_version: &str) -> bool { let version = get_version(version); expected_version.starts_with(&version) } -fn get_version(value: &String) -> String { +fn get_version(value: &str) -> String { // Regex to extract just the d.d.d version from the full version string let captures = PYTHON_VERSION.captures(value).unwrap(); let version = captures.get(1).unwrap().as_str().to_string(); @@ -39,6 +39,6 @@ fn get_version(value: &String) -> String { } #[allow(dead_code)] -pub fn is_valid_version(value: &String) -> bool { +pub fn is_valid_version(value: &str) -> bool { PYTHON_FULLVERSION.is_match(value) }