Skip to content

Commit 29ad0dc

Browse files
committed
fix: address PR #460 round-3 review feedback
- resolve_project_virtual_dirs(): cache configured paths regardless of whether the directory exists on disk yet. A user may configure 'virtual = .hatch' and create the env later in this process lifetime; we now recognise it without requiring the client to re-send 'configure'. find_envs_in_flat_dir() already handles missing dirs by returning empty. - default_virtual_dir field doc: corrected to reflect that the path may not exist on disk; existence is rechecked at find() time. - Module docs: aligned with implementation. All workspace-configured 'dirs.env.virtual' paths use the flat layout, regardless of whether they are relative, absolute, or use ~ expansion.
1 parent b2a819b commit 29ad0dc

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

crates/pet-hatch/src/lib.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
//! virtual = ".hatch"
2626
//! ```
2727
//!
28-
//! When the configured `virtual` path is relative or matches `~/.virtualenvs`,
29-
//! Hatch uses a flat layout: `<configured_dir>/<venv_name>/`.
28+
//! For these workspace-configured locations Hatch uses a flat layout:
29+
//! `<configured_dir>/<venv_name>/`. Configured paths may be relative
30+
//! (resolved against the workspace root), absolute, or use `~` /
31+
//! `${HOME}` style expansion (e.g. `~/.virtualenvs`).
3032
3133
use std::{
3234
fs,
@@ -60,8 +62,12 @@ type WorkspaceVirtualDirs = Vec<(PathBuf, Vec<PathBuf>)>;
6062

6163
pub struct Hatch {
6264
/// Default storage directory for Hatch virtual environments — i.e.
63-
/// `<data_dir>/env/virtual`. Resolved at construction. None if the
64-
/// directory does not yet exist (it is created lazily by Hatch).
65+
/// `<data_dir>/env/virtual`. Resolved at construction. The path may not
66+
/// exist on disk yet (Hatch creates it lazily on first use); existence
67+
/// is re-checked by `find()` at discovery time so envs created later in
68+
/// this process lifetime are still discoverable without a restart.
69+
/// `None` only when the platform data directory itself cannot be
70+
/// resolved (e.g. no home directory).
6571
default_virtual_dir: Option<PathBuf>,
6672
/// Per-workspace resolved virtual directories, computed during
6773
/// `configure()` so that hot-path identification (`try_from`) does no
@@ -370,9 +376,15 @@ struct HatchDirs {
370376
/// each to an absolute directory. Both `pyproject.toml` (`[tool.hatch.dirs.env]`)
371377
/// and a top-level `hatch.toml` (`[dirs.env]`) are checked.
372378
///
373-
/// Each value may be relative (resolved against the workspace root) or
374-
/// absolute. Returns an empty Vec if the workspace is not a Hatch project,
375-
/// or if no `virtual` value is configured.
379+
/// Each value may be relative (resolved against the workspace root),
380+
/// absolute, or use `~` / `${HOME}` expansion. Returns an empty Vec if the
381+
/// workspace is not a Hatch project, or if no `virtual` value is configured.
382+
///
383+
/// The returned paths are cached regardless of whether they currently exist
384+
/// on disk — a user may configure `virtual = ".hatch"` and create the env
385+
/// later in this process lifetime, and we want subsequent `try_from()`
386+
/// calls to recognise it without requiring the client to re-send `configure`.
387+
/// `find_envs_in_flat_dir()` handles missing directories at discovery time.
376388
fn resolve_project_virtual_dirs(workspace: &Path) -> Vec<PathBuf> {
377389
let mut dirs = Vec::new();
378390
for raw in read_configured_virtual_paths(workspace) {
@@ -385,9 +397,7 @@ fn resolve_project_virtual_dirs(workspace: &Path) -> Vec<PathBuf> {
385397
} else {
386398
workspace.join(expanded)
387399
};
388-
if resolved.is_dir() {
389-
dirs.push(norm_case(resolved));
390-
}
400+
dirs.push(norm_case(resolved));
391401
}
392402
dirs
393403
}

0 commit comments

Comments
 (0)