Skip to content

Commit a72405c

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

File tree

7 files changed

+50
-51
lines changed

7 files changed

+50
-51
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-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-pyenv/tests/pyenv_test.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ fn find_pyenv_envs() {
248248
home.to_str().unwrap(),
249249
".pyenv/versions/3.12.1a3/bin/python",
250250
])]),
251-
252251
};
253252
let expected_no_gil = PythonEnvironment {
254253
display_name: None,
@@ -270,7 +269,6 @@ fn find_pyenv_envs() {
270269
home.to_str().unwrap(),
271270
".pyenv/versions/nogil-3.9.10-1/bin/python",
272271
])]),
273-
274272
};
275273
let expected_pypy = PythonEnvironment {
276274
display_name: None,
@@ -292,7 +290,6 @@ fn find_pyenv_envs() {
292290
home.to_str().unwrap(),
293291
".pyenv/versions/pypy3.9-7.3.15/bin/python",
294292
])]),
295-
296293
};
297294

298295
let expected_conda_root = PythonEnvironment {
@@ -306,7 +303,6 @@ fn find_pyenv_envs() {
306303
manager: Some(expected_conda_manager.clone()),
307304
arch: Some(Architecture::X64),
308305
symlinks: Some(vec![conda_dir.join("bin").join("python")]),
309-
310306
};
311307
let expected_conda_one = PythonEnvironment {
312308
display_name: None,
@@ -319,7 +315,6 @@ fn find_pyenv_envs() {
319315
manager: Some(expected_conda_manager.clone()),
320316
arch: None,
321317
symlinks: Some(vec![conda_dir.join("envs").join("one").join("python")]),
322-
323318
};
324319
let expected_conda_two = PythonEnvironment {
325320
display_name: None,
@@ -332,7 +327,6 @@ fn find_pyenv_envs() {
332327
manager: Some(expected_conda_manager.clone()),
333328
symlinks: Some(vec![conda_dir.join("envs").join("two").join("python")]),
334329
arch: None,
335-
336330
};
337331

338332
let mut expected_envs = vec![
@@ -402,7 +396,6 @@ fn resolve_pyenv_environment() {
402396
manager: Some(expected_manager.clone()),
403397
arch: None,
404398
symlinks: Some(vec![executable]),
405-
406399
};
407400
let expected_virtual_env = PythonEnvironment {
408401
display_name: None,
@@ -424,7 +417,6 @@ fn resolve_pyenv_environment() {
424417
home.to_str().unwrap(),
425418
".pyenv/versions/my-virtual-env/bin/python",
426419
])]),
427-
428420
};
429421

430422
// 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: 19 additions & 21 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);
@@ -288,12 +290,9 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) {
288290
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
289291
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
290292
&& 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")
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")
297296
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
298297
&& interpreter_info.clone().sys_prefix == "/home/codespace/.python/current")
299298
{
@@ -492,13 +491,10 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment,
492491
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
493492
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
494493
&& 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")))
494+
|| actual.clone().executable
495+
== Some(PathBuf::from("/home/codespace/.python/current/bin/python"))
496+
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
497+
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
502498
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
503499
&& actual.clone().prefix == Some(PathBuf::from("/home/codespace/.python/current")))
504500
{
@@ -591,8 +587,10 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe(
591587
let os_environment = EnvironmentApi::new();
592588
let conda_locator = Arc::new(Conda::from(&os_environment));
593589
let poetry_locator = Arc::new(Poetry::from(&os_environment));
594-
let mut config = Configuration::default();
595-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
590+
let config = Configuration {
591+
workspace_directories: Some(vec![workspace_dir.clone()]),
592+
..Default::default()
593+
};
596594
let locators = create_locators(
597595
conda_locator.clone(),
598596
poetry_locator.clone(),
@@ -720,13 +718,13 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
720718
"python".to_string(),
721719
]
722720
} else if let Some(prefix) = env.prefix.clone() {
723-
return vec![
721+
vec![
724722
conda_exe,
725723
"run".to_string(),
726724
"-p".to_string(),
727725
prefix.to_str().unwrap_or_default().to_string(),
728726
"python".to_string(),
729-
];
727+
]
730728
} else {
731729
panic!("Conda environment without name or prefix")
732730
}
@@ -741,8 +739,8 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
741739
}
742740
}
743741

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

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)