Skip to content

Move hegel-core install to XDG cache dir#129

Open
DRMacIver wants to merge 4 commits intomainfrom
DRMacIver/xdg-home-install
Open

Move hegel-core install to XDG cache dir#129
DRMacIver wants to merge 4 commits intomainfrom
DRMacIver/xdg-home-install

Conversation

@DRMacIver
Copy link
Copy Markdown
Member

@DRMacIver DRMacIver commented Mar 26, 2026

Install hegel-core into $XDG_CACHE_HOME/hegel/versions//venv (or a suitable fallback for XDG_CACHE_HOME if not set) instead of the project-local .hegel/venv

Fixes #108 (more or less. Technically one can still trigger the bad behaviour if you work really hard, but it requires you to be doing something really screwy)

DRMacIver and others added 2 commits March 26, 2026 16:02
Install hegel-core into $XDG_CACHE_HOME/hegel/versions/<version>/venv
instead of the project-local .hegel/venv directory. Falls back to
~/Library/Caches/hegel on macOS and ~/.cache/hegel on Linux.

Adds mkdir-based cross-process file locking so parallel test processes
don't race on installation. Server logs remain in project-local .hegel/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…elease

The eprintln calls were writing to stderr instead of the install log.
Remove them rather than redirecting, since the log file already captures
uv output. Also change release_file_lock to expect instead of silently
discarding errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DRMacIver DRMacIver changed the title Move hegel-core install to XDG cache dir with cross-process file locking Move hegel-core install to XDG cache dir Mar 26, 2026
DRMacIver and others added 2 commits March 26, 2026 16:23
The test_missing_uv_error_message test was removing .hegel/ to clear the
cached install, but hegel-core now lives in the XDG cache directory. Fix
by pointing XDG_CACHE_HOME at an empty temp dir so no cached install is
found. Also fix a formatting diff caught by CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DRMacIver DRMacIver marked this pull request as ready for review March 26, 2026 22:25
Copy link
Copy Markdown
Member

@Liam-DeVoe Liam-DeVoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm broadly okay with this. The installation logic is now complicated enough that I'd like it to live in a src/installation.rs file. This will help with using it as a reference for other hegel libraries as well.

Comment on lines +1025 to +1037

#[cfg(test)]
mod tests {
use super::*;
use std::sync::Mutex as StdMutex;
use tempfile::TempDir;

// Environment variable tests must run serially since env vars are process-global.
// Use into_ok() to recover from poison (the should_panic test poisons the mutex).
static ENV_LOCK: StdMutex<()> = StdMutex::new(());

fn lock_env() -> std::sync::MutexGuard<'static, ()> {
ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests should live in a tests file to keep the actual code file clean

Comment on lines +25 to +30
///
/// Resolution order:
/// 1. `$XDG_CACHE_HOME/hegel` if `XDG_CACHE_HOME` is set
/// 2. `~/Library/Caches/hegel` on macOS
/// 3. `~/.cache/hegel` on other platforms
fn hegel_cache_dir() -> PathBuf {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually prefer ~/.cache/hegel even on macos. Yes, this is strictly speaking not the macos idiomatic location for caches. But it eliminates a code path for us, and plenty of tools use ~/.cache on macos, among them pip, uv, and gh.

I would say ~/.cache is actually the more standard location for coding ecosystem tool caches, while ~/Library/Caches is standard for application-level caches.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, seems reasonable.

Comment on lines +34 to +37
let home = std::env::var("HOME").expect(
"Could not determine home directory: HOME is not set. \
Set XDG_CACHE_HOME or HEGEL_SERVER_COMMAND to work around this.",
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use https://doc.rust-lang.org/std/env/fn.home_dir.html instead, which gets us windows support

Comment on lines +342 to +345
// Acquire cross-process file lock.
let lock_dir = version_dir.join(".install-lock");
acquire_file_lock(&lock_dir)?;
let result = do_install(&venv_dir, &version_file, &hegel_bin, &install_log);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.install-lock is actually a directory here, making this a lockdir, not a lockfile. I'd prefer to use a file here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Claude had some argument as to why a lockdir was better (atomic cross platform or something?) but I don't remember what it was. I'll investigate and see whether there's an actually compelling reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.hegel venv issues with containerized development

2 participants