diff --git a/crates/pet-conda/src/environments.rs b/crates/pet-conda/src/environments.rs index b795d067..7b29b0a4 100644 --- a/crates/pet-conda/src/environments.rs +++ b/crates/pet-conda/src/environments.rs @@ -57,7 +57,7 @@ impl CondaEnvironment { } } // This is a root env. - let builder = PythonEnvironmentBuilder::new(PythonEnvironmentKind::Conda) + let builder = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Conda)) .executable(self.executable.clone()) .version(self.version.clone()) .prefix(Some(self.prefix.clone())) diff --git a/crates/pet-conda/tests/ci_test.rs b/crates/pet-conda/tests/ci_test.rs index aa080f44..3f44703f 100644 --- a/crates/pet-conda/tests/ci_test.rs +++ b/crates/pet-conda/tests/ci_test.rs @@ -54,7 +54,7 @@ fn detect_conda_root() { .unwrap(); assert_eq!(env.prefix, conda_dir.clone().into()); assert_eq!(env.name, Some("base".into())); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, Some(conda_dir.join("bin").join("python"))); assert_eq!(env.version, Some(get_version(&info.python_version))); @@ -93,7 +93,7 @@ fn detect_conda_root_from_path() { assert_eq!(env.prefix, conda_dir.clone().into()); assert_eq!(env.name, Some("base".into())); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, Some(conda_dir.join("bin").join("python"))); assert_eq!(env.version, Some(get_version(&info.python_version))); } @@ -144,7 +144,7 @@ fn detect_new_conda_env() { let prefix = conda_dir.clone().join("envs").join(env_name); assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, Some(env_name.into())); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, prefix.join("bin").join("python").into()); assert!( env.version.clone().unwrap_or_default().starts_with("3.10"), @@ -193,7 +193,7 @@ fn detect_conda_env_from_path() { assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, Some(env_name.into())); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, exe.clone().into()); assert!( env.version.clone().unwrap_or_default().starts_with("3.10"), @@ -245,7 +245,7 @@ fn detect_new_conda_env_without_python() { let prefix = conda_dir.clone().join("envs").join(env_name); assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, Some(env_name.into())); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable.is_none(), true); assert_eq!(env.version.is_none(), true); @@ -293,7 +293,7 @@ fn detect_new_conda_env_created_with_p_flag_without_python() { assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, None); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable.is_none(), true); assert_eq!(env.version.is_none(), true); @@ -345,7 +345,7 @@ fn detect_new_conda_env_created_with_p_flag_with_python() { assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, None); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, exe.into()); assert!( env.version.clone().unwrap_or_default().starts_with("3.10"), diff --git a/crates/pet-conda/tests/lib_test.rs b/crates/pet-conda/tests/lib_test.rs index 4a0df507..eb6524d4 100644 --- a/crates/pet-conda/tests/lib_test.rs +++ b/crates/pet-conda/tests/lib_test.rs @@ -26,7 +26,7 @@ fn find_conda_env_without_manager() { assert_eq!(env.prefix, path.clone().into()); assert_eq!(env.arch, Architecture::X64.into()); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, path.join("bin").join("python").into()); assert_eq!(env.version, "3.12.2".to_string().into()); assert_eq!(env.manager, None); @@ -75,7 +75,7 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() { assert_eq!(env.prefix, path.clone().into()); assert_eq!(env.arch, Architecture::X64.into()); - assert_eq!(env.kind, PythonEnvironmentKind::Conda); + assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); assert_eq!(env.executable, path.join("bin").join("python").into()); assert_eq!(env.version, "3.12.2".to_string().into()); assert_eq!( diff --git a/crates/pet-core/src/python_environment.rs b/crates/pet-core/src/python_environment.rs index 05954e7c..6326b851 100644 --- a/crates/pet-core/src/python_environment.rs +++ b/crates/pet-core/src/python_environment.rs @@ -41,7 +41,7 @@ impl PartialOrd for PythonEnvironmentKind { #[derive(Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] -#[derive(Debug)] +#[derive(Debug, Default)] // Python environment. // Any item that has information is known to be accurate, if an item is missing it is unknown. pub struct PythonEnvironment { @@ -51,7 +51,7 @@ pub struct PythonEnvironment { pub name: Option, // Python executable, can be empty in the case of conda envs that do not have Python installed in them. pub executable: Option, - pub kind: PythonEnvironmentKind, + pub kind: Option, pub version: Option, // SysPrefix for the environment. pub prefix: Option, @@ -93,31 +93,10 @@ impl PartialOrd for PythonEnvironment { } } -impl Default for PythonEnvironment { - fn default() -> Self { - Self { - display_name: None, - name: None, - executable: None, - // Sometimes we might not know the env type. - // Lets never default these to System/Global or others as thats not true. - // Not knowing does not mean it is a system env. - kind: PythonEnvironmentKind::Unknown, - version: None, - prefix: None, - manager: None, - project: None, - arch: None, - symlinks: None, - search_path: None, - } - } -} - impl PythonEnvironment { pub fn new( executable: Option, - kind: PythonEnvironmentKind, + kind: Option, prefix: Option, manager: Option, version: Option, @@ -205,7 +184,7 @@ pub struct PythonEnvironmentBuilder { display_name: Option, name: Option, executable: Option, - kind: PythonEnvironmentKind, + kind: Option, version: Option, prefix: Option, manager: Option, @@ -216,7 +195,7 @@ pub struct PythonEnvironmentBuilder { } impl PythonEnvironmentBuilder { - pub fn new(kind: PythonEnvironmentKind) -> Self { + pub fn new(kind: Option) -> Self { Self { kind, display_name: None, @@ -359,11 +338,11 @@ impl PythonEnvironmentBuilder { // Given a list of executables, return the one with the shortest path. // The shortest path is the most likely to be most user friendly. fn get_shortest_executable( - kind: &PythonEnvironmentKind, + kind: &Option, exes: &Option>, ) -> Option { // For windows store, the exe should always be the one in the WindowsApps folder. - if *kind == PythonEnvironmentKind::WindowsStore { + if *kind == Some(PythonEnvironmentKind::WindowsStore) { if let Some(exes) = exes { if let Some(exe) = exes.iter().find(|e| { e.to_string_lossy().contains("AppData") @@ -398,7 +377,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option { Some(exe.clone()) } else if let Some(prefix) = &env.prefix { // If this is a conda env without Python, then the exe will be prefix/bin/python - if env.kind == PythonEnvironmentKind::Conda { + if env.kind == Some(PythonEnvironmentKind::Conda) { Some(prefix.join("bin").join(if cfg!(windows) { "python.exe" } else { diff --git a/crates/pet-core/src/telemetry/inaccurate_python_info.rs b/crates/pet-core/src/telemetry/inaccurate_python_info.rs index 83ce92ee..7a91828e 100644 --- a/crates/pet-core/src/telemetry/inaccurate_python_info.rs +++ b/crates/pet-core/src/telemetry/inaccurate_python_info.rs @@ -8,7 +8,7 @@ use crate::python_environment::PythonEnvironmentKind; /// And we will not report that as an inaccuracy. pub struct InaccuratePythonEnvironmentInfo { /// Python Env kind - pub kind: PythonEnvironmentKind, + pub kind: Option, /// Whether the actual exe is not what we expected. pub invalid_executable: Option, /// Whether the actual exe was not even in the list of symlinks that we expected. diff --git a/crates/pet-homebrew/src/environments.rs b/crates/pet-homebrew/src/environments.rs index 841c5f6a..2b8861e3 100644 --- a/crates/pet-homebrew/src/environments.rs +++ b/crates/pet-homebrew/src/environments.rs @@ -48,7 +48,7 @@ pub fn get_python_info( symlinks.sort(); symlinks.dedup(); - let env = PythonEnvironmentBuilder::new(PythonEnvironmentKind::Homebrew) + let env = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Homebrew)) .executable(Some(python_exe_from_bin_dir.to_path_buf())) .version(version) .prefix(get_prefix(resolved_exe)) diff --git a/crates/pet-linux-global-python/src/lib.rs b/crates/pet-linux-global-python/src/lib.rs index bc36abc2..f7dee33d 100644 --- a/crates/pet-linux-global-python/src/lib.rs +++ b/crates/pet-linux-global-python/src/lib.rs @@ -209,7 +209,7 @@ fn get_python_in_bin(env: &PythonEnv, is_64bit: bool) -> Option Option { let version = version::from_pyvenv_cfg(path)?; Some( - PythonEnvironmentBuilder::new(PythonEnvironmentKind::PyenvVirtualEnv) + PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::PyenvVirtualEnv)) .executable(Some(executable.to_path_buf())) .version(Some(version)) .prefix(Some(path.to_path_buf())) diff --git a/crates/pet-pyenv/tests/pyenv_test.rs b/crates/pet-pyenv/tests/pyenv_test.rs index fcaec403..e03b3937 100644 --- a/crates/pet-pyenv/tests/pyenv_test.rs +++ b/crates/pet-pyenv/tests/pyenv_test.rs @@ -156,7 +156,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.9.9/bin/python", ])), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.9.9".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -178,7 +178,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/my-virtual-env/bin/python", ])), - kind: PythonEnvironmentKind::PyenvVirtualEnv, + kind: Some(PythonEnvironmentKind::PyenvVirtualEnv), version: Some("3.10.13".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -200,7 +200,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.12.1/bin/python", ])), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.12.1".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -222,7 +222,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.13-dev/bin/python", ])), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.13-dev".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -244,7 +244,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/3.12.1a3/bin/python", ])), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.12.1a3".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -266,7 +266,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/nogil-3.9.10-1/bin/python", ])), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.9.10".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -288,7 +288,7 @@ fn find_pyenv_envs() { home.to_str().unwrap(), ".pyenv/versions/pypy3.9-7.3.15/bin/python", ])), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.9.18".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -308,7 +308,7 @@ fn find_pyenv_envs() { project: None, name: Some("base".to_string()), executable: Some(conda_dir.join("bin").join("python")), - kind: PythonEnvironmentKind::Conda, + kind: Some(PythonEnvironmentKind::Conda), version: Some("3.11.5".to_string()), prefix: Some(conda_dir.clone()), manager: Some(expected_conda_manager.clone()), @@ -321,7 +321,7 @@ fn find_pyenv_envs() { project: None, name: Some("one".to_string()), executable: Some(conda_dir.join("envs").join("one").join("python")), - kind: PythonEnvironmentKind::Conda, + kind: Some(PythonEnvironmentKind::Conda), version: Some("3.11.1".to_string()), prefix: Some(conda_dir.join("envs").join("one")), manager: Some(expected_conda_manager.clone()), @@ -334,7 +334,7 @@ fn find_pyenv_envs() { project: None, name: Some("two".to_string()), executable: Some(conda_dir.join("envs").join("two").join("python")), - kind: PythonEnvironmentKind::Conda, + kind: Some(PythonEnvironmentKind::Conda), version: Some("3.11.1".to_string()), prefix: Some(conda_dir.join("envs").join("two")), manager: Some(expected_conda_manager.clone()), @@ -401,7 +401,7 @@ fn resolve_pyenv_environment() { project: None, name: None, executable: Some(executable.clone()), - kind: PythonEnvironmentKind::Pyenv, + kind: Some(PythonEnvironmentKind::Pyenv), version: Some("3.9.9".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -420,7 +420,7 @@ fn resolve_pyenv_environment() { home.to_str().unwrap(), ".pyenv/versions/my-virtual-env/bin/python", ])), - kind: PythonEnvironmentKind::PyenvVirtualEnv, + kind: Some(PythonEnvironmentKind::PyenvVirtualEnv), version: Some("3.10.13".to_string()), prefix: Some(resolve_test_path(&[ home.to_str().unwrap(), @@ -491,5 +491,5 @@ fn resolve_pyenv_environment() { )); assert_eq!(result.is_some(), true); - assert_eq!(result.unwrap().kind, PythonEnvironmentKind::Conda); + assert_eq!(result.unwrap().kind, Some(PythonEnvironmentKind::Conda)); } diff --git a/crates/pet-reporter/src/environment.rs b/crates/pet-reporter/src/environment.rs index 806430a9..2bae3d74 100644 --- a/crates/pet-reporter/src/environment.rs +++ b/crates/pet-reporter/src/environment.rs @@ -10,7 +10,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option { Some(exe.clone()) } else if let Some(prefix) = &env.prefix { // If this is a conda env without Python, then the exe will be prefix/bin/python - if env.kind == PythonEnvironmentKind::Conda { + if env.kind == Some(PythonEnvironmentKind::Conda) { Some(prefix.join("bin").join(if cfg!(windows) { "python.exe" } else { diff --git a/crates/pet-reporter/src/stdio.rs b/crates/pet-reporter/src/stdio.rs index f42391e6..42bdec28 100644 --- a/crates/pet-reporter/src/stdio.rs +++ b/crates/pet-reporter/src/stdio.rs @@ -17,12 +17,12 @@ use std::{ pub struct StdioReporter { print_list: bool, managers: Arc>>, - environments: Arc>>, + environments: Arc, u16>>>, } pub struct Summary { pub managers: HashMap, - pub environments: HashMap, + pub environments: HashMap, u16>, } impl StdioReporter { diff --git a/crates/pet-venv/src/lib.rs b/crates/pet-venv/src/lib.rs index 075e9a10..46253428 100644 --- a/crates/pet-venv/src/lib.rs +++ b/crates/pet-venv/src/lib.rs @@ -58,7 +58,7 @@ impl Locator for Venv { symlinks.append(&mut find_executables(prefix)); } Some( - PythonEnvironmentBuilder::new(PythonEnvironmentKind::Venv) + PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Venv)) .executable(Some(env.executable.clone())) .version(version) .prefix(prefix) diff --git a/crates/pet-virtualenv/src/lib.rs b/crates/pet-virtualenv/src/lib.rs index 9bcced42..7e5e11af 100644 --- a/crates/pet-virtualenv/src/lib.rs +++ b/crates/pet-virtualenv/src/lib.rs @@ -92,7 +92,7 @@ impl Locator for VirtualEnv { symlinks.append(&mut find_executables(prefix)); } Some( - PythonEnvironmentBuilder::new(PythonEnvironmentKind::VirtualEnv) + PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::VirtualEnv)) .executable(Some(env.executable.clone())) .version(version) .prefix(env.prefix.clone()) diff --git a/crates/pet-virtualenvwrapper/src/lib.rs b/crates/pet-virtualenvwrapper/src/lib.rs index 6c501dfd..a52ba8d1 100644 --- a/crates/pet-virtualenvwrapper/src/lib.rs +++ b/crates/pet-virtualenvwrapper/src/lib.rs @@ -53,7 +53,7 @@ impl Locator for VirtualEnvWrapper { } Some( - PythonEnvironmentBuilder::new(PythonEnvironmentKind::VirtualEnvWrapper) + PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::VirtualEnvWrapper)) .executable(Some(env.executable.clone())) .version(version) .prefix(env.prefix.clone()) diff --git a/crates/pet-windows-registry/src/environments.rs b/crates/pet-windows-registry/src/environments.rs index cf351a23..ece33255 100644 --- a/crates/pet-windows-registry/src/environments.rs +++ b/crates/pet-windows-registry/src/environments.rs @@ -177,24 +177,25 @@ fn get_registry_pythons_from_key_for_company( .ok() .unwrap_or_default(); - let env = - PythonEnvironmentBuilder::new(PythonEnvironmentKind::WindowsRegistry) - .display_name(Some(display_name)) - .executable(Some(executable.clone())) - .version(if version.is_empty() { - None - } else { - Some(version) - }) - .prefix(env_path) - .arch(if architecture.contains("32") { - Some(Architecture::X86) - } else if architecture.contains("64") { - Some(Architecture::X64) - } else { - None - }) - .build(); + let env = PythonEnvironmentBuilder::new(Some( + PythonEnvironmentKind::WindowsRegistry, + )) + .display_name(Some(display_name)) + .executable(Some(executable.clone())) + .version(if version.is_empty() { + None + } else { + Some(version) + }) + .prefix(env_path) + .arch(if architecture.contains("32") { + Some(Architecture::X86) + } else if architecture.contains("64") { + Some(Architecture::X64) + } else { + None + }) + .build(); // env.company = Some(company.to_string()); // env.company_display_name = company_display_name.clone(); environments.push(env); diff --git a/crates/pet-windows-store/src/environments.rs b/crates/pet-windows-store/src/environments.rs index 22390c4b..267c0f99 100644 --- a/crates/pet-windows-store/src/environments.rs +++ b/crates/pet-windows-store/src/environments.rs @@ -52,9 +52,9 @@ impl PotentialPython { let env_path = norm_case(PathBuf::from(result.env_path)); Some( - PythonEnvironmentBuilder::new( + PythonEnvironmentBuilder::new(Some( pet_core::python_environment::PythonEnvironmentKind::WindowsStore, - ) + )) .display_name(Some(result.display_name)) .executable(Some(exe.clone())) .prefix(Some(env_path.clone())) diff --git a/crates/pet/src/locators.rs b/crates/pet/src/locators.rs index f314555c..5cffdfe4 100644 --- a/crates/pet/src/locators.rs +++ b/crates/pet/src/locators.rs @@ -169,9 +169,9 @@ pub fn identify_and_set_search_path(env: &mut PythonEnvironment, search_path: &V // then thats a weird situation, either way, when we cache the result it will re-appear (however for all other workspaces as well) // Thats fine for now (if users complain then we'll find out that there's a problem and we can fix it then). // Else no need to try and identify/fix edge cases that may not exist. - if env.kind == PythonEnvironmentKind::Conda - || env.kind == PythonEnvironmentKind::Venv - || env.kind == PythonEnvironmentKind::VirtualEnv + if env.kind == Some(PythonEnvironmentKind::Conda) + || env.kind == Some(PythonEnvironmentKind::Venv) + || env.kind == Some(PythonEnvironmentKind::VirtualEnv) { if let Some(prefix) = &env.prefix { for path in search_path { @@ -190,7 +190,7 @@ fn create_unknown_env( ) -> PythonEnvironment { // Find all the python exes in the same bin directory. - PythonEnvironmentBuilder::new(fallback_category.unwrap_or(PythonEnvironmentKind::Unknown)) + PythonEnvironmentBuilder::new(fallback_category) .symlinks(find_symlinks(&resolved_env.executable)) .executable(Some(resolved_env.executable)) .prefix(Some(resolved_env.prefix)) diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index abce690a..2bc78b26 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -31,7 +31,7 @@ fn verify_python_in_homebrew_contaner() { let environments = result.environments; let python3_12 = PythonEnvironment { - kind: PythonEnvironmentKind::Homebrew, + 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 symlinks: Some(vec![ @@ -49,7 +49,7 @@ fn verify_python_in_homebrew_contaner() { ..Default::default() }; let python3_11 = PythonEnvironment { - kind: PythonEnvironmentKind::Homebrew, + kind: Some(PythonEnvironmentKind::Homebrew), executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.11")), version: Some("3.11.9".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ diff --git a/crates/pet/tests/ci_jupyter_container.rs b/crates/pet/tests/ci_jupyter_container.rs index 00644efa..22e57a09 100644 --- a/crates/pet/tests/ci_jupyter_container.rs +++ b/crates/pet/tests/ci_jupyter_container.rs @@ -49,7 +49,7 @@ fn verify_python_in_jupyter_contaner() { let environments = result.environments; let conda = PythonEnvironment { - kind: PythonEnvironmentKind::Conda, + kind: Some(PythonEnvironmentKind::Conda), name: Some("base".to_string()), executable: Some(PathBuf::from("/opt/conda/bin/python")), prefix: Some(PathBuf::from("/opt/conda")), @@ -69,7 +69,7 @@ fn verify_python_in_jupyter_contaner() { ..Default::default() }; let codespace_python = PythonEnvironment { - kind: PythonEnvironmentKind::GlobalPaths, + kind: Some(PythonEnvironmentKind::GlobalPaths), executable: Some(PathBuf::from("/home/codespace/.python/current/bin/python")), prefix: Some(PathBuf::from("/usr/local/python/3.10.13")), version: Some("3.10.13.final.0".to_string()), @@ -83,7 +83,7 @@ fn verify_python_in_jupyter_contaner() { ..Default::default() }; let current_python = PythonEnvironment { - kind: PythonEnvironmentKind::GlobalPaths, + kind: Some(PythonEnvironmentKind::GlobalPaths), executable: Some(PathBuf::from("/usr/local/python/current/bin/python")), prefix: Some(PathBuf::from("/usr/local/python/3.10.13")), version: Some("3.10.13.final.0".to_string()), @@ -97,7 +97,7 @@ fn verify_python_in_jupyter_contaner() { ..Default::default() }; let usr_bin_python = PythonEnvironment { - kind: PythonEnvironmentKind::LinuxGlobal, + kind: Some(PythonEnvironmentKind::LinuxGlobal), executable: Some(PathBuf::from("/usr/bin/python3")), prefix: Some(PathBuf::from("/usr")), version: Some("3.8.10.final.0".to_string()), @@ -110,7 +110,7 @@ fn verify_python_in_jupyter_contaner() { ..Default::default() }; let bin_python = PythonEnvironment { - kind: PythonEnvironmentKind::LinuxGlobal, + kind: Some(PythonEnvironmentKind::LinuxGlobal), executable: Some(PathBuf::from("/bin/python3")), prefix: Some(PathBuf::from("/usr")), version: Some("3.8.10.final.0".to_string()), diff --git a/crates/pet/tests/ci_poetry.rs b/crates/pet/tests/ci_poetry.rs index 83b71d53..033b5e95 100644 --- a/crates/pet/tests/ci_poetry.rs +++ b/crates/pet/tests/ci_poetry.rs @@ -47,7 +47,7 @@ fn verify_ci_poetry_global() { let poetry_envs = environments .iter() .filter(|e| { - e.kind == PythonEnvironmentKind::Poetry && e.project == Some(project_dir.clone()) + e.kind == Some(PythonEnvironmentKind::Poetry) && e.project == Some(project_dir.clone()) }) .collect::>(); @@ -107,7 +107,7 @@ fn verify_ci_poetry_project() { let poetry_envs = environments .iter() .filter(|e| { - e.kind == PythonEnvironmentKind::Poetry && e.project == Some(project_dir.clone()) + e.kind == Some(PythonEnvironmentKind::Poetry) && e.project == Some(project_dir.clone()) }) .collect::>(); diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index 0d6c5638..582e1b1d 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -144,9 +144,8 @@ fn check_if_virtualenvwrapper_exists() { let environments = result.environments; assert!( - environments - .iter() - .any(|env| env.kind == PythonEnvironmentKind::VirtualEnvWrapper + environments.iter().any( + |env| env.kind == Some(PythonEnvironmentKind::VirtualEnvWrapper) && env.executable.is_some() && env.prefix.is_some() && env @@ -155,7 +154,8 @@ fn check_if_virtualenvwrapper_exists() { .unwrap_or_default() .to_str() .unwrap_or_default() - .contains("venv_wrapper_env1")), + .contains("venv_wrapper_env1") + ), "Virtualenvwrapper environment not found, found: {environments:?}" ); } @@ -188,7 +188,8 @@ fn check_if_pipenv_exists() { environments .iter() .find(|env| { - env.kind == PythonEnvironmentKind::Pipenv && env.project == Some(project_dir.clone()) + env.kind == Some(PythonEnvironmentKind::Pipenv) + && env.project == Some(project_dir.clone()) }) .expect(format!("Pipenv environment not found, found {environments:?}").as_str()); } @@ -221,9 +222,8 @@ fn check_if_pyenv_virtualenv_exists() { let environments = result.environments; assert!( - environments - .iter() - .any(|env| env.kind == PythonEnvironmentKind::PyenvVirtualEnv + environments.iter().any( + |env| env.kind == Some(PythonEnvironmentKind::PyenvVirtualEnv) && env.executable.is_some() && env.prefix.is_some() && env.manager.is_some() @@ -233,7 +233,8 @@ fn check_if_pyenv_virtualenv_exists() { .unwrap_or_default() .to_str() .unwrap_or_default() - .contains("pyenv-virtualenv-env1")), + .contains("pyenv-virtualenv-env1") + ), "pyenv-virtualenv environment not found, found: {environments:?}" ); } @@ -243,7 +244,7 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { let interpreter_info = get_python_interpreter_info(&run_command); // Home brew has too many syminks, unfortunately its not easy to test in CI. - if environment.kind != PythonEnvironmentKind::Homebrew { + if environment.kind != Some(PythonEnvironmentKind::Homebrew) { let expected_executable = environment.executable.clone().unwrap(); // Ensure the executable is in one of the identified symlinks @@ -258,7 +259,7 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { ); } // If this is a conda env, then the manager, prefix and a few things must exist. - if environment.kind == PythonEnvironmentKind::Conda { + if environment.kind == Some(PythonEnvironmentKind::Conda) { assert!(environment.manager.is_some()); assert!(environment.prefix.is_some()); if environment.executable.is_some() { @@ -628,7 +629,7 @@ struct InterpreterInfo { } fn get_python_run_command(env: &PythonEnvironment) -> Vec { - if env.clone().kind == PythonEnvironmentKind::Conda { + if env.clone().kind == Some(PythonEnvironmentKind::Conda) { if env.executable.is_none() { panic!("Conda environment without executable"); }