Skip to content

Commit badbd94

Browse files
Copilotkarthiknadig
andcommitted
Fix all clippy warnings and format code
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
1 parent 3bfba83 commit badbd94

File tree

11 files changed

+96
-93
lines changed

11 files changed

+96
-93
lines changed

crates/pet-conda/tests/ci_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn create_conda_env(mode: &CondaCreateEnvNameOrPath, python_version: Option<Stri
387387
.expect("Failed to execute command");
388388
}
389389

390-
fn get_version(value: &String) -> String {
390+
fn get_version(value: &str) -> String {
391391
// Regex to extract just the d.d.d version from the full version string
392392
let re = regex::Regex::new(r"\d+\.\d+\.\d+").unwrap();
393393
let captures = re.captures(value).unwrap();

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {
416416

417417
#[cfg(test)]
418418
mod tests {
419-
use super::*;
419+
#[cfg(windows)]
420+
use super::{get_shortest_executable, PythonEnvironmentKind};
421+
#[cfg(windows)]
422+
use std::path::PathBuf;
420423

421424
#[test]
422425
#[cfg(windows)]

crates/pet-poetry/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ regex = "1.10.4"
2121
sha2 = "0.10.6"
2222
base64 = "0.22.0"
2323
toml = "0.8.14"
24+
25+
[features]
26+
ci = []

crates/pet-poetry/tests/common.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,27 @@ pub struct TestEnvironment {
3535
home: Option<PathBuf>,
3636
root: Option<PathBuf>,
3737
}
38+
39+
impl Environment for TestEnvironment {
40+
fn get_env_var(&self, key: String) -> Option<String> {
41+
self.vars.get(&key).cloned()
42+
}
43+
fn get_root(&self) -> Option<PathBuf> {
44+
self.root.clone()
45+
}
46+
fn get_user_home(&self) -> Option<PathBuf> {
47+
self.home.clone()
48+
}
49+
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
50+
vec![]
51+
}
52+
}
53+
3854
#[allow(dead_code)]
3955
pub fn create_test_environment(
4056
vars: HashMap<String, String>,
4157
home: Option<PathBuf>,
4258
root: Option<PathBuf>,
4359
) -> TestEnvironment {
44-
impl Environment for TestEnvironment {
45-
fn get_env_var(&self, key: String) -> Option<String> {
46-
self.vars.get(&key).cloned()
47-
}
48-
fn get_root(&self) -> Option<PathBuf> {
49-
self.root.clone()
50-
}
51-
fn get_user_home(&self) -> Option<PathBuf> {
52-
self.home.clone()
53-
}
54-
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
55-
vec![]
56-
}
57-
}
5860
TestEnvironment { vars, home, root }
5961
}

crates/pet-poetry/tests/config_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ fn global_config_with_specific_values() {
8383
#[cfg(unix)]
8484
#[cfg_attr(any(feature = "ci",), test)]
8585
#[allow(dead_code)]
86-
8786
fn local_config_with_specific_values() {
8887
use std::path::PathBuf;
8988

crates/pet-pyenv/tests/common.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,29 @@ pub struct TestEnvironment {
3434
root: Option<PathBuf>,
3535
globals_locations: Vec<PathBuf>,
3636
}
37+
38+
impl Environment for TestEnvironment {
39+
fn get_env_var(&self, key: String) -> Option<String> {
40+
self.vars.get(&key).cloned()
41+
}
42+
fn get_root(&self) -> Option<PathBuf> {
43+
self.root.clone()
44+
}
45+
fn get_user_home(&self) -> Option<PathBuf> {
46+
self.home.clone()
47+
}
48+
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
49+
self.globals_locations.clone()
50+
}
51+
}
52+
3753
#[allow(dead_code)]
3854
pub fn create_test_environment(
3955
vars: HashMap<String, String>,
4056
home: Option<PathBuf>,
4157
globals_locations: Vec<PathBuf>,
4258
root: Option<PathBuf>,
4359
) -> TestEnvironment {
44-
impl Environment for TestEnvironment {
45-
fn get_env_var(&self, key: String) -> Option<String> {
46-
self.vars.get(&key).cloned()
47-
}
48-
fn get_root(&self) -> Option<PathBuf> {
49-
self.root.clone()
50-
}
51-
fn get_user_home(&self) -> Option<PathBuf> {
52-
self.home.clone()
53-
}
54-
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
55-
self.globals_locations.clone()
56-
}
57-
}
5860
TestEnvironment {
5961
vars,
6062
home,

crates/pet-pyenv/tests/pyenv_test.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ fn find_pyenv_envs() {
164164
home.to_str().unwrap(),
165165
".pyenv/versions/3.9.9/bin/python",
166166
])]),
167-
..Default::default()
168167
};
169168
let expected_virtual_env = PythonEnvironment {
170169
display_name: None,
@@ -186,7 +185,6 @@ fn find_pyenv_envs() {
186185
home.to_str().unwrap(),
187186
".pyenv/versions/my-virtual-env/bin/python",
188187
])]),
189-
..Default::default()
190188
};
191189
let expected_3_12_1 = PythonEnvironment {
192190
display_name: None,
@@ -208,7 +206,6 @@ fn find_pyenv_envs() {
208206
home.to_str().unwrap(),
209207
".pyenv/versions/3.12.1/bin/python",
210208
])]),
211-
..Default::default()
212209
};
213210
let expected_3_13_dev = PythonEnvironment {
214211
display_name: None,
@@ -230,7 +227,6 @@ fn find_pyenv_envs() {
230227
home.to_str().unwrap(),
231228
".pyenv/versions/3.13-dev/bin/python",
232229
])]),
233-
..Default::default()
234230
};
235231
let expected_3_12_1a3 = PythonEnvironment {
236232
display_name: None,
@@ -252,7 +248,6 @@ fn find_pyenv_envs() {
252248
home.to_str().unwrap(),
253249
".pyenv/versions/3.12.1a3/bin/python",
254250
])]),
255-
..Default::default()
256251
};
257252
let expected_no_gil = PythonEnvironment {
258253
display_name: None,
@@ -274,7 +269,6 @@ fn find_pyenv_envs() {
274269
home.to_str().unwrap(),
275270
".pyenv/versions/nogil-3.9.10-1/bin/python",
276271
])]),
277-
..Default::default()
278272
};
279273
let expected_pypy = PythonEnvironment {
280274
display_name: None,
@@ -296,7 +290,6 @@ fn find_pyenv_envs() {
296290
home.to_str().unwrap(),
297291
".pyenv/versions/pypy3.9-7.3.15/bin/python",
298292
])]),
299-
..Default::default()
300293
};
301294

302295
let expected_conda_root = PythonEnvironment {
@@ -310,7 +303,6 @@ fn find_pyenv_envs() {
310303
manager: Some(expected_conda_manager.clone()),
311304
arch: Some(Architecture::X64),
312305
symlinks: Some(vec![conda_dir.join("bin").join("python")]),
313-
..Default::default()
314306
};
315307
let expected_conda_one = PythonEnvironment {
316308
display_name: None,
@@ -323,7 +315,6 @@ fn find_pyenv_envs() {
323315
manager: Some(expected_conda_manager.clone()),
324316
arch: None,
325317
symlinks: Some(vec![conda_dir.join("envs").join("one").join("python")]),
326-
..Default::default()
327318
};
328319
let expected_conda_two = PythonEnvironment {
329320
display_name: None,
@@ -336,7 +327,6 @@ fn find_pyenv_envs() {
336327
manager: Some(expected_conda_manager.clone()),
337328
symlinks: Some(vec![conda_dir.join("envs").join("two").join("python")]),
338329
arch: None,
339-
..Default::default()
340330
};
341331

342332
let mut expected_envs = vec![
@@ -406,7 +396,6 @@ fn resolve_pyenv_environment() {
406396
manager: Some(expected_manager.clone()),
407397
arch: None,
408398
symlinks: Some(vec![executable]),
409-
..Default::default()
410399
};
411400
let expected_virtual_env = PythonEnvironment {
412401
display_name: None,
@@ -428,7 +417,6 @@ fn resolve_pyenv_environment() {
428417
home.to_str().unwrap(),
429418
".pyenv/versions/my-virtual-env/bin/python",
430419
])]),
431-
..Default::default()
432420
};
433421

434422
// Resolve regular Python installs in Pyenv

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/ci_test.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ fn verify_validity_of_discovered_envs() {
7575
let environment = EnvironmentApi::new();
7676
let conda_locator = Arc::new(Conda::from(&environment));
7777
let poetry_locator = Arc::new(Poetry::from(&environment));
78-
let mut config = Configuration::default();
79-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
78+
let config = Configuration {
79+
workspace_directories: Some(vec![workspace_dir.clone()]),
80+
..Default::default()
81+
};
8082
let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment);
8183
for locator in locators.iter() {
8284
locator.configure(&config);
@@ -283,19 +285,16 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) {
283285
}
284286
}
285287
if let Some(prefix) = environment.clone().prefix {
286-
if interpreter_info.clone().executable == "/usr/local/python/current/bin/python"
288+
if (interpreter_info.clone().executable == "/usr/local/python/current/bin/python"
287289
&& (prefix.to_str().unwrap() == "/usr/local/python/current"
288290
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
289291
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
290-
&& interpreter_info.clone().sys_prefix == "/usr/local/python/current")
291-
{
292-
// known issue https://github.com/microsoft/python-environment-tools/issues/64
293-
} else if interpreter_info.clone().executable
294-
== "/home/codespace/.python/current/bin/python"
295-
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
296-
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
297-
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
298-
&& interpreter_info.clone().sys_prefix == "/home/codespace/.python/current")
292+
&& interpreter_info.clone().sys_prefix == "/usr/local/python/current"))
293+
|| (interpreter_info.clone().executable == "/home/codespace/.python/current/bin/python"
294+
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
295+
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
296+
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
297+
&& interpreter_info.clone().sys_prefix == "/home/codespace/.python/current"))
299298
{
300299
// known issue https://github.com/microsoft/python-environment-tools/issues/64
301300
} else {
@@ -487,20 +486,19 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment,
487486
actual.version = expected.clone().version;
488487

489488
if let Some(prefix) = expected.clone().prefix {
490-
if actual.clone().executable == Some(PathBuf::from("/usr/local/python/current/bin/python"))
489+
if (actual.clone().executable
490+
== Some(PathBuf::from("/usr/local/python/current/bin/python"))
491491
&& (prefix.to_str().unwrap() == "/usr/local/python/current"
492492
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
493493
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
494-
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/current")))
495-
{
496-
// known issue https://github.com/microsoft/python-environment-tools/issues/64
497-
actual.prefix = expected.clone().prefix;
498-
} else if actual.clone().executable
499-
== Some(PathBuf::from("/home/codespace/.python/current/bin/python"))
500-
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
501-
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
502-
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
503-
&& actual.clone().prefix == Some(PathBuf::from("/home/codespace/.python/current")))
494+
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/current"))))
495+
|| (actual.clone().executable
496+
== Some(PathBuf::from("/home/codespace/.python/current/bin/python"))
497+
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
498+
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
499+
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
500+
&& actual.clone().prefix
501+
== Some(PathBuf::from("/home/codespace/.python/current"))))
504502
{
505503
// known issue https://github.com/microsoft/python-environment-tools/issues/64
506504
actual.prefix = expected.clone().prefix;
@@ -591,8 +589,10 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe(
591589
let os_environment = EnvironmentApi::new();
592590
let conda_locator = Arc::new(Conda::from(&os_environment));
593591
let poetry_locator = Arc::new(Poetry::from(&os_environment));
594-
let mut config = Configuration::default();
595-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
592+
let config = Configuration {
593+
workspace_directories: Some(vec![workspace_dir.clone()]),
594+
..Default::default()
595+
};
596596
let locators = create_locators(
597597
conda_locator.clone(),
598598
poetry_locator.clone(),
@@ -720,13 +720,13 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
720720
"python".to_string(),
721721
]
722722
} else if let Some(prefix) = env.prefix.clone() {
723-
return vec![
723+
vec![
724724
conda_exe,
725725
"run".to_string(),
726726
"-p".to_string(),
727727
prefix.to_str().unwrap_or_default().to_string(),
728728
"python".to_string(),
729-
];
729+
]
730730
} else {
731731
panic!("Conda environment without name or prefix")
732732
}
@@ -741,8 +741,8 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
741741
}
742742
}
743743

744-
fn get_python_interpreter_info(cli: &Vec<String>) -> InterpreterInfo {
745-
let mut cli = cli.clone();
744+
fn get_python_interpreter_info(cli: &[String]) -> InterpreterInfo {
745+
let mut cli = cli.to_owned();
746746
cli.push(
747747
resolve_test_path(&["interpreterInfo.py"])
748748
.to_str()

0 commit comments

Comments
 (0)