Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/pet-conda/src/environment_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ pub fn get_known_conda_install_locations(
env_vars: &EnvVariables,
conda_executable: &Option<PathBuf>,
) -> Vec<PathBuf> {
use pet_fs::path::norm_case;

let user_profile = env_vars.userprofile.clone().unwrap_or_default();
let program_data = env_vars.programdata.clone().unwrap_or_default();
let all_user_profile = env_vars.allusersprofile.clone().unwrap_or_default();
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-conda/tests/ci_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ fn create_conda_env(mode: &CondaCreateEnvNameOrPath, python_version: Option<Stri
.expect("Failed to execute command");
}

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 re = regex::Regex::new(r"\d+\.\d+\.\d+").unwrap();
let captures = re.captures(value).unwrap();
Expand Down
30 changes: 16 additions & 14 deletions crates/pet-conda/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,29 @@ pub struct TestEnvironment {
root: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
}

impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}

#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}
TestEnvironment {
vars,
home,
Expand Down
5 changes: 4 additions & 1 deletion crates/pet-core/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {

#[cfg(test)]
mod tests {
use super::*;
#[cfg(windows)]
use super::{get_shortest_executable, PythonEnvironmentKind};
#[cfg(windows)]
use std::path::PathBuf;

#[test]
#[cfg(windows)]
Expand Down
3 changes: 3 additions & 0 deletions crates/pet-poetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ regex = "1.10.4"
sha2 = "0.10.6"
base64 = "0.22.0"
toml = "0.8.14"

[features]
ci = []
30 changes: 16 additions & 14 deletions crates/pet-poetry/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ pub struct TestEnvironment {
home: Option<PathBuf>,
root: Option<PathBuf>,
}

impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
vec![]
}
}

#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
vec![]
}
}
TestEnvironment { vars, home, root }
}
1 change: 0 additions & 1 deletion crates/pet-poetry/tests/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn global_config_with_specific_values() {
#[cfg(unix)]
#[cfg_attr(any(feature = "ci",), test)]
#[allow(dead_code)]

fn local_config_with_specific_values() {
use std::path::PathBuf;

Expand Down
30 changes: 16 additions & 14 deletions crates/pet-pyenv/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,29 @@ pub struct TestEnvironment {
root: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
}

impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}

#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}
TestEnvironment {
vars,
home,
Expand Down
12 changes: 0 additions & 12 deletions crates/pet-pyenv/tests/pyenv_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.9.9/bin/python",
])]),
..Default::default()
};
let expected_virtual_env = PythonEnvironment {
display_name: None,
Expand All @@ -186,7 +185,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/my-virtual-env/bin/python",
])]),
..Default::default()
};
let expected_3_12_1 = PythonEnvironment {
display_name: None,
Expand All @@ -208,7 +206,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.12.1/bin/python",
])]),
..Default::default()
};
let expected_3_13_dev = PythonEnvironment {
display_name: None,
Expand All @@ -230,7 +227,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.13-dev/bin/python",
])]),
..Default::default()
};
let expected_3_12_1a3 = PythonEnvironment {
display_name: None,
Expand All @@ -252,7 +248,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.12.1a3/bin/python",
])]),
..Default::default()
};
let expected_no_gil = PythonEnvironment {
display_name: None,
Expand All @@ -274,7 +269,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/nogil-3.9.10-1/bin/python",
])]),
..Default::default()
};
let expected_pypy = PythonEnvironment {
display_name: None,
Expand All @@ -296,7 +290,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/pypy3.9-7.3.15/bin/python",
])]),
..Default::default()
};

let expected_conda_root = PythonEnvironment {
Expand All @@ -310,7 +303,6 @@ fn find_pyenv_envs() {
manager: Some(expected_conda_manager.clone()),
arch: Some(Architecture::X64),
symlinks: Some(vec![conda_dir.join("bin").join("python")]),
..Default::default()
};
let expected_conda_one = PythonEnvironment {
display_name: None,
Expand All @@ -323,7 +315,6 @@ fn find_pyenv_envs() {
manager: Some(expected_conda_manager.clone()),
arch: None,
symlinks: Some(vec![conda_dir.join("envs").join("one").join("python")]),
..Default::default()
};
let expected_conda_two = PythonEnvironment {
display_name: None,
Expand All @@ -336,7 +327,6 @@ fn find_pyenv_envs() {
manager: Some(expected_conda_manager.clone()),
symlinks: Some(vec![conda_dir.join("envs").join("two").join("python")]),
arch: None,
..Default::default()
};

let mut expected_envs = vec![
Expand Down Expand Up @@ -406,7 +396,6 @@ fn resolve_pyenv_environment() {
manager: Some(expected_manager.clone()),
arch: None,
symlinks: Some(vec![executable]),
..Default::default()
};
let expected_virtual_env = PythonEnvironment {
display_name: None,
Expand All @@ -428,7 +417,6 @@ fn resolve_pyenv_environment() {
home.to_str().unwrap(),
".pyenv/versions/my-virtual-env/bin/python",
])]),
..Default::default()
};

// Resolve regular Python installs in Pyenv
Expand Down
13 changes: 7 additions & 6 deletions crates/pet-windows-registry/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ use std::{path::PathBuf, sync::Arc};
#[cfg(windows)]
use winreg::RegKey;

#[cfg(windows)]
use log::{trace, warn};
#[cfg(windows)]
use pet_conda::utils::is_conda_env;
#[cfg(windows)]
use pet_fs::path::norm_case;

#[cfg(windows)]
pub fn get_registry_pythons(
conda_locator: &Arc<dyn CondaLocator>,
reporter: &Option<&dyn Reporter>,
) -> LocatorResult {
use log::{trace, warn};

let mut environments = vec![];
let mut managers: Vec<EnvManager> = vec![];

Expand Down Expand Up @@ -88,10 +93,6 @@ fn get_registry_pythons_from_key_for_company(
conda_locator: &Arc<dyn CondaLocator>,
reporter: &Option<&dyn Reporter>,
) -> LocatorResult {
use log::{trace, warn};
use pet_conda::utils::is_conda_env;
use pet_fs::path::norm_case;

let mut environments = vec![];
// let company_display_name: Option<String> = company_key.get_value("DisplayName").ok();
for installed_python in company_key.enum_keys().filter_map(Result::ok) {
Expand Down
15 changes: 7 additions & 8 deletions crates/pet-windows-store/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ use std::path::PathBuf;
#[cfg(windows)]
use winreg::RegKey;

#[cfg(windows)]
use crate::environment_locations::get_search_locations;
#[cfg(windows)]
use log::{trace, warn};
#[cfg(windows)]
use std::collections::HashMap;

#[cfg(windows)]
lazy_static! {
static ref PYTHON_SOFTWARE_FOUNDATION_FOLDER_VERSION: Regex = Regex::new(
Expand Down Expand Up @@ -92,10 +99,6 @@ impl PotentialPython {

#[cfg(windows)]
pub fn list_store_pythons(environment: &EnvVariables) -> Option<Vec<PythonEnvironment>> {
use crate::environment_locations::get_search_locations;
use log::{trace, warn};
use std::collections::HashMap;

let mut python_envs: Vec<PythonEnvironment> = vec![];
let apps_path = get_search_locations(environment)?;
let hkcu = winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
Expand Down Expand Up @@ -238,8 +241,6 @@ struct StorePythonInfo {

#[cfg(windows)]
fn get_package_display_name_and_location(name: &String, hkcu: &RegKey) -> Option<StorePythonInfo> {
use log::trace;

if let Some(name) = get_package_full_name_from_registry(name, hkcu) {
let key = format!("Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages\\{}", name);
trace!("Opening registry key {:?}", key);
Expand All @@ -258,8 +259,6 @@ fn get_package_display_name_and_location(name: &String, hkcu: &RegKey) -> Option

#[cfg(windows)]
fn get_package_full_name_from_registry(name: &String, hkcu: &RegKey) -> Option<String> {
use log::trace;

let key = format!("Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\SystemAppData\\{}\\Schemas", name);
trace!("Opening registry key {:?}", key);
let package_key = hkcu.open_subkey(key).ok()?;
Expand Down
12 changes: 7 additions & 5 deletions crates/pet-windows-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ use pet_core::{os_environment::Environment, Locator};
use std::path::Path;
use std::sync::{Arc, Mutex};

#[cfg(windows)]
use pet_core::python_environment::PythonEnvironmentBuilder;
#[cfg(windows)]
use pet_virtualenv::is_virtualenv;
#[cfg(windows)]
use std::path::PathBuf;

pub fn is_windows_app_folder_in_program_files(path: &Path) -> bool {
path.to_str().unwrap_or_default().to_string().to_lowercase()[1..]
.starts_with(":\\program files\\windowsapps")
Expand Down Expand Up @@ -61,11 +68,6 @@ impl Locator for WindowsStore {

#[cfg(windows)]
fn try_from(&self, env: &PythonEnv) -> Option<PythonEnvironment> {
use std::path::PathBuf;

use pet_core::python_environment::PythonEnvironmentBuilder;
use pet_virtualenv::is_virtualenv;

// Assume we create a virtual env from a python install,
// Then the exe in the virtual env bin will be a symlink to the homebrew python install.
// Hence the first part of the condition will be true, but the second part will be false.
Expand Down
12 changes: 8 additions & 4 deletions crates/pet/tests/ci_poetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading