Skip to content

Commit

Permalink
Better name
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jun 5, 2024
1 parent 59cda0b commit a5014a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 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::get_absolute_path;
use pet_utils::path::fix_file_path_casing;
use std::{
fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -146,7 +146,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(get_absolute_path(&PathBuf::from(line.to_string())));
envs.push(fix_file_path_casing(&PathBuf::from(line.to_string())));
}
}
}
Expand All @@ -156,7 +156,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::get_absolute_path;
use pet_utils::path::fix_file_path_casing;

let user_profile = env_vars.userprofile.clone().unwrap_or_default();
let program_data = env_vars.programdata.clone().unwrap_or_default();
Expand Down Expand Up @@ -209,7 +209,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| get_absolute_path(&p)).collect();
known_paths = known_paths.iter().map(|p| fix_file_path_casing(&p)).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::get_absolute_path};
use pet_utils::{executable::find_executable, path::fix_file_path_casing};
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(get_absolute_path(conda_dir).to_path_buf());
return Some(fix_file_path_casing(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(get_absolute_path(&cmd_line).to_path_buf());
return Some(fix_file_path_casing(&cmd_line).to_path_buf());
}
}
None
Expand Down
6 changes: 5 additions & 1 deletion crates/pet-utils/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use std::{
path::{Path, PathBuf},
};

pub fn get_absolute_path(path: &Path) -> PathBuf {
// This function is used to fix the casing of the file path.
// by returning the actual path with the correct casing as found on the OS.
// This is a noop for Unix systems.
// I.e. this function is only useful on Windows.
pub fn fix_file_path_casing(path: &Path) -> PathBuf {
// Return the path as is.
if cfg!(unix) {
return path.to_path_buf();
Expand Down

0 comments on commit a5014a9

Please sign in to comment.