Skip to content

Commit 85bcc76

Browse files
committed
Formatting
1 parent 9b02261 commit 85bcc76

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

crates/pet-core/src/pyvenv_cfg.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ impl PyVenvCfg {
4242
uv_version,
4343
}
4444
}
45-
45+
4646
/// Returns true if this virtual environment was created with UV
4747
pub fn is_uv(&self) -> bool {
4848
self.uv_version.is_some()
4949
}
50-
50+
5151
pub fn find(path: &Path) -> Option<Self> {
5252
if let Some(ref file) = find(path) {
5353
parse(file)
@@ -141,7 +141,9 @@ fn parse(file: &Path) -> Option<PyVenvCfg> {
141141
}
142142

143143
match (version, version_major, version_minor) {
144-
(Some(ver), Some(major), Some(minor)) => Some(PyVenvCfg::new(ver, major, minor, prompt, uv_version)),
144+
(Some(ver), Some(major), Some(minor)) => {
145+
Some(PyVenvCfg::new(ver, major, minor, prompt, uv_version))
146+
}
145147
_ => None,
146148
}
147149
}

crates/pet-venv/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ pub fn is_venv_dir(path: &Path) -> bool {
3131

3232
/// Check if this is a UV-created virtual environment
3333
pub fn is_venv_uv(env: &PythonEnv) -> bool {
34-
if let Some(cfg) = PyVenvCfg::find(env.executable.parent().unwrap_or(&env.executable))
35-
.or_else(|| PyVenvCfg::find(&env.prefix.clone().unwrap_or_else(|| env.executable.parent().unwrap().parent().unwrap().to_path_buf())))
34+
if let Some(cfg) =
35+
PyVenvCfg::find(env.executable.parent().unwrap_or(&env.executable)).or_else(|| {
36+
PyVenvCfg::find(&env.prefix.clone().unwrap_or_else(|| {
37+
env.executable
38+
.parent()
39+
.unwrap()
40+
.parent()
41+
.unwrap()
42+
.to_path_buf()
43+
}))
44+
})
3645
{
3746
cfg.is_uv()
3847
} else {
@@ -90,7 +99,7 @@ impl Locator for Venv {
9099
let cfg = PyVenvCfg::find(env.executable.parent()?)
91100
.or_else(|| PyVenvCfg::find(&env.prefix.clone()?));
92101
let name = cfg.as_ref().and_then(|cfg| cfg.prompt.clone());
93-
102+
94103
// Determine environment kind based on whether UV was used
95104
let kind = match &cfg {
96105
Some(cfg) if cfg.is_uv() => Some(PythonEnvironmentKind::VenvUv),

crates/pet-venv/tests/mod.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ use std::fs;
77
use tempfile::TempDir;
88

99
use pet_core::pyvenv_cfg::PyVenvCfg;
10+
use pet_core::Locator;
1011
use pet_core::{env::PythonEnv, python_environment::PythonEnvironmentKind};
1112
use pet_venv::{is_venv, is_venv_dir, is_venv_uv, is_venv_uv_dir, Venv};
12-
use pet_core::Locator;
1313

1414
/// Test that we can detect regular venv environments
1515
#[test]
1616
fn test_detect_regular_venv() {
1717
let temp_dir = TempDir::new().unwrap();
1818
let venv_dir = temp_dir.path().join("test_venv");
1919
fs::create_dir_all(&venv_dir).unwrap();
20-
20+
2121
// Create a regular pyvenv.cfg (without UV)
2222
let pyvenv_cfg_content = r#"home = /usr/bin
2323
implementation = CPython
@@ -27,29 +27,33 @@ prompt = test_venv
2727
"#;
2828
let pyvenv_cfg_path = venv_dir.join("pyvenv.cfg");
2929
fs::write(&pyvenv_cfg_path, pyvenv_cfg_content).unwrap();
30-
30+
3131
// Create a dummy python executable
3232
let scripts_dir = if cfg!(windows) { "Scripts" } else { "bin" };
3333
let bin_dir = venv_dir.join(scripts_dir);
3434
fs::create_dir_all(&bin_dir).unwrap();
35-
let python_exe = bin_dir.join(if cfg!(windows) { "python.exe" } else { "python" });
35+
let python_exe = bin_dir.join(if cfg!(windows) {
36+
"python.exe"
37+
} else {
38+
"python"
39+
});
3640
fs::write(&python_exe, "dummy").unwrap();
37-
41+
3842
// Test PyVenvCfg detection
3943
let cfg = PyVenvCfg::find(&venv_dir).unwrap();
4044
assert!(!cfg.is_uv());
4145
assert_eq!(cfg.version, "3.12.11");
4246
assert_eq!(cfg.prompt, Some("test_venv".to_string()));
43-
47+
4448
// Test directory detection
4549
assert!(is_venv_dir(&venv_dir));
4650
assert!(!is_venv_uv_dir(&venv_dir));
47-
51+
4852
// Test with PythonEnv
4953
let python_env = PythonEnv::new(python_exe.clone(), None, None);
5054
assert!(is_venv(&python_env));
5155
assert!(!is_venv_uv(&python_env));
52-
56+
5357
// Test locator
5458
let locator = Venv::new();
5559
let result = locator.try_from(&python_env).unwrap();
@@ -63,7 +67,7 @@ fn test_detect_uv_venv() {
6367
let temp_dir = TempDir::new().unwrap();
6468
let venv_dir = temp_dir.path().join("test_uv_venv");
6569
fs::create_dir_all(&venv_dir).unwrap();
66-
70+
6771
// Create a UV pyvenv.cfg (with UV entry)
6872
let pyvenv_cfg_content = r#"home = /usr/bin
6973
implementation = CPython
@@ -74,30 +78,34 @@ prompt = test_uv_venv
7478
"#;
7579
let pyvenv_cfg_path = venv_dir.join("pyvenv.cfg");
7680
fs::write(&pyvenv_cfg_path, pyvenv_cfg_content).unwrap();
77-
81+
7882
// Create a dummy python executable
7983
let scripts_dir = if cfg!(windows) { "Scripts" } else { "bin" };
8084
let bin_dir = venv_dir.join(scripts_dir);
8185
fs::create_dir_all(&bin_dir).unwrap();
82-
let python_exe = bin_dir.join(if cfg!(windows) { "python.exe" } else { "python" });
86+
let python_exe = bin_dir.join(if cfg!(windows) {
87+
"python.exe"
88+
} else {
89+
"python"
90+
});
8391
fs::write(&python_exe, "dummy").unwrap();
84-
92+
8593
// Test PyVenvCfg detection
8694
let cfg = PyVenvCfg::find(&venv_dir).unwrap();
8795
assert!(cfg.is_uv());
8896
assert_eq!(cfg.uv_version, Some("0.8.14".to_string()));
8997
assert_eq!(cfg.version, "3.12.11");
9098
assert_eq!(cfg.prompt, Some("test_uv_venv".to_string()));
91-
99+
92100
// Test directory detection
93101
assert!(is_venv_dir(&venv_dir));
94102
assert!(is_venv_uv_dir(&venv_dir));
95-
103+
96104
// Test with PythonEnv
97105
let python_env = PythonEnv::new(python_exe.clone(), None, None);
98106
assert!(is_venv(&python_env));
99107
assert!(is_venv_uv(&python_env));
100-
108+
101109
// Test locator
102110
let locator = Venv::new();
103111
let result = locator.try_from(&python_env).unwrap();
@@ -111,15 +119,15 @@ fn test_uv_version_parsing() {
111119
let temp_dir = TempDir::new().unwrap();
112120
let venv_dir = temp_dir.path().join("test_uv_version");
113121
fs::create_dir_all(&venv_dir).unwrap();
114-
122+
115123
// Test different UV version formats
116124
let test_cases = vec![
117125
("uv = 0.8.14", Some("0.8.14".to_string())),
118126
("uv=0.8.14", Some("0.8.14".to_string())),
119127
("uv = 1.0.0-beta", Some("1.0.0-beta".to_string())),
120128
("uv= 2.1.3 ", Some("2.1.3".to_string())),
121129
];
122-
130+
123131
for (uv_line, expected) in test_cases {
124132
let pyvenv_cfg_content = format!(
125133
r#"home = /usr/bin
@@ -133,7 +141,7 @@ prompt = test_uv
133141
);
134142
let pyvenv_cfg_path = venv_dir.join("pyvenv.cfg");
135143
fs::write(&pyvenv_cfg_path, pyvenv_cfg_content).unwrap();
136-
144+
137145
let cfg = PyVenvCfg::find(&venv_dir).unwrap();
138146
assert_eq!(cfg.uv_version, expected, "Failed for UV line: {}", uv_line);
139147
assert!(cfg.is_uv());
@@ -145,8 +153,8 @@ prompt = test_uv
145153
fn test_locator_supported_categories() {
146154
let locator = Venv::new();
147155
let categories = locator.supported_categories();
148-
156+
149157
assert!(categories.contains(&PythonEnvironmentKind::Venv));
150158
assert!(categories.contains(&PythonEnvironmentKind::VenvUv));
151159
assert_eq!(categories.len(), 2);
152-
}
160+
}

0 commit comments

Comments
 (0)