Skip to content

Commit 4dc8f73

Browse files
authored
Update Poetry environment name regex to require Python version (#337)
Fixes #334 Refine the regex for Poetry environment names to ensure it includes the Python version, enhancing validation accuracy. Update tests to reflect this change.
1 parent 9d42321 commit 4dc8f73

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

crates/pet-poetry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod pyproject_toml;
3131
mod telemetry;
3232

3333
lazy_static! {
34-
static ref POETRY_ENV_NAME_PATTERN: Regex = Regex::new(r"^.+-[A-Za-z0-9_-]{8}-py.*$")
34+
static ref POETRY_ENV_NAME_PATTERN: Regex = Regex::new(r"^.+-[A-Za-z0-9_-]{8}-py\d+\.\d+$")
3535
.expect("Error generating RegEx for poetry environment name pattern");
3636
}
3737

crates/pet-poetry/tests/path_identification_test.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod tests {
3232

3333
if path_str.contains("pypoetry") && path_str.contains("virtualenvs") {
3434
if let Some(dir_name) = path.file_name().and_then(|n| n.to_str()) {
35-
let re = Regex::new(r"^.+-[A-Za-z0-9_-]{8}-py.*$").unwrap();
35+
let re = Regex::new(r"^.+-[A-Za-z0-9_-]{8}-py\d+\.\d+$").unwrap();
3636
return re.is_match(dir_name);
3737
}
3838
}
@@ -97,8 +97,10 @@ mod tests {
9797
}
9898

9999
#[test]
100-
fn test_poetry_path_pattern_no_version() {
101-
assert!(test_poetry_cache_path_pattern(
100+
fn test_poetry_path_pattern_no_version_rejected() {
101+
// Poetry always includes the Python version (major.minor) in the environment name
102+
// A name ending in just "py" without version should not match
103+
assert!(!test_poetry_cache_path_pattern(
102104
"/home/user/.cache/pypoetry/virtualenvs/testproject-XyZ12345-py"
103105
));
104106
}

0 commit comments

Comments
 (0)