Skip to content

Unified cache under sys.prefix - #5400

Merged
pbrubeck merged 5 commits into
mainfrom
pbrubeck/unify-cache-dirs
Aug 28, 2026
Merged

Unified cache under sys.prefix#5400
pbrubeck merged 5 commits into
mainfrom
pbrubeck/unify-cache-dirs

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

David asked, on #5346, for the sys.prefix writability check and the FIREDRAKE_CACHE_DIR unification to be split into their own PR:

test sys.prefix for writability. If it is then use it. If it is not writable then fall back to Path.home()

Put this in a separate PR. Possibly add support for FIREDRAKE_CACHE_DIR at the same time.

Summary

  • setup_cache_dirs() now checks sys.prefix for writability instead of reading $VIRTUAL_ENV (which is unset for a bare venv/bin/python invocation, and can point somewhere unwritable), falling back to Path.home() when it is not writable.
  • Introduces FIREDRAKE_CACHE_DIR as a single root directory. PYOP2_CACHE_DIR, FIREDRAKE_TSFC_KERNEL_CACHE_DIR, and loopy's pytools-backed persistent cache (via XDG_CACHE_HOME) are all derived from it, so setting one variable moves all three caches together.
  • Any of the four variables can still be set individually to override the derived default.

@pbrubeck pbrubeck changed the title Test sys.prefix for writability and unify the cache dirs Unified cache under sys.prefix Aug 27, 2026
@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Aug 27, 2026
Comment thread firedrake/configuration.py
Comment thread tests/firedrake/test_0init.py Outdated
@pbrubeck
pbrubeck requested a review from connorjward August 27, 2026 15:39
Comment thread firedrake/configuration.py
Comment thread firedrake/configuration.py Outdated
Comment thread tests/firedrake/test_configuration.py Outdated
Comment thread tests/firedrake/test_configuration.py Outdated
@pbrubeck
pbrubeck force-pushed the pbrubeck/unify-cache-dirs branch 2 times, most recently from a478fee to 20a77ee Compare August 28, 2026 10:35
@pbrubeck
pbrubeck requested a review from connorjward August 28, 2026 10:38
Comment thread tests/firedrake/test_0init.py
connorjward
connorjward previously approved these changes Aug 28, 2026
pbrubeck and others added 5 commits August 28, 2026 13:31
setup_cache_dirs() used $VIRTUAL_ENV, which is unset for a bare
venv/bin/python invocation and can point somewhere unwritable (e.g. a
system-wide install). Use sys.prefix instead, falling back to the
user's home directory when it is not writable.

Introduce FIREDRAKE_CACHE_DIR as the single root that PYOP2_CACHE_DIR,
FIREDRAKE_TSFC_KERNEL_CACHE_DIR and loopy's pytools-backed persistent
cache (via XDG_CACHE_HOME) are all derived from, so the three caches
live under one directory and one variable overrides all of them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
connorjward asked to minimise environment mutation, so setup_cache_dirs()
no longer sets FIREDRAKE_CACHE_DIR itself when it falls back to sys.prefix
or the home directory -- it only ever reads it. The derived-cache-dir
tests move into test_0init.py alongside the other cache-dir test, and gain
a fixture that clears the cache env vars after each test too, since
setup_cache_dirs() writes os.environ directly and monkeypatch's own undo
stack never sees those writes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRubJuLapd9jZw6iBPUxrL
Update the caching section for the sys.prefix-based default and the new
XDG_CACHE_HOME/loopy cache, and add guidance on running with an isolated
FIREDRAKE_CACHE_DIR plus the risk that firedrake-clean cannot see caches
left behind under a FIREDRAKE_CACHE_DIR that isn't set in the environment
it's run under.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRubJuLapd9jZw6iBPUxrL
monkeypatch.delenv() already snapshots each variable's pre-test value
and restores it automatically at teardown, regardless of what
setup_cache_dirs() writes to os.environ directly in between -- the
restore is unconditional, not a diff against the current value. The
second delenv() pass after yield was dead weight.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRubJuLapd9jZw6iBPUxrL
os.access(path, os.W_OK) reports writable for root regardless of the
file mode, so a chmod(0o555) directory doesn't actually simulate an
unwritable prefix when the suite runs as root (as CI does), and
setup_cache_dirs() picked the "unwritable" prefix instead of falling
back to home. Mock os.access directly for the path under test instead
of relying on real permission bits, which is deterministic for any
caller including root.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRubJuLapd9jZw6iBPUxrL
@pbrubeck
pbrubeck force-pushed the pbrubeck/unify-cache-dirs branch from 03e69d1 to 51d604e Compare August 28, 2026 12:33
@pbrubeck
pbrubeck changed the base branch from main to connorjward/merge-release August 28, 2026 12:33
@pbrubeck pbrubeck added the base:main Run this PR using a main (dev) build label Aug 28, 2026
Base automatically changed from connorjward/merge-release to main August 28, 2026 14:44
@pbrubeck
pbrubeck merged commit 779e07c into main Aug 28, 2026
7 of 15 checks passed
@pbrubeck
pbrubeck deleted the pbrubeck/unify-cache-dirs branch August 28, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base:main Run this PR using a main (dev) build LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants