Skip to content

Commit 4ef5a03

Browse files
authored
normalize all paths (#17)
1 parent 9679dcb commit 4ef5a03

File tree

19 files changed

+102
-324
lines changed

19 files changed

+102
-324
lines changed

crates/pet-conda/src/conda_rc.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::env_variables::EnvVariables;
55
use log::trace;
6-
use pet_utils::path::fix_file_path_casing;
6+
use pet_utils::path::normalize;
77
use std::{fs, path::PathBuf};
88

99
#[derive(Debug)]
@@ -155,9 +155,7 @@ fn parse_conda_rc(conda_rc: &PathBuf) -> Option<Condarc> {
155155
if line.trim().starts_with('-') {
156156
if let Some(env_dir) = line.split_once('-').map(|x| x.1) {
157157
// Directories in conda-rc are where `envs` are stored.
158-
env_dirs.push(fix_file_path_casing(
159-
&PathBuf::from(env_dir.trim()).join("envs"),
160-
));
158+
env_dirs.push(normalize(&PathBuf::from(env_dir.trim()).join("envs")));
161159
}
162160
continue;
163161
} else {

crates/pet-conda/src/environment_locations.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
utils::{is_conda_env, is_conda_install},
88
};
99
use log::trace;
10-
use pet_utils::path::fix_file_path_casing;
10+
use pet_utils::path::normalize;
1111
use std::{
1212
fs,
1313
path::{Path, PathBuf},
@@ -35,7 +35,7 @@ pub fn get_conda_environment_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
3535
envs
3636
});
3737

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

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

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

crates/pet-conda/src/environments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pet_core::{
1212
manager::EnvManager,
1313
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory},
1414
};
15-
use pet_utils::{executable::find_executable, path::fix_file_path_casing};
15+
use pet_utils::{executable::find_executable, path::normalize};
1616
use std::{
1717
fs,
1818
path::{Path, PathBuf},
@@ -180,7 +180,7 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option<PathBuf> {
180180
// The casing in history might not be same as that on disc
181181
// We do not want to have duplicates in different cases.
182182
// & we'd like to preserve the case of the original path as on disc.
183-
return Some(fix_file_path_casing(conda_dir).to_path_buf());
183+
return Some(normalize(conda_dir).to_path_buf());
184184
}
185185
}
186186
// Sometimes we can have paths like
@@ -212,7 +212,7 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option<PathBuf> {
212212
// The casing in history might not be same as that on disc
213213
// We do not want to have duplicates in different cases.
214214
// & we'd like to preserve the case of the original path as on disc.
215-
return Some(fix_file_path_casing(&cmd_line).to_path_buf());
215+
return Some(normalize(&cmd_line).to_path_buf());
216216
}
217217
}
218218
None

crates/pet-conda/src/manager.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,3 @@ fn get_conda_manager(path: &Path) -> Option<CondaManager> {
135135
None
136136
}
137137
}
138-
139-
// pub fn get_conda_version(conda_binary: &PathBuf) -> Option<String> {
140-
// let mut parent = conda_binary.parent()?;
141-
// if parent.ends_with("bin") {
142-
// parent = parent.parent()?;
143-
// }
144-
// if parent.ends_with("Library") {
145-
// parent = parent.parent()?;
146-
// }
147-
// match get_conda_package_info(&parent, "conda") {
148-
// Some(result) => Some(result.version),
149-
// None => match get_conda_package_info(&parent.parent()?, "conda") {
150-
// Some(result) => Some(result.version),
151-
// None => None,
152-
// },
153-
// }
154-
// }

crates/pet-conda/src/mod.rs

Lines changed: 0 additions & 246 deletions
This file was deleted.

0 commit comments

Comments
 (0)