Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize all paths #17

Merged
merged 3 commits into from
Jun 5, 2024
Merged
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
6 changes: 2 additions & 4 deletions crates/pet-conda/src/conda_rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::env_variables::EnvVariables;
use log::trace;
use pet_utils::path::fix_file_path_casing;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to make the new intent clear

use pet_utils::path::normalize;
use std::{fs, path::PathBuf};

#[derive(Debug)]
Expand Down Expand Up @@ -155,9 +155,7 @@ fn parse_conda_rc(conda_rc: &PathBuf) -> Option<Condarc> {
if line.trim().starts_with('-') {
if let Some(env_dir) = line.split_once('-').map(|x| x.1) {
// Directories in conda-rc are where `envs` are stored.
env_dirs.push(fix_file_path_casing(
&PathBuf::from(env_dir.trim()).join("envs"),
));
env_dirs.push(normalize(&PathBuf::from(env_dir.trim()).join("envs")));
}
continue;
} else {
Expand Down
13 changes: 5 additions & 8 deletions crates/pet-conda/src/environment_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
utils::{is_conda_env, is_conda_install},
};
use log::trace;
use pet_utils::path::fix_file_path_casing;
use pet_utils::path::normalize;
use std::{
fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn get_conda_environment_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
envs
});

env_paths = env_paths.iter().map(|p| fix_file_path_casing(p)).collect();
env_paths = env_paths.iter().map(normalize).collect();
env_paths.sort();
env_paths.dedup();
// For each env, check if we have a conda install directory in them and
Expand Down Expand Up @@ -147,7 +147,7 @@ pub fn get_conda_envs_from_environment_txt(env_vars: &EnvVariables) -> Vec<PathB
if let Ok(reader) = fs::read_to_string(environment_txt.clone()) {
trace!("Found environments.txt file {:?}", environment_txt);
for line in reader.lines() {
envs.push(fix_file_path_casing(&PathBuf::from(line.to_string())));
envs.push(normalize(&PathBuf::from(line.to_string())));
}
}
}
Expand All @@ -157,7 +157,7 @@ pub fn get_conda_envs_from_environment_txt(env_vars: &EnvVariables) -> Vec<PathB

#[cfg(windows)]
pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec<PathBuf> {
use pet_utils::path::fix_file_path_casing;
use pet_utils::path::normalize;

let user_profile = env_vars.userprofile.clone().unwrap_or_default();
let program_data = env_vars.programdata.clone().unwrap_or_default();
Expand Down Expand Up @@ -210,10 +210,7 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec<PathBuf
// We use lower cases above, but it could be in any case on disc.
// We do not want to have duplicates in different cases.
// & we'd like to preserve the case of the original path as on disc.
known_paths = known_paths
.iter()
.map(|p| fix_file_path_casing(p))
.collect();
known_paths = known_paths.iter().map(normalize).collect();
known_paths.sort();
known_paths.dedup();

Expand Down
6 changes: 3 additions & 3 deletions crates/pet-conda/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pet_core::{
manager::EnvManager,
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory},
};
use pet_utils::{executable::find_executable, path::fix_file_path_casing};
use pet_utils::{executable::find_executable, path::normalize};
use std::{
fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -180,7 +180,7 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option<PathBuf> {
// The casing in history might not be same as that on disc
// We do not want to have duplicates in different cases.
// & we'd like to preserve the case of the original path as on disc.
return Some(fix_file_path_casing(conda_dir).to_path_buf());
return Some(normalize(conda_dir).to_path_buf());
}
}
// Sometimes we can have paths like
Expand Down Expand Up @@ -212,7 +212,7 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option<PathBuf> {
// The casing in history might not be same as that on disc
// We do not want to have duplicates in different cases.
// & we'd like to preserve the case of the original path as on disc.
return Some(fix_file_path_casing(&cmd_line).to_path_buf());
return Some(normalize(&cmd_line).to_path_buf());
}
}
None
Expand Down
17 changes: 0 additions & 17 deletions crates/pet-conda/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,3 @@ fn get_conda_manager(path: &Path) -> Option<CondaManager> {
None
}
}

// pub fn get_conda_version(conda_binary: &PathBuf) -> Option<String> {
// let mut parent = conda_binary.parent()?;
// if parent.ends_with("bin") {
// parent = parent.parent()?;
// }
// if parent.ends_with("Library") {
// parent = parent.parent()?;
// }
// match get_conda_package_info(&parent, "conda") {
// Some(result) => Some(result.version),
// None => match get_conda_package_info(&parent.parent()?, "conda") {
// Some(result) => Some(result.version),
// None => None,
// },
// }
// }
246 changes: 0 additions & 246 deletions crates/pet-conda/src/mod.rs

This file was deleted.

Loading
Loading