Skip to content

Commit 27d13de

Browse files
committed
fix: address Poetry cache path review feedback (PR #417)
1 parent 98d1437 commit 27d13de

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

crates/pet-poetry/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn is_poetry_cache_environment(path: &Path) -> bool {
4949
// Further validate by checking if the directory name matches Poetry's naming pattern
5050
// Pattern: {name}-{8-char-hash}-py{version}
5151
if let Some(dir_name) = path.file_name().and_then(|n| n.to_str()) {
52-
// Check for Poetry's hash-based naming: name-XXXXXXXX-py
52+
// Check for Poetry's hash-based naming: name-XXXXXXXX-py<major>.<minor>
5353
// The hash is 8 characters of base64url encoding
5454
if POETRY_ENV_NAME_PATTERN.is_match(dir_name) {
5555
return true;
@@ -63,16 +63,22 @@ fn is_poetry_cache_environment(path: &Path) -> bool {
6363
fn has_poetry_cache_components(path: &Path) -> bool {
6464
let mut found_pypoetry = false;
6565

66-
path.components()
67-
.filter_map(|component| component.as_os_str().to_str())
68-
.any(|component| {
69-
if component.eq_ignore_ascii_case("pypoetry") {
70-
found_pypoetry = true;
71-
return false;
72-
}
66+
for component in path.components() {
67+
let Some(component) = component.as_os_str().to_str() else {
68+
return false;
69+
};
7370

74-
found_pypoetry && component.eq_ignore_ascii_case("virtualenvs")
75-
})
71+
if component.eq_ignore_ascii_case("pypoetry") {
72+
found_pypoetry = true;
73+
continue;
74+
}
75+
76+
if found_pypoetry && component.eq_ignore_ascii_case("virtualenvs") {
77+
return true;
78+
}
79+
}
80+
81+
false
7682
}
7783

7884
/// Check if a .venv directory is an in-project Poetry environment

0 commit comments

Comments
 (0)