Skip to content

fix(paths): prefer SCRATCH, TMPDIR, MNE_DATA and platform cache over cwd for the default cache directory - #435

Merged
bruAristimunha merged 4 commits into
eegdash:developfrom
cpruijsen:fix/issue-400-5de90e06
Nov 18, 2026
Merged

bruAristimunha merged 4 commits into
eegdash:developfrom
cpruijsen:fix/issue-400-5de90e06

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Closes #400

Description

get_default_cache_dir() in eegdash/paths.py no longer defaults to ./.eegdash_cache. It now resolves in the order proposed in the issue:

  1. EEGDASH_CACHE_DIR (unchanged)
  2. $SCRATCH/eegdash, when $SCRATCH is an existing, writable directory
  3. $TMPDIR/eegdash, when $TMPDIR is an existing, writable directory
  4. MNE_DATA (unchanged)
  5. platformdirs.user_cache_dir("eegdash", appauthor=False), created on first use
  6. ./.eegdash_cache, as the last resort (still created best-effort)

Before, MNE_DATA was read only when the mkdir in the working directory failed. On a cluster the working directory is usually on a filesystem with an inode quota, and array jobs started from one directory all share one cache.

The resolved path is logged once per process at INFO.

platformdirs is now a declared dependency in pyproject.toml. It was already installed through mne and pooch, but eegdash.paths now imports it directly. The tutorial plot_42_features_to_sklearn.py said the default cache is relative to the working directory, so I changed that sentence.

Type of change

Bug fix

Testing performed

tests/unit_tests/test_paths.py covers each step, a missing or unwritable SCRATCH/TMPDIR, the full order, and the log-once behaviour. 12 of its 14 tests fail on the previous implementation and all pass with this change. The 2 that pass on both are the unchanged EEGDASH_CACHE_DIR cases.

Judgement calls

  • $SCRATCH and $TMPDIR get an eegdash subdirectory, so the cache does not mix with other files in shared space. The issue text uses the root directly. That is a one-line change if you prefer it.
  • $SCRATCH gets the same exists-and-writable check as $TMPDIR, although the issue says only "if set". With the check, a stale $SCRATCH falls through to the next step instead of giving an unusable path.
  • With no configuration, the default is now $TMPDIR/eegdash when TMPDIR is set. macOS always sets TMPDIR to a per-user directory that the OS can purge, and many Slurm sites set it to a job-local directory. If you want TMPDIR below MNE_DATA and the platform cache, I can move it.
  • There is no CHANGELOG entry. I can add one under Unreleased if you want it.

cpruijsen and others added 4 commits October 9, 2026 03:04
…p TMPDIR

- An existing ./.eegdash_cache (the previous default) is used before the new
  locations, so upgrading does not download every dataset again.
- TMPDIR is purged by macOS and wiped after a Slurm job, and placed before
  MNE_DATA it overrode a user's explicit MNE_DATA (macOS always sets it).
  After the platform cache it would never be reached, so it is dropped.
- Stale ./.eegdash_cache defaults in corpus.py (docstring, --cache-dir help)
  and base.py; CHANGELOG entry.
- test_paths.py: every test runs in an empty working directory; one test per
  step (8 tests).
@bruAristimunha

Copy link
Copy Markdown
Collaborator

Thanks @cpruijsen, nice tests and clear judgement calls. I merged develop and pushed c3c68f0 with two changes to the order, following your own notes:

  • An existing ./.eegdash_cache (the previous default) is used right after EEGDASH_CACHE_DIR, so upgrading does not download every cached dataset again.
  • TMPDIR is dropped: before MNE_DATA it overrode an explicit MNE_DATA (macOS always sets TMPDIR) with a directory macOS purges and Slurm wipes after each job; after the platform cache it would never be reached.
  • The stale ./.eegdash_cache defaults in corpus.py and base.py, a CHANGELOG entry, and test_paths.py reworked so every test runs in an empty working directory (one test per step).

@bruAristimunha
bruAristimunha merged commit a47e2bb into eegdash:develop Nov 18, 2026
3 checks passed
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.

Cache directory default is a footgun on shared filesystems

2 participants