Fix: Auto-create TMPDIR directory when it doesn't exist (Issue #7877) #7890
+153
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Auto-create TMPDIR directory when it doesn't exist
Fixes #7877
Description
This PR fixes issue #7877 by implementing automatic creation of the
TMPDIRdirectory when it is set but doesn't exist. Previously,tempfile.mkdtemp()would silently ignoreTMPDIRand fall back to/tmpif the specified directory didn't exist, causing confusion for users experiencing "No space left on device" errors.Problem
When users set
TMPDIRto a non-existent directory (e.g.,export TMPDIR=/some/big/storage), Python'stempfilemodule silently ignores it and falls back to the default temporary directory (/tmp). This leads to:TMPDIRSolution
The fix automatically creates the
TMPDIRdirectory if it is set but doesn't exist, ensuring that:TMPDIRsettings are respectedtempfile.gettempdir()was already called and cachedChanges
Implementation (
src/datasets/fingerprint.py)_TempCacheDir.__init__()to check ifTMPDIRenvironment variable is setos.makedirs()dirparameter totempfile.mkdtemp()to ensure TMPDIR is respectedTests (
tests/test_fingerprint.py)Added comprehensive test coverage:
test_temp_cache_dir_with_tmpdir_nonexistent: Tests auto-creation of non-existent TMPDIRtest_temp_cache_dir_with_tmpdir_existing: Tests behaviour when TMPDIR already existstest_temp_cache_dir_without_tmpdir: Tests default behaviour when TMPDIR is not settest_temp_cache_dir_tmpdir_creation_failure: Tests error handling when directory creation failsAlso fixed incomplete
test_fingerprint_in_multiprocessingtest that was missing implementation.Testing
make styleExample Usage
Before this fix:
After this fix:
Type of Change
Note: This implementation follows the approach suggested in the issue, automatically creating the TMPDIR directory when it doesn't exist, which provides the best user experience whilst maintaining security (we only create directories explicitly specified by the user via environment variable).