Skip to content

Commit eada485

Browse files
Copilotkarthiknadig
andcommitted
Fix initial clippy warnings: unused imports, non-local impl blocks, and function restructuring
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
1 parent f346c90 commit eada485

7 files changed

Lines changed: 70 additions & 63 deletions

File tree

crates/pet-conda/tests/common.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,29 @@ pub struct TestEnvironment {
4646
root: Option<PathBuf>,
4747
globals_locations: Vec<PathBuf>,
4848
}
49+
50+
impl Environment for TestEnvironment {
51+
fn get_env_var(&self, key: String) -> Option<String> {
52+
self.vars.get(&key).cloned()
53+
}
54+
fn get_root(&self) -> Option<PathBuf> {
55+
self.root.clone()
56+
}
57+
fn get_user_home(&self) -> Option<PathBuf> {
58+
self.home.clone()
59+
}
60+
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
61+
self.globals_locations.clone()
62+
}
63+
}
64+
4965
#[allow(dead_code)]
5066
pub fn create_test_environment(
5167
vars: HashMap<String, String>,
5268
home: Option<PathBuf>,
5369
globals_locations: Vec<PathBuf>,
5470
root: Option<PathBuf>,
5571
) -> TestEnvironment {
56-
impl Environment for TestEnvironment {
57-
fn get_env_var(&self, key: String) -> Option<String> {
58-
self.vars.get(&key).cloned()
59-
}
60-
fn get_root(&self) -> Option<PathBuf> {
61-
self.root.clone()
62-
}
63-
fn get_user_home(&self) -> Option<PathBuf> {
64-
self.home.clone()
65-
}
66-
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
67-
self.globals_locations.clone()
68-
}
69-
}
7072
TestEnvironment {
7173
vars,
7274
home,

crates/pet-core/src/python_environment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {
416416

417417
#[cfg(test)]
418418
mod tests {
419+
#[cfg(windows)]
419420
use super::*;
420421

421422
#[test]

crates/pet-python-utils/src/executable.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,46 @@ fn is_python_executable_name(exe: &Path) -> bool {
119119
}
120120
}
121121

122+
pub fn should_search_for_environments_in_path<P: AsRef<Path>>(path: &P) -> bool {
123+
// Never search in the .git folder
124+
// Never search in the node_modules folder
125+
// Mostly copied from https://github.com/github/gitignore/blob/main/Python.gitignore
126+
let folders_to_ignore = [
127+
"node_modules",
128+
".cargo",
129+
".devcontainer",
130+
".github",
131+
".git",
132+
".tox",
133+
".nox",
134+
".hypothesis",
135+
".ipynb_checkpoints",
136+
".eggs",
137+
".coverage",
138+
".cache",
139+
".pyre",
140+
".ptype",
141+
".pytest_cache",
142+
".vscode",
143+
"__pycache__",
144+
"__pypackages__",
145+
".mypy_cache",
146+
"cython_debug",
147+
"env.bak",
148+
"venv.bak",
149+
"Scripts", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env.
150+
"bin", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env.
151+
];
152+
for folder in folders_to_ignore.iter() {
153+
if path.as_ref().ends_with(folder) {
154+
trace!("Ignoring folder: {:?}", path.as_ref());
155+
return false;
156+
}
157+
}
158+
159+
true
160+
}
161+
122162
#[cfg(test)]
123163
mod tests {
124164
use super::*;
@@ -186,43 +226,3 @@ mod tests {
186226
));
187227
}
188228
}
189-
190-
pub fn should_search_for_environments_in_path<P: AsRef<Path>>(path: &P) -> bool {
191-
// Never search in the .git folder
192-
// Never search in the node_modules folder
193-
// Mostly copied from https://github.com/github/gitignore/blob/main/Python.gitignore
194-
let folders_to_ignore = [
195-
"node_modules",
196-
".cargo",
197-
".devcontainer",
198-
".github",
199-
".git",
200-
".tox",
201-
".nox",
202-
".hypothesis",
203-
".ipynb_checkpoints",
204-
".eggs",
205-
".coverage",
206-
".cache",
207-
".pyre",
208-
".ptype",
209-
".pytest_cache",
210-
".vscode",
211-
"__pycache__",
212-
"__pypackages__",
213-
".mypy_cache",
214-
"cython_debug",
215-
"env.bak",
216-
"venv.bak",
217-
"Scripts", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env.
218-
"bin", // If the folder ends bin/scripts, then ignore it, as the parent is most likely an env.
219-
];
220-
for folder in folders_to_ignore.iter() {
221-
if path.as_ref().ends_with(folder) {
222-
trace!("Ignoring folder: {:?}", path.as_ref());
223-
return false;
224-
}
225-
}
226-
227-
true
228-
}

crates/pet/tests/ci_homebrew_container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn verify_python_in_homebrew_contaner() {
107107
let python_env = environments
108108
.iter()
109109
.find(|e| e.executable == env.executable)
110-
.expect(format!("Expected to find python environment {:?}", env.executable).as_str());
110+
.unwrap_or_else(|| panic!("Expected to find python environment {:?}", env.executable));
111111
assert_eq!(python_env.executable, env.executable);
112112
assert_eq!(python_env.kind, env.kind);
113113
assert_eq!(python_env.manager, env.manager);

crates/pet/tests/ci_jupyter_container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn verify_python_in_jupyter_contaner() {
137137
let python_env = environments
138138
.iter()
139139
.find(|e| e.executable == env.executable)
140-
.expect(format!("Expected to find python environment {:?}", env.executable).as_str());
140+
.unwrap_or_else(|| panic!("Expected to find python environment {:?}", env.executable));
141141
assert_eq!(
142142
python_env.executable, env.executable,
143143
"Expected exe to be same when comparing {python_env:?} and {env:?}"

crates/pet/tests/ci_poetry.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ fn verify_ci_poetry_global() {
4040
let environment = EnvironmentApi::new();
4141
let conda_locator = Arc::new(Conda::from(&environment));
4242
let poetry_locator = Arc::new(Poetry::from(&environment));
43-
let mut config = Configuration::default();
44-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
43+
let config = Configuration {
44+
workspace_directories: Some(vec![workspace_dir.clone()]),
45+
..Default::default()
46+
};
4547
let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment);
4648
for locator in locators.iter() {
4749
locator.configure(&config);
@@ -110,8 +112,10 @@ fn verify_ci_poetry_project() {
110112
let environment = EnvironmentApi::new();
111113
let conda_locator = Arc::new(Conda::from(&environment));
112114
let poetry_locator = Arc::new(Poetry::from(&environment));
113-
let mut config = Configuration::default();
114-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
115+
let config = Configuration {
116+
workspace_directories: Some(vec![workspace_dir.clone()]),
117+
..Default::default()
118+
};
115119
let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment);
116120
for locator in locators.iter() {
117121
locator.configure(&config);

crates/pet/tests/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub fn resolve_test_path(paths: &[&str]) -> PathBuf {
2222
}
2323

2424
#[allow(dead_code)]
25-
pub fn does_version_match(version: &String, expected_version: &String) -> bool {
25+
pub fn does_version_match(version: &str, expected_version: &str) -> bool {
2626
let version = get_version(version);
2727
expected_version.starts_with(&version)
2828
}
2929

30-
fn get_version(value: &String) -> String {
30+
fn get_version(value: &str) -> String {
3131
// Regex to extract just the d.d.d version from the full version string
3232
let captures = PYTHON_VERSION.captures(value).unwrap();
3333
let version = captures.get(1).unwrap().as_str().to_string();
@@ -39,6 +39,6 @@ fn get_version(value: &String) -> String {
3939
}
4040

4141
#[allow(dead_code)]
42-
pub fn is_valid_version(value: &String) -> bool {
42+
pub fn is_valid_version(value: &str) -> bool {
4343
PYTHON_FULLVERSION.is_match(value)
4444
}

0 commit comments

Comments
 (0)