Skip to content

Commit 5e66a8c

Browse files
edvilmeCopilot
andcommitted
fix: handle Option<PathBuf> from resolve_dot_venv correctly
- find.rs: resolve_dot_venv returns Option<PathBuf>, use if-let to conditionally insert into search paths vec - environment_locations.rs: fix bug where ? operator on None would short-circuit the function, losing already-collected environments - path.rs: remove trailing whitespace in doc comments (fmt check) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9d47e7f commit 5e66a8c

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

crates/pet-fs/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ fn get_user_home() -> Option<PathBuf> {
336336

337337
/// Resolves the `.venv` entry in a directory to the virtual environment path. `.venv` may be either
338338
/// - A **directory**: The virtual environment itself (traditional convention)
339-
/// - A **file**: A text file containing the path (relative or absolute) to the virtual environment
339+
/// - A **file**: A text file containing the path (relative or absolute) to the virtual environment
340340
/// located somewhere else in disk (PEP 832 convention)
341-
///
341+
///
342342
/// # Resolution order
343343
/// 1. If `<dir>/.venv` is a directory, return that path.
344344
/// 2. If `<dir>/.venv` is a file, read its contents, trim whitespaces, and resolve the path:

crates/pet-poetry/src/environment_locations.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ fn list_all_environments_from_project_config(
109109
// Order of preference is Project (local config) > EnvVariable > Global
110110
if should_use_local_venv_as_poetry_env(global, &local, env) {
111111
// If virtualenvs are in the project, then look for .venv
112-
let venv = resolve_dot_venv(path);
113-
if venv.clone()?.is_dir() {
114-
envs.push(venv?);
112+
if let Some(venv) = resolve_dot_venv(path) {
113+
if venv.is_dir() {
114+
envs.push(venv);
115+
}
115116
}
116117
}
117118
Some(envs)

crates/pet/src/find.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,14 @@ pub fn find_python_environments_in_workspace_folder_recursive(
277277
let mut paths_to_search_first = vec![
278278
// Possible this is a virtual env
279279
workspace_folder.to_path_buf(),
280-
// Optimize for finding these first.
281-
resolve_dot_venv(workspace_folder),
282280
workspace_folder.join(".conda"),
283281
workspace_folder.join(".virtualenv"),
284282
workspace_folder.join("venv"),
285283
];
284+
// Optimize for finding .venv first (supports PEP 832 file-based .venv).
285+
if let Some(dot_venv) = resolve_dot_venv(workspace_folder) {
286+
paths_to_search_first.insert(1, dot_venv);
287+
}
286288

287289
// Add all subdirectories of .pixi/envs/**
288290
if let Ok(reader) = fs::read_dir(workspace_folder.join(".pixi").join("envs")) {

0 commit comments

Comments
 (0)