From ae335aa07696314b9d94ae3efc17fe70c86afed4 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Tue, 2 Sep 2025 17:17:37 -0700 Subject: [PATCH 1/8] Fix to detect `venv` with `pipenv` installed in it as `pipenv` environment --- crates/pet-pipenv/src/lib.rs | 45 ++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/crates/pet-pipenv/src/lib.rs b/crates/pet-pipenv/src/lib.rs index b727a11d..c3f5a6ea 100644 --- a/crates/pet-pipenv/src/lib.rs +++ b/crates/pet-pipenv/src/lib.rs @@ -20,22 +20,35 @@ mod env_variables; fn get_pipenv_project(env: &PythonEnv) -> Option { if let Some(prefix) = &env.prefix { - get_pipenv_project_from_prefix(prefix) - } else { - // If the parent is bin or script, then get the parent. - let bin = env.executable.parent()?; - if bin.file_name().unwrap_or_default() == Path::new("bin") - || bin.file_name().unwrap_or_default() == Path::new("Scripts") - { - get_pipenv_project_from_prefix(env.executable.parent()?.parent()?) - } else { - get_pipenv_project_from_prefix(env.executable.parent()?) + if let Some(project) = get_pipenv_project_from_prefix(prefix) { + return Some(project); + } + } + + // We can also have a venv in the workspace that has pipenv installed in it. + // In such cases, the project is the workspace folder containing the venv. + if let Some(project) = &env.project { + if project.join("Pipfile").exists() { + return Some(project.clone()); } } + + // If the parent is bin or script, then get the parent. + let bin = env.executable.parent()?; + if bin.file_name().unwrap_or_default() == Path::new("bin") + || bin.file_name().unwrap_or_default() == Path::new("Scripts") + { + get_pipenv_project_from_prefix(env.executable.parent()?.parent()?) + } else { + get_pipenv_project_from_prefix(env.executable.parent()?) + } } fn get_pipenv_project_from_prefix(prefix: &Path) -> Option { let project_file = prefix.join(".project"); + if !project_file.exists() { + return None; + } let contents = fs::read_to_string(project_file).ok()?; let project_folder = norm_case(PathBuf::from(contents.trim().to_string())); if project_folder.exists() { @@ -45,12 +58,24 @@ fn get_pipenv_project_from_prefix(prefix: &Path) -> Option { } } +fn is_pipenv_from_project(env: &PythonEnv) -> bool { + if let Some(project) = &env.project { + if project.join("Pipfile").exists() { + return true; + } + } + false +} + fn is_pipenv(env: &PythonEnv, env_vars: &EnvVariables) -> bool { if let Some(project_path) = get_pipenv_project(env) { if project_path.join(env_vars.pipenv_pipfile.clone()).exists() { return true; } } + if is_pipenv_from_project(env) { + return true; + } // If we have a Pipfile, then this is a pipenv environment. // Else likely a virtualenvwrapper or the like. if let Some(project_path) = get_pipenv_project(env) { From 8893c4a79da0d86d1460385d29e14bfc003df840 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Tue, 2 Sep 2025 17:51:31 -0700 Subject: [PATCH 2/8] fix error --- crates/pet-pipenv/src/lib.rs | 122 +++++++++++++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 6 deletions(-) diff --git a/crates/pet-pipenv/src/lib.rs b/crates/pet-pipenv/src/lib.rs index c3f5a6ea..e5e6f353 100644 --- a/crates/pet-pipenv/src/lib.rs +++ b/crates/pet-pipenv/src/lib.rs @@ -23,13 +23,36 @@ fn get_pipenv_project(env: &PythonEnv) -> Option { if let Some(project) = get_pipenv_project_from_prefix(prefix) { return Some(project); } + // If there's no .project file, but the venv lives inside the project folder + // (e.g., /.venv or /venv), then the project is the parent + // directory of the venv. Detect that by checking for a Pipfile next to the venv. + if let Some(parent) = prefix.parent() { + let project_folder = parent; + if project_folder.join("Pipfile").exists() { + return Some(project_folder.to_path_buf()); + } + } } // We can also have a venv in the workspace that has pipenv installed in it. // In such cases, the project is the workspace folder containing the venv. - if let Some(project) = &env.project { - if project.join("Pipfile").exists() { - return Some(project.clone()); + // Derive the project folder from the executable path when prefix isn't available. + // Typical layout: /.venv/{bin|Scripts}/python + // So walk up to {bin|Scripts} -> venv dir -> project dir and check for Pipfile. + if let Some(bin) = env.executable.parent() { + let venv_dir = if bin.file_name().unwrap_or_default() == Path::new("bin") + || bin.file_name().unwrap_or_default() == Path::new("Scripts") + { + bin.parent() + } else { + Some(bin) + }; + if let Some(venv_dir) = venv_dir { + if let Some(project_dir) = venv_dir.parent() { + if project_dir.join("Pipfile").exists() { + return Some(project_dir.to_path_buf()); + } + } } } @@ -59,9 +82,29 @@ fn get_pipenv_project_from_prefix(prefix: &Path) -> Option { } fn is_pipenv_from_project(env: &PythonEnv) -> bool { - if let Some(project) = &env.project { - if project.join("Pipfile").exists() { - return true; + // If the env prefix is inside a project folder, check that folder for a Pipfile. + if let Some(prefix) = &env.prefix { + if let Some(project_dir) = prefix.parent() { + if project_dir.join("Pipfile").exists() { + return true; + } + } + } + // Derive from the executable path as a fallback. + if let Some(bin) = env.executable.parent() { + let venv_dir = if bin.file_name().unwrap_or_default() == Path::new("bin") + || bin.file_name().unwrap_or_default() == Path::new("Scripts") + { + bin.parent() + } else { + Some(bin) + }; + if let Some(venv_dir) = venv_dir { + if let Some(project_dir) = venv_dir.parent() { + if project_dir.join("Pipfile").exists() { + return true; + } + } } } false @@ -144,3 +187,70 @@ impl Locator for PipEnv { // } } + +#[cfg(test)] +mod tests { + use super::*; + use std::time::{SystemTime, UNIX_EPOCH}; + + fn unique_temp_dir() -> PathBuf { + let mut dir = std::env::temp_dir(); + let nanos = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_nanos(); + dir.push(format!("pet_pipenv_test_{}", nanos)); + dir + } + + #[test] + fn infer_project_for_venv_in_project() { + let project_dir = unique_temp_dir(); + let venv_dir = project_dir.join(".venv"); + let bin_dir = if cfg!(windows) { + venv_dir.join("Scripts") + } else { + venv_dir.join("bin") + }; + let python_exe = if cfg!(windows) { + bin_dir.join("python.exe") + } else { + bin_dir.join("python") + }; + + // Create directories and files + std::fs::create_dir_all(&bin_dir).unwrap(); + std::fs::write(project_dir.join("Pipfile"), b"[[source]]\n").unwrap(); + // Touch python exe file + std::fs::write(&python_exe, b"").unwrap(); + // Touch pyvenv.cfg in venv root so PythonEnv::new logic would normally detect prefix + std::fs::write(venv_dir.join("pyvenv.cfg"), b"version = 3.12.0\n").unwrap(); + + // Construct PythonEnv directly + let env = PythonEnv { + executable: norm_case(python_exe.clone()), + prefix: Some(norm_case(venv_dir.clone())), + version: None, + symlinks: None, + }; + + // Validate helper infers project + let inferred = get_pipenv_project(&env).expect("expected project path"); + assert_eq!(inferred, norm_case(project_dir.clone())); + + // Validate locator populates project + let locator = PipEnv { + env_vars: EnvVariables { + pipenv_max_depth: 3, + pipenv_pipfile: "Pipfile".to_string(), + }, + }; + let result = locator + .try_from(&env) + .expect("expected locator to return environment"); + assert_eq!(result.project, Some(norm_case(project_dir.clone()))); + + // Cleanup + std::fs::remove_dir_all(&project_dir).ok(); + } +} From f346c90581266f689ab6c28bcbb798a1ee771f61 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Sep 2025 00:57:50 +0000 Subject: [PATCH 3/8] Initial plan From eada48561e482fb623743e220d90a1ac67b99943 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Sep 2025 01:08:20 +0000 Subject: [PATCH 4/8] Fix initial clippy warnings: unused imports, non-local impl blocks, and function restructuring Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com> --- crates/pet-conda/tests/common.rs | 30 +++++---- crates/pet-core/src/python_environment.rs | 1 + crates/pet-python-utils/src/executable.rs | 80 +++++++++++------------ crates/pet/tests/ci_homebrew_container.rs | 2 +- crates/pet/tests/ci_jupyter_container.rs | 2 +- crates/pet/tests/ci_poetry.rs | 12 ++-- crates/pet/tests/common.rs | 6 +- 7 files changed, 70 insertions(+), 63 deletions(-) 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-core/src/python_environment.rs b/crates/pet-core/src/python_environment.rs index 9531a70a..d52d9baf 100644 --- a/crates/pet-core/src/python_environment.rs +++ b/crates/pet-core/src/python_environment.rs @@ -416,6 +416,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option { #[cfg(test)] mod tests { + #[cfg(windows)] use super::*; #[test] diff --git a/crates/pet-python-utils/src/executable.rs b/crates/pet-python-utils/src/executable.rs index 9808584b..84b9286a 100644 --- a/crates/pet-python-utils/src/executable.rs +++ b/crates/pet-python-utils/src/executable.rs @@ -119,6 +119,46 @@ fn is_python_executable_name(exe: &Path) -> bool { } } +pub fn should_search_for_environments_in_path>(path: &P) -> bool { + // Never search in the .git folder + // Never search in the node_modules folder + // Mostly copied from https://github.com/github/gitignore/blob/main/Python.gitignore + let folders_to_ignore = [ + "node_modules", + ".cargo", + ".devcontainer", + ".github", + ".git", + ".tox", + ".nox", + ".hypothesis", + ".ipynb_checkpoints", + ".eggs", + ".coverage", + ".cache", + ".pyre", + ".ptype", + ".pytest_cache", + ".vscode", + "__pycache__", + "__pypackages__", + ".mypy_cache", + "cython_debug", + "env.bak", + "venv.bak", + "Scripts", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env. + "bin", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env. + ]; + for folder in folders_to_ignore.iter() { + if path.as_ref().ends_with(folder) { + trace!("Ignoring folder: {:?}", path.as_ref()); + return false; + } + } + + true +} + #[cfg(test)] mod tests { use super::*; @@ -186,43 +226,3 @@ mod tests { )); } } - -pub fn should_search_for_environments_in_path>(path: &P) -> bool { - // Never search in the .git folder - // Never search in the node_modules folder - // Mostly copied from https://github.com/github/gitignore/blob/main/Python.gitignore - let folders_to_ignore = [ - "node_modules", - ".cargo", - ".devcontainer", - ".github", - ".git", - ".tox", - ".nox", - ".hypothesis", - ".ipynb_checkpoints", - ".eggs", - ".coverage", - ".cache", - ".pyre", - ".ptype", - ".pytest_cache", - ".vscode", - "__pycache__", - "__pypackages__", - ".mypy_cache", - "cython_debug", - "env.bak", - "venv.bak", - "Scripts", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env. - "bin", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env. - ]; - for folder in folders_to_ignore.iter() { - if path.as_ref().ends_with(folder) { - trace!("Ignoring folder: {:?}", path.as_ref()); - return false; - } - } - - true -} diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index 9b0e67ea..3777d453 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -107,7 +107,7 @@ fn verify_python_in_homebrew_contaner() { let python_env = environments .iter() .find(|e| e.executable == env.executable) - .expect(format!("Expected to find python environment {:?}", env.executable).as_str()); + .unwrap_or_else(|| panic!("Expected to find python environment {:?}", env.executable)); assert_eq!(python_env.executable, env.executable); assert_eq!(python_env.kind, env.kind); assert_eq!(python_env.manager, env.manager); diff --git a/crates/pet/tests/ci_jupyter_container.rs b/crates/pet/tests/ci_jupyter_container.rs index 4ecdbb18..0e61efd2 100644 --- a/crates/pet/tests/ci_jupyter_container.rs +++ b/crates/pet/tests/ci_jupyter_container.rs @@ -137,7 +137,7 @@ fn verify_python_in_jupyter_contaner() { let python_env = environments .iter() .find(|e| e.executable == env.executable) - .expect(format!("Expected to find python environment {:?}", env.executable).as_str()); + .unwrap_or_else(|| panic!("Expected to find python environment {:?}", env.executable)); assert_eq!( python_env.executable, env.executable, "Expected exe to be same when comparing {python_env:?} and {env:?}" 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/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) } From 5a5d71cc428b3b7f38bd0a739783fd4a7f5822bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Sep 2025 01:14:22 +0000 Subject: [PATCH 5/8] Fix more clippy warnings: field assignments, expect_fun_call, ptr_arg, and cfg conditions Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com> --- crates/pet-poetry/tests/common.rs | 30 +++++++++--------- crates/pet-poetry/tests/config_test.rs | 19 +++++------- crates/pet/tests/ci_test.rs | 42 +++++++++++++------------- 3 files changed, 45 insertions(+), 46 deletions(-) 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 19d100d2..824f0021 100644 --- a/crates/pet-poetry/tests/config_test.rs +++ b/crates/pet-poetry/tests/config_test.rs @@ -4,7 +4,7 @@ mod common; #[cfg(unix)] -#[cfg_attr(any(feature = "ci",), test)] +#[test] #[allow(dead_code)] fn global_config_with_defaults() { use common::create_env_variables; @@ -37,7 +37,7 @@ fn global_config_with_defaults() { } #[cfg(unix)] -#[cfg_attr(any(feature = "ci",), test)] +#[test] #[allow(dead_code)] fn global_config_with_specific_values() { use std::path::PathBuf; @@ -69,13 +69,12 @@ fn global_config_with_specific_values() { "config.toml" ])) ); - assert_eq!( + assert!( config .clone() .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - true + .unwrap_or_default() ); assert_eq!( config.clone().unwrap().virtualenvs_path, @@ -84,9 +83,8 @@ fn global_config_with_specific_values() { } #[cfg(unix)] -#[cfg_attr(any(feature = "ci",), test)] +#[test] #[allow(dead_code)] - fn local_config_with_specific_values() { use std::path::PathBuf; @@ -117,13 +115,12 @@ fn local_config_with_specific_values() { "poetry.toml" ])) ); - assert_eq!( - config + assert!( + !config .clone() .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - false + .unwrap_or_default() ); assert_eq!( config.clone().unwrap().virtualenvs_path, diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index b4d432aa..c2d36f89 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -66,7 +66,7 @@ fn verify_validity_of_discovered_envs() { use pet::{find::find_and_report_envs, locators::create_locators}; use pet_conda::Conda; use pet_core::{os_environment::EnvironmentApi, Configuration}; - use std::{env, sync::Arc, thread}; + use std::{env, sync::Arc}; setup(); @@ -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); @@ -205,7 +207,7 @@ fn check_if_pipenv_exists() { env.kind == Some(PythonEnvironmentKind::Pipenv) && env.project == Some(workspace_dir.clone()) }) - .expect(format!("Pipenv environment not found, found {environments:?}").as_str()); + .unwrap_or_else(|| panic!("Pipenv environment not found, found {environments:?}")); } #[cfg(unix)] @@ -367,10 +369,7 @@ fn verify_we_can_get_same_env_info_using_from_with_exe( let env = PythonEnv::new(executable.clone(), None, None); let resolved = identify_python_environment_using_locators(&env, &locators, &global_env_search_paths) - .expect( - format!("Failed to resolve environment using `resolve` for {environment:?}") - .as_str(), - ); + .unwrap_or_else(|| panic!("Failed to resolve environment using `resolve` for {environment:?}")); trace!( "For exe {:?} we got Environment = {:?}, To compare against {:?}", executable, @@ -603,8 +602,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(), @@ -614,9 +615,8 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe( locator.configure(&config); } - let env = resolve_environment(&executable, &locators, &os_environment).expect( - format!("Failed to resolve environment using `resolve` for {environment:?}").as_str(), - ); + let env = resolve_environment(executable, &locators, &os_environment) + .unwrap_or_else(|| panic!("Failed to resolve environment using `resolve` for {environment:?}")); trace!( "For exe {:?} we got Environment = {:?}, To compare against {:?}", executable, @@ -724,21 +724,21 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec { None => get_conda_exe().to_string(), }; if let Some(name) = env.name.clone() { - return vec![ + vec![ conda_exe, "run".to_string(), "-n".to_string(), name, "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") } @@ -753,8 +753,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() @@ -765,13 +765,13 @@ fn get_python_interpreter_info(cli: &Vec) -> InterpreterInfo { let output = std::process::Command::new(cli.first().unwrap()) .args(&cli[1..]) .output() - .expect(format!("Failed to execute command {cli:?}").as_str()); + .unwrap_or_else(|_| panic!("Failed to execute command {cli:?}")); let output = String::from_utf8(output.stdout).unwrap(); trace!("Get Interpreter Info: {:?} => {:?}", cli, output); let output = output .split_once("503bebe7-c838-4cea-a1bc-0f2963bcb657") .unwrap() .1; - let info: InterpreterInfo = serde_json::from_str(&output).unwrap(); + let info: InterpreterInfo = serde_json::from_str(output).unwrap(); info } From 5094581e215c1a0fa9fea03c45622f111c6c95c2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Sep 2025 01:18:15 +0000 Subject: [PATCH 6/8] Fix repetitive clippy patterns: needless struct updates, useless conversions, assert_eq with bool Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com> --- crates/pet-poetry/src/config.rs | 30 ++++++++++++------------- crates/pet-poetry/src/pyproject_toml.rs | 2 +- crates/pet-pyenv/tests/common.rs | 30 +++++++++++++------------ crates/pet-pyenv/tests/pyenv_test.rs | 8 +++---- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/pet-poetry/src/config.rs b/crates/pet-poetry/src/config.rs index 8b4f8632..feb541b7 100644 --- a/crates/pet-poetry/src/config.rs +++ b/crates/pet-poetry/src/config.rs @@ -242,7 +242,7 @@ create = false "#; assert_eq!( - parse_contents(&cfg.to_string()) + parse_contents(cfg) .unwrap() .virtualenvs_in_project .unwrap_or_default(), @@ -256,7 +256,7 @@ create = false "#; assert_eq!( - parse_contents(&cfg.to_string()) + parse_contents(cfg) .unwrap() .virtualenvs_in_project .unwrap_or_default(), @@ -269,7 +269,7 @@ create = false "#; assert_eq!( - parse_contents(&cfg.to_string()) + parse_contents(cfg) .unwrap() .virtualenvs_in_project .unwrap_or_default(), @@ -279,22 +279,20 @@ create = false let cfg = r#" virtualenvs.in-project = true # comment "#; - assert_eq!( - parse_contents(&cfg.to_string()) + assert!( + parse_contents(&cfg) .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - true + .unwrap_or_default() ); let cfg = r#" "#; - assert_eq!( - parse_contents(&cfg.to_string()) + assert!( + !parse_contents(&cfg) .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - false + .unwrap_or_default() ); } @@ -305,7 +303,7 @@ cache-dir = "/path/to/cache/directory" "#; assert_eq!( - parse_contents(&cfg.to_string()).unwrap().cache_dir, + parse_contents(cfg).unwrap().cache_dir, Some(PathBuf::from("/path/to/cache/directory".to_string())) ); @@ -313,7 +311,7 @@ cache-dir = "/path/to/cache/directory" some-other-value = 1234 "#; - assert_eq!(parse_contents(&cfg.to_string()).unwrap().cache_dir, None); + assert_eq!(parse_contents(cfg).unwrap().cache_dir, None); } #[test] @@ -323,7 +321,7 @@ virtualenvs.path = "/path/to/virtualenvs" "#; assert_eq!( - parse_contents(&cfg.to_string()).unwrap().virtualenvs_path, + parse_contents(cfg).unwrap().virtualenvs_path, Some(PathBuf::from("/path/to/virtualenvs".to_string())) ); @@ -332,7 +330,7 @@ some-other-value = 1234 "#; assert_eq!( - parse_contents(&cfg.to_string()).unwrap().virtualenvs_path, + parse_contents(cfg).unwrap().virtualenvs_path, None ); } @@ -343,7 +341,7 @@ some-other-value = 1234 cache-dir = "/path/to/cache/directory" "#; assert_eq!( - parse_contents(&cfg.to_string()).unwrap().virtualenvs_path, + parse_contents(cfg).unwrap().virtualenvs_path, Some(PathBuf::from("/path/to/cache/directory/virtualenvs")) ); } diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index de5dc69c..0bd785ad 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -90,7 +90,7 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" "#; assert_eq!( - parse_contents(&cfg.to_string(), Path::new("pyproject.toml")) + parse_contents(cfg, Path::new("pyproject.toml")) .unwrap() .name, "poetry-demo" 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 ea46aee5..f62d00b3 100644 --- a/crates/pet-pyenv/tests/pyenv_test.rs +++ b/crates/pet-pyenv/tests/pyenv_test.rs @@ -29,8 +29,8 @@ fn does_not_find_any_pyenv_envs() { let environments = reporter.environments.lock().unwrap().clone(); let managers = reporter.managers.lock().unwrap().clone(); - assert_eq!(managers.is_empty(), true); - assert_eq!(environments.is_empty(), true); + assert!(managers.is_empty()); + assert!(environments.is_empty()); } #[test] @@ -63,7 +63,7 @@ fn does_not_find_any_pyenv_envs_even_with_pyenv_installed() { let environment = create_test_environment( HashMap::new(), Some(home.clone()), - vec![PathBuf::from(homebrew_bin)], + vec![homebrew_bin], None, ); @@ -119,7 +119,7 @@ fn find_pyenv_envs() { let environment = create_test_environment( HashMap::new(), Some(home.clone()), - vec![PathBuf::from(homebrew_bin)], + vec![homebrew_bin], None, ); From 5770a5aef21b5a056ed4105d99baedf20bee05c3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Sep 2025 01:26:11 +0000 Subject: [PATCH 7/8] Complete clippy fixes: resolve remaining identical if blocks and ptr_arg issues Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com> --- crates/pet-conda/src/conda_rc.rs | 10 ++-- crates/pet-conda/tests/ci_test.rs | 50 ++++++------------- .../tests/environment_locations_test.rs | 4 +- crates/pet-conda/tests/lib_test.rs | 8 +-- crates/pet-conda/tests/manager_test.rs | 2 +- crates/pet-conda/tests/package_test.rs | 10 ++-- crates/pet-conda/tests/utils_test.rs | 26 +++++----- crates/pet-poetry/src/config.rs | 23 ++++----- crates/pet-pyenv/tests/pyenv_test.rs | 20 ++------ .../pet-python-utils/tests/executable_test.rs | 16 +++--- .../pet-python-utils/tests/sys_prefix_test.rs | 25 +++++----- crates/pet/tests/ci_test.rs | 49 ++++++------------ 12 files changed, 94 insertions(+), 149 deletions(-) diff --git a/crates/pet-conda/src/conda_rc.rs b/crates/pet-conda/src/conda_rc.rs index 64fa88cd..83374830 100644 --- a/crates/pet-conda/src/conda_rc.rs +++ b/crates/pet-conda/src/conda_rc.rs @@ -353,7 +353,7 @@ envs_path: "#; assert_eq!( - parse_conda_rc_contents(&cfg).unwrap().env_dirs, + parse_conda_rc_contents(cfg).unwrap().env_dirs, [ PathBuf::from("/Users/username/dev/envs"), PathBuf::from("/opt/conda/envs"), @@ -373,7 +373,7 @@ envs_dirs: "#; assert_eq!( - parse_conda_rc_contents(&cfg).unwrap().env_dirs, + parse_conda_rc_contents(cfg).unwrap().env_dirs, ["/Users/username/dev/envs", "/opt/conda/envs",].map(PathBuf::from) ); @@ -388,7 +388,7 @@ envs_path: "#; assert_eq!( - parse_conda_rc_contents(&cfg).unwrap().env_dirs, + parse_conda_rc_contents(cfg).unwrap().env_dirs, [ PathBuf::from("/opt/somep lace/envs"), expand_path(PathBuf::from("~/dev/envs2")) @@ -402,7 +402,7 @@ channels: channel_priority: strict "#; - assert!(parse_conda_rc_contents(&cfg).unwrap().env_dirs.is_empty(),); - assert!(parse_conda_rc_contents(&cfg).unwrap().files.is_empty(),); + assert!(parse_conda_rc_contents(cfg).unwrap().env_dirs.is_empty(),); + assert!(parse_conda_rc_contents(cfg).unwrap().files.is_empty(),); } } diff --git a/crates/pet-conda/tests/ci_test.rs b/crates/pet-conda/tests/ci_test.rs index 0bfd0a6a..126cc4cb 100644 --- a/crates/pet-conda/tests/ci_test.rs +++ b/crates/pet-conda/tests/ci_test.rs @@ -84,7 +84,7 @@ fn detect_conda_root_from_path() { let python_env = PythonEnv::new(exe, Some(conda_dir.clone()), None); let env = conda.try_from(&python_env).unwrap(); - assert_eq!(env.manager.is_some(), true); + assert!(env.manager.is_some()); let manager = env.manager.unwrap(); assert_eq!(manager.executable, conda_dir.join("bin").join("conda")); @@ -132,13 +132,8 @@ fn detect_new_conda_env() { let env = environments .iter() .find(|x| x.name == Some(env_name.into())) - .expect( - format!( - "New Environment not created, detected envs {:?}", - environments - ) - .as_str(), - ); + .unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}", + environments)); let prefix = conda_dir.clone().join("envs").join(env_name); assert_eq!(env.prefix, prefix.clone().into()); @@ -182,7 +177,7 @@ fn detect_conda_env_from_path() { let python_env = PythonEnv::new(exe.clone(), Some(prefix.clone()), None); let env = conda.try_from(&python_env).unwrap(); - assert_eq!(env.manager.is_some(), true); + assert!(env.manager.is_some()); let manager = env.manager.unwrap(); assert_eq!(manager.executable, conda_dir.join("bin").join("conda")); @@ -231,20 +226,15 @@ fn detect_new_conda_env_without_python() { let env = environments .iter() .find(|x| x.name == Some(env_name.into())) - .expect( - format!( - "New Environment not created, detected envs {:?}", - environments - ) - .as_str(), - ); + .unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}", + environments)); 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, Some(PythonEnvironmentKind::Conda)); - assert_eq!(env.executable.is_none(), true); - assert_eq!(env.version.is_none(), true); + assert!(env.executable.is_none()); + assert!(env.version.is_none()); assert_eq!(env.manager, Some(manager.clone())); } @@ -281,19 +271,14 @@ fn detect_new_conda_env_created_with_p_flag_without_python() { let env = environments .iter() .find(|x| x.prefix == Some(prefix.clone())) - .expect( - format!( - "New Environment ({:?}) not created, detected envs {:?}", - prefix, environments - ) - .as_str(), - ); + .unwrap_or_else(|| panic!("New Environment ({:?}) not created, detected envs {:?}", + prefix, environments)); assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, None); assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda)); - assert_eq!(env.executable.is_none(), true); - assert_eq!(env.version.is_none(), true); + assert!(env.executable.is_none()); + assert!(env.version.is_none()); assert_eq!(env.manager, Some(manager.clone())); } @@ -334,13 +319,8 @@ fn detect_new_conda_env_created_with_p_flag_with_python() { let env = environments .iter() .find(|x| x.prefix == Some(prefix.clone())) - .expect( - format!( - "New Environment not created, detected envs {:?}", - environments - ) - .as_str(), - ); + .unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}", + environments)); assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, None); @@ -409,7 +389,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/environment_locations_test.rs b/crates/pet-conda/tests/environment_locations_test.rs index c438d61d..0d3a61c0 100644 --- a/crates/pet-conda/tests/environment_locations_test.rs +++ b/crates/pet-conda/tests/environment_locations_test.rs @@ -9,8 +9,8 @@ fn non_existent_envrionments_txt() { use common::{create_env_variables, resolve_test_path}; use pet_conda::environment_locations::get_conda_envs_from_environment_txt; - let root = resolve_test_path(&["unix", "root_empty"]).into(); - let home = resolve_test_path(&["unix", "bogus directory"]).into(); + let root = resolve_test_path(&["unix", "root_empty"]); + let home = resolve_test_path(&["unix", "bogus directory"]); let env = create_env_variables(home, root); let environments = get_conda_envs_from_environment_txt(&env); diff --git a/crates/pet-conda/tests/lib_test.rs b/crates/pet-conda/tests/lib_test.rs index 7efa4ff1..ff62f5aa 100644 --- a/crates/pet-conda/tests/lib_test.rs +++ b/crates/pet-conda/tests/lib_test.rs @@ -20,8 +20,8 @@ fn find_conda_env_without_manager() { let env = locator .try_from(&PythonEnv::new( - path.join("bin").join("python").into(), - Some(path.clone().into()), + path.join("bin").join("python"), + Some(path.clone()), None, )) .unwrap(); @@ -71,8 +71,8 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() { let env = locator .try_from(&PythonEnv::new( - path.join("bin").join("python").into(), - Some(path.clone().into()), + path.join("bin").join("python"), + Some(path.clone()), None, )) .unwrap(); diff --git a/crates/pet-conda/tests/manager_test.rs b/crates/pet-conda/tests/manager_test.rs index 1face145..f19481ef 100644 --- a/crates/pet-conda/tests/manager_test.rs +++ b/crates/pet-conda/tests/manager_test.rs @@ -48,5 +48,5 @@ fn does_not_find_conda_env_for_bogus_dirs() { let path = resolve_test_path(&["unix", "bogus_directory"]); - assert_eq!(CondaManager::from(&path).is_none(), true); + assert!(CondaManager::from(&path).is_none()); } diff --git a/crates/pet-conda/tests/package_test.rs b/crates/pet-conda/tests/package_test.rs index 828c07a9..0dd83cc5 100644 --- a/crates/pet-conda/tests/package_test.rs +++ b/crates/pet-conda/tests/package_test.rs @@ -10,7 +10,7 @@ use common::resolve_test_path; #[cfg(unix)] #[test] fn empty_result_for_bogus_paths() { - let path: PathBuf = resolve_test_path(&["unix", "bogus_path"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "bogus_path"]); let pkg = CondaPackageInfo::from(&path, &package::Package::Conda); assert!(pkg.is_none()); @@ -19,7 +19,7 @@ fn empty_result_for_bogus_paths() { #[cfg(unix)] #[test] fn get_conda_package_info() { - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]); let pkg = CondaPackageInfo::from(&path, &package::Package::Conda).unwrap(); assert_eq!(pkg.package, package::Package::Conda); @@ -38,7 +38,7 @@ fn get_conda_package_info() { #[cfg(unix)] #[test] fn get_python_package_info() { - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]); let pkg = CondaPackageInfo::from(&path, &package::Package::Python).unwrap(); assert_eq!(pkg.package, package::Package::Python); @@ -57,7 +57,7 @@ fn get_python_package_info() { #[cfg(unix)] #[test] fn get_conda_package_info_without_history() { - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]); let pkg = CondaPackageInfo::from(&path, &package::Package::Conda).unwrap(); assert_eq!(pkg.package, package::Package::Conda); @@ -76,7 +76,7 @@ fn get_conda_package_info_without_history() { #[cfg(unix)] #[test] fn get_python_package_info_without_history() { - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]); let pkg = CondaPackageInfo::from(&path, &package::Package::Python).unwrap(); assert_eq!(pkg.package, package::Package::Python); diff --git a/crates/pet-conda/tests/utils_test.rs b/crates/pet-conda/tests/utils_test.rs index 94192b97..ed5e604e 100644 --- a/crates/pet-conda/tests/utils_test.rs +++ b/crates/pet-conda/tests/utils_test.rs @@ -9,48 +9,48 @@ use std::path::PathBuf; #[cfg(unix)] #[test] fn is_conda_install() { - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]); assert!(utils::is_conda_install(&path)); - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]); assert!(utils::is_conda_install(&path)); } #[cfg(unix)] #[test] fn is_not_conda_install() { - let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]).into(); - assert_eq!(utils::is_conda_install(&path), false); + let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]); + assert!(!utils::is_conda_install(&path)); // Conda env is not an install location. let path: PathBuf = - resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]).into(); - assert_eq!(utils::is_conda_install(&path), false); + resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]); + assert!(!utils::is_conda_install(&path)); } #[cfg(unix)] #[test] fn is_conda_env() { - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]); assert!(utils::is_conda_env(&path)); - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]); assert!(utils::is_conda_env(&path)); let path: PathBuf = - resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]).into(); + resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]); assert!(utils::is_conda_env(&path)); } #[cfg(unix)] #[test] fn is_not_conda_env() { - let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]).into(); - assert_eq!(utils::is_conda_env(&path), false); + let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]); + assert!(!utils::is_conda_env(&path)); - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]); assert!(utils::is_conda_env(&path)); - let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]); assert!(utils::is_conda_env(&path)); } diff --git a/crates/pet-poetry/src/config.rs b/crates/pet-poetry/src/config.rs index feb541b7..1ccb43d1 100644 --- a/crates/pet-poetry/src/config.rs +++ b/crates/pet-poetry/src/config.rs @@ -241,12 +241,11 @@ create = false "#; - assert_eq!( - parse_contents(cfg) + assert!( + !parse_contents(cfg) .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - false + .unwrap_or_default() ); let cfg = r#" @@ -255,12 +254,11 @@ in-project = true create = false "#; - assert_eq!( + assert!( parse_contents(cfg) .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - true + .unwrap_or_default() ); let cfg = r#" @@ -268,19 +266,18 @@ create = false create = false "#; - assert_eq!( - parse_contents(cfg) + assert!( + !parse_contents(cfg) .unwrap() .virtualenvs_in_project - .unwrap_or_default(), - false + .unwrap_or_default() ); let cfg = r#" virtualenvs.in-project = true # comment "#; assert!( - parse_contents(&cfg) + parse_contents(cfg) .unwrap() .virtualenvs_in_project .unwrap_or_default() @@ -289,7 +286,7 @@ virtualenvs.in-project = true # comment let cfg = r#" "#; assert!( - !parse_contents(&cfg) + !parse_contents(cfg) .unwrap() .virtualenvs_in_project .unwrap_or_default() diff --git a/crates/pet-pyenv/tests/pyenv_test.rs b/crates/pet-pyenv/tests/pyenv_test.rs index f62d00b3..eaf87730 100644 --- a/crates/pet-pyenv/tests/pyenv_test.rs +++ b/crates/pet-pyenv/tests/pyenv_test.rs @@ -48,7 +48,7 @@ fn does_not_find_any_pyenv_envs_even_with_pyenv_installed() { use pet_pyenv::PyEnv; use pet_reporter::{cache::CacheReporter, collect}; use serde_json::json; - use std::{collections::HashMap, path::PathBuf, sync::Arc}; + use std::{collections::HashMap, sync::Arc}; let home = resolve_test_path(&["unix", "pyenv_without_envs", "user_home"]); let homebrew_bin = resolve_test_path(&[ @@ -101,7 +101,7 @@ fn find_pyenv_envs() { use pet_pyenv::PyEnv; use pet_reporter::{cache::CacheReporter, collect}; use serde_json::json; - use std::{collections::HashMap, path::PathBuf, sync::Arc}; + use std::{collections::HashMap, sync::Arc}; let home = resolve_test_path(&["unix", "pyenv", "user_home"]); let homebrew_bin = resolve_test_path(&["unix", "pyenv", "home", "opt", "homebrew", "bin"]); @@ -172,7 +172,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, @@ -194,7 +193,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, @@ -216,7 +214,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, @@ -238,7 +235,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, @@ -260,7 +256,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, @@ -282,7 +277,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, @@ -304,7 +298,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 { @@ -318,7 +311,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, @@ -331,7 +323,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, @@ -344,7 +335,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![ @@ -414,7 +404,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, @@ -436,7 +425,6 @@ fn resolve_pyenv_environment() { home.to_str().unwrap(), ".pyenv/versions/my-virtual-env/bin/python", ])]), - ..Default::default() }; // Resolve regular Python installs in Pyenv @@ -479,7 +467,7 @@ fn resolve_pyenv_environment() { None, )); - assert_eq!(result.is_none(), true); + assert!(result.is_none()); // Should not resolve conda envs using Conda Locator let result = conda.try_from(&PythonEnv::new( @@ -494,6 +482,6 @@ fn resolve_pyenv_environment() { None, )); - assert_eq!(result.is_some(), true); + assert!(result.is_some()); assert_eq!(result.unwrap().kind, Some(PythonEnvironmentKind::Conda)); } diff --git a/crates/pet-python-utils/tests/executable_test.rs b/crates/pet-python-utils/tests/executable_test.rs index bfbcd76c..a578142c 100644 --- a/crates/pet-python-utils/tests/executable_test.rs +++ b/crates/pet-python-utils/tests/executable_test.rs @@ -11,8 +11,8 @@ use common::resolve_test_path; #[test] fn find_executables() { // .venv - let path: PathBuf = resolve_test_path(&["unix", "executables", ".venv"]).into(); - let mut executables = executable::find_executables(&path.clone()); + let path: PathBuf = resolve_test_path(&["unix", "executables", ".venv"]); + let mut executables = executable::find_executables(path.clone()); executables.sort(); assert_eq!( @@ -24,8 +24,8 @@ fn find_executables() { ); // Python3.9.9 - let path: PathBuf = resolve_test_path(&["unix", "executables", "python3.9.9"]).into(); - let mut executables = executable::find_executables(&path.clone()); + let path: PathBuf = resolve_test_path(&["unix", "executables", "python3.9.9"]); + let mut executables = executable::find_executables(path.clone()); executables.sort(); assert_eq!( @@ -37,14 +37,14 @@ fn find_executables() { ); // Conda without Python. - let path: PathBuf = resolve_test_path(&["unix", "executables", "conda_without_python"]).into(); - let executables = executable::find_executables(&path.clone()); + let path: PathBuf = resolve_test_path(&["unix", "executables", "conda_without_python"]); + let executables = executable::find_executables(path.clone()); assert_eq!(executables.len(), 0); // Bogus dir - let path: PathBuf = resolve_test_path(&["unix_bogus_dir"]).into(); - let executables = executable::find_executables(&path.clone()); + let path: PathBuf = resolve_test_path(&["unix_bogus_dir"]); + let executables = executable::find_executables(path.clone()); assert_eq!(executables.len(), 0); } diff --git a/crates/pet-python-utils/tests/sys_prefix_test.rs b/crates/pet-python-utils/tests/sys_prefix_test.rs index 379c2cf4..aecbd7f8 100644 --- a/crates/pet-python-utils/tests/sys_prefix_test.rs +++ b/crates/pet-python-utils/tests/sys_prefix_test.rs @@ -10,11 +10,11 @@ use common::resolve_test_path; #[cfg(unix)] #[test] fn version_from_sys_prefix() { - let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", ".venv"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", ".venv"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.12.1"); - let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", ".venv", "bin"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", ".venv", "bin"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.12.1"); } @@ -22,11 +22,11 @@ fn version_from_sys_prefix() { #[cfg(unix)] #[test] fn version_from_sys_prefix_using_version_info_format() { - let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", "hatch_env"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", "hatch_env"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.9.6.final.0"); - let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", "hatch_env", "bin"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", "hatch_env", "bin"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.9.6.final.0"); } @@ -35,12 +35,12 @@ fn version_from_sys_prefix_using_version_info_format() { #[test] fn no_version_without_pyvenv_cfg_and_without_headers() { let path: PathBuf = - resolve_test_path(&["unix", "pyvenv_cfg", "python3.9.9_without_headers"]).into(); + resolve_test_path(&["unix", "pyvenv_cfg", "python3.9.9_without_headers"]); let version = version::from_prefix(&path); assert!(version.is_none()); let path: PathBuf = - resolve_test_path(&["unix", "pyvenv_cfg", "python3.9.9_without_headers", "bin"]).into(); + resolve_test_path(&["unix", "pyvenv_cfg", "python3.9.9_without_headers", "bin"]); let version = version::from_prefix(&path); assert!(version.is_none()); @@ -50,8 +50,7 @@ fn no_version_without_pyvenv_cfg_and_without_headers() { "python3.9.9_without_headers", "bin", "python", - ]) - .into(); + ]); let version = version::from_prefix(&path); assert!(version.is_none()); } @@ -59,7 +58,7 @@ fn no_version_without_pyvenv_cfg_and_without_headers() { #[cfg(unix)] #[test] fn no_version_for_invalid_paths() { - let path: PathBuf = resolve_test_path(&["unix_1234"]).into(); + let path: PathBuf = resolve_test_path(&["unix_1234"]); let version = version::from_prefix(&path); assert!(version.is_none()); } @@ -67,19 +66,19 @@ fn no_version_for_invalid_paths() { #[cfg(unix)] #[test] fn version_from_header_files() { - let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.9.9"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.9.9"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.9.9"); - let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.9.9", "bin"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.9.9", "bin"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.9.9"); - let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.10-dev", "bin"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.10-dev", "bin"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.10.14+"); - let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.13", "bin"]).into(); + let path: PathBuf = resolve_test_path(&["unix", "headers", "python3.13", "bin"]); let version = version::from_prefix(&path).unwrap(); assert_eq!(version, "3.13.0a5"); } diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index c2d36f89..ea6a4e84 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -270,7 +270,7 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { .symlinks .clone() .unwrap_or_default() - .contains(&PathBuf::from(expected_executable)), + .contains(&expected_executable), "Executable mismatch for {:?}", environment.clone() ); @@ -285,19 +285,17 @@ 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 + && 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") + && interpreter_info.clone().sys_prefix == "/home/codespace/.python/current")) { // known issue https://github.com/microsoft/python-environment-tools/issues/64 } else { @@ -490,20 +488,17 @@ 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 + && 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"))) + && 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; @@ -518,13 +513,7 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment, .iter() .filter(|p| { // This is in the path, but not easy to figure out, unless we add support for codespaces or CI. - if p.starts_with("/Users/runner/hostedtoolcache/Python") - && p.to_string_lossy().contains("arm64") - { - false - } else { - true - } + !(p.starts_with("/Users/runner/hostedtoolcache/Python") && p.to_string_lossy().contains("arm64")) }) .map(|p| p.to_path_buf()) .collect::>(), @@ -537,38 +526,30 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment, .iter() .filter(|p| { // This is in the path, but not easy to figure out, unless we add support for codespaces or CI. - if p.starts_with("/Users/runner/hostedtoolcache/Python") - && p.to_string_lossy().contains("arm64") - { - false - } else { - true - } + !(p.starts_with("/Users/runner/hostedtoolcache/Python") && p.to_string_lossy().contains("arm64")) }) .map(|p| p.to_path_buf()) .collect::>(), ); // if we know the arch, then verify it - if expected.arch.as_ref().is_some() && actual.arch.as_ref().is_some() { - if actual.arch.as_ref() != expected.arch.as_ref() { + if expected.arch.as_ref().is_some() && actual.arch.as_ref().is_some() + && actual.arch.as_ref() != expected.arch.as_ref() { error!( "Arch mismatch when using {} for {:?} and {:?}", method, expected, actual ); } - } actual.arch = expected.clone().arch; // if we know the prefix, then verify it - if expected.prefix.as_ref().is_some() && actual.prefix.as_ref().is_some() { - if actual.prefix.as_ref() != expected.prefix.as_ref() { + if expected.prefix.as_ref().is_some() && actual.prefix.as_ref().is_some() + && actual.prefix.as_ref() != expected.prefix.as_ref() { error!( "Prefirx mismatch when using {} for {:?} and {:?}", method, expected, actual ); } - } actual.prefix = expected.clone().prefix; assert_eq!( From 0982c5678efe72d824cb11d48134ebbf9a1176a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Sep 2025 01:54:09 +0000 Subject: [PATCH 8/8] Apply cargo fmt formatting across the workspace Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com> --- crates/pet-conda/tests/ci_test.rs | 32 ++++++-- crates/pet-conda/tests/utils_test.rs | 6 +- crates/pet-poetry/src/config.rs | 55 ++++++-------- crates/pet-poetry/tests/config_test.rs | 24 +++--- crates/pet-pyenv/tests/pyenv_test.rs | 16 +--- .../pet-python-utils/tests/sys_prefix_test.rs | 3 +- crates/pet/tests/ci_test.rs | 74 +++++++++++-------- 7 files changed, 104 insertions(+), 106 deletions(-) diff --git a/crates/pet-conda/tests/ci_test.rs b/crates/pet-conda/tests/ci_test.rs index 126cc4cb..d6401199 100644 --- a/crates/pet-conda/tests/ci_test.rs +++ b/crates/pet-conda/tests/ci_test.rs @@ -132,8 +132,12 @@ fn detect_new_conda_env() { let env = environments .iter() .find(|x| x.name == Some(env_name.into())) - .unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}", - environments)); + .unwrap_or_else(|| { + panic!( + "New Environment not created, detected envs {:?}", + environments + ) + }); let prefix = conda_dir.clone().join("envs").join(env_name); assert_eq!(env.prefix, prefix.clone().into()); @@ -226,8 +230,12 @@ fn detect_new_conda_env_without_python() { let env = environments .iter() .find(|x| x.name == Some(env_name.into())) - .unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}", - environments)); + .unwrap_or_else(|| { + panic!( + "New Environment not created, detected envs {:?}", + environments + ) + }); let prefix = conda_dir.clone().join("envs").join(env_name); assert_eq!(env.prefix, prefix.clone().into()); @@ -271,8 +279,12 @@ fn detect_new_conda_env_created_with_p_flag_without_python() { let env = environments .iter() .find(|x| x.prefix == Some(prefix.clone())) - .unwrap_or_else(|| panic!("New Environment ({:?}) not created, detected envs {:?}", - prefix, environments)); + .unwrap_or_else(|| { + panic!( + "New Environment ({:?}) not created, detected envs {:?}", + prefix, environments + ) + }); assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, None); @@ -319,8 +331,12 @@ fn detect_new_conda_env_created_with_p_flag_with_python() { let env = environments .iter() .find(|x| x.prefix == Some(prefix.clone())) - .unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}", - environments)); + .unwrap_or_else(|| { + panic!( + "New Environment not created, detected envs {:?}", + environments + ) + }); assert_eq!(env.prefix, prefix.clone().into()); assert_eq!(env.name, None); diff --git a/crates/pet-conda/tests/utils_test.rs b/crates/pet-conda/tests/utils_test.rs index ed5e604e..db56247c 100644 --- a/crates/pet-conda/tests/utils_test.rs +++ b/crates/pet-conda/tests/utils_test.rs @@ -23,8 +23,7 @@ fn is_not_conda_install() { assert!(!utils::is_conda_install(&path)); // Conda env is not an install location. - let path: PathBuf = - resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]); assert!(!utils::is_conda_install(&path)); } @@ -37,8 +36,7 @@ fn is_conda_env() { let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]); assert!(utils::is_conda_env(&path)); - let path: PathBuf = - resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]); + let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]); assert!(utils::is_conda_env(&path)); } diff --git a/crates/pet-poetry/src/config.rs b/crates/pet-poetry/src/config.rs index 1ccb43d1..07e518d2 100644 --- a/crates/pet-poetry/src/config.rs +++ b/crates/pet-poetry/src/config.rs @@ -241,12 +241,10 @@ create = false "#; - assert!( - !parse_contents(cfg) - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(!parse_contents(cfg) + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); let cfg = r#" [virtualenvs] @@ -254,43 +252,35 @@ in-project = true create = false "#; - assert!( - parse_contents(cfg) - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(parse_contents(cfg) + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); let cfg = r#" [virtualenvs] create = false "#; - assert!( - !parse_contents(cfg) - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(!parse_contents(cfg) + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); let cfg = r#" virtualenvs.in-project = true # comment "#; - assert!( - parse_contents(cfg) - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(parse_contents(cfg) + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); let cfg = r#" "#; - assert!( - !parse_contents(cfg) - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(!parse_contents(cfg) + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); } #[test] @@ -326,10 +316,7 @@ virtualenvs.path = "/path/to/virtualenvs" some-other-value = 1234 "#; - assert_eq!( - parse_contents(cfg).unwrap().virtualenvs_path, - None - ); + assert_eq!(parse_contents(cfg).unwrap().virtualenvs_path, None); } #[test] diff --git a/crates/pet-poetry/tests/config_test.rs b/crates/pet-poetry/tests/config_test.rs index 824f0021..c1d203cd 100644 --- a/crates/pet-poetry/tests/config_test.rs +++ b/crates/pet-poetry/tests/config_test.rs @@ -69,13 +69,11 @@ fn global_config_with_specific_values() { "config.toml" ])) ); - assert!( - config - .clone() - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(config + .clone() + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); assert_eq!( config.clone().unwrap().virtualenvs_path, PathBuf::from("some/path/virtualenvs".to_string()) @@ -115,13 +113,11 @@ fn local_config_with_specific_values() { "poetry.toml" ])) ); - assert!( - !config - .clone() - .unwrap() - .virtualenvs_in_project - .unwrap_or_default() - ); + assert!(!config + .clone() + .unwrap() + .virtualenvs_in_project + .unwrap_or_default()); assert_eq!( config.clone().unwrap().virtualenvs_path, PathBuf::from("/directory/virtualenvs".to_string()) diff --git a/crates/pet-pyenv/tests/pyenv_test.rs b/crates/pet-pyenv/tests/pyenv_test.rs index eaf87730..33b461c7 100644 --- a/crates/pet-pyenv/tests/pyenv_test.rs +++ b/crates/pet-pyenv/tests/pyenv_test.rs @@ -60,12 +60,8 @@ fn does_not_find_any_pyenv_envs_even_with_pyenv_installed() { "bin", ]); let pyenv_exe = resolve_test_path(&[homebrew_bin.to_str().unwrap(), "pyenv"]); - let environment = create_test_environment( - HashMap::new(), - Some(home.clone()), - vec![homebrew_bin], - None, - ); + let environment = + create_test_environment(HashMap::new(), Some(home.clone()), vec![homebrew_bin], None); let conda = Arc::new(Conda::from(&environment)); let locator = PyEnv::from(&environment, conda); @@ -116,12 +112,8 @@ fn find_pyenv_envs() { ]); let conda_exe = conda_dir.join("bin").join("conda"); - let environment = create_test_environment( - HashMap::new(), - Some(home.clone()), - vec![homebrew_bin], - None, - ); + let environment = + create_test_environment(HashMap::new(), Some(home.clone()), vec![homebrew_bin], None); let conda = Arc::new(Conda::from(&environment)); let locator = PyEnv::from(&environment, conda); diff --git a/crates/pet-python-utils/tests/sys_prefix_test.rs b/crates/pet-python-utils/tests/sys_prefix_test.rs index aecbd7f8..ba5c5f71 100644 --- a/crates/pet-python-utils/tests/sys_prefix_test.rs +++ b/crates/pet-python-utils/tests/sys_prefix_test.rs @@ -34,8 +34,7 @@ fn version_from_sys_prefix_using_version_info_format() { #[cfg(unix)] #[test] fn no_version_without_pyvenv_cfg_and_without_headers() { - let path: PathBuf = - resolve_test_path(&["unix", "pyvenv_cfg", "python3.9.9_without_headers"]); + let path: PathBuf = resolve_test_path(&["unix", "pyvenv_cfg", "python3.9.9_without_headers"]); let version = version::from_prefix(&path); assert!(version.is_none()); diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index ea6a4e84..4ebbb3f5 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -290,12 +290,11 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) { && 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")) - || (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().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 { @@ -367,7 +366,9 @@ fn verify_we_can_get_same_env_info_using_from_with_exe( let env = PythonEnv::new(executable.clone(), None, None); let resolved = identify_python_environment_using_locators(&env, &locators, &global_env_search_paths) - .unwrap_or_else(|| panic!("Failed to resolve environment using `resolve` for {environment:?}")); + .unwrap_or_else(|| { + panic!("Failed to resolve environment using `resolve` for {environment:?}") + }); trace!( "For exe {:?} we got Environment = {:?}, To compare against {:?}", executable, @@ -488,17 +489,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")))) - || (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().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; @@ -513,7 +516,8 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment, .iter() .filter(|p| { // This is in the path, but not easy to figure out, unless we add support for codespaces or CI. - !(p.starts_with("/Users/runner/hostedtoolcache/Python") && p.to_string_lossy().contains("arm64")) + !(p.starts_with("/Users/runner/hostedtoolcache/Python") + && p.to_string_lossy().contains("arm64")) }) .map(|p| p.to_path_buf()) .collect::>(), @@ -526,30 +530,35 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment, .iter() .filter(|p| { // This is in the path, but not easy to figure out, unless we add support for codespaces or CI. - !(p.starts_with("/Users/runner/hostedtoolcache/Python") && p.to_string_lossy().contains("arm64")) + !(p.starts_with("/Users/runner/hostedtoolcache/Python") + && p.to_string_lossy().contains("arm64")) }) .map(|p| p.to_path_buf()) .collect::>(), ); // if we know the arch, then verify it - if expected.arch.as_ref().is_some() && actual.arch.as_ref().is_some() - && actual.arch.as_ref() != expected.arch.as_ref() { - error!( - "Arch mismatch when using {} for {:?} and {:?}", - method, expected, actual - ); - } + if expected.arch.as_ref().is_some() + && actual.arch.as_ref().is_some() + && actual.arch.as_ref() != expected.arch.as_ref() + { + error!( + "Arch mismatch when using {} for {:?} and {:?}", + method, expected, actual + ); + } actual.arch = expected.clone().arch; // if we know the prefix, then verify it - if expected.prefix.as_ref().is_some() && actual.prefix.as_ref().is_some() - && actual.prefix.as_ref() != expected.prefix.as_ref() { - error!( - "Prefirx mismatch when using {} for {:?} and {:?}", - method, expected, actual - ); - } + if expected.prefix.as_ref().is_some() + && actual.prefix.as_ref().is_some() + && actual.prefix.as_ref() != expected.prefix.as_ref() + { + error!( + "Prefirx mismatch when using {} for {:?} and {:?}", + method, expected, actual + ); + } actual.prefix = expected.clone().prefix; assert_eq!( @@ -596,8 +605,9 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe( locator.configure(&config); } - let env = resolve_environment(executable, &locators, &os_environment) - .unwrap_or_else(|| panic!("Failed to resolve environment using `resolve` for {environment:?}")); + let env = resolve_environment(executable, &locators, &os_environment).unwrap_or_else(|| { + panic!("Failed to resolve environment using `resolve` for {environment:?}") + }); trace!( "For exe {:?} we got Environment = {:?}, To compare against {:?}", executable,