fix(fingerprint): treat TMPDIR as strict API and fail (Issue #7877) #7891
+159
−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.
Fixes #7877 and follows up on feedback from
#7890.Context
In
#7890it was introduced an automatic creation of theTMPDIRdirectory in_TempCacheDirso thatdatasetsdoes not silently fall back to/tmpwhenTMPDIRpoints to a non‑existent path. This addressed the original “tempfilesilently ignores TMPDIR” issue in#7877.During review, it was pointed out by @stas00 (see review comment) that if the code treats
TMPDIRas part of the public API, then failures to use it should fail loudly, not just emit warnings, because warnings are easy to miss in complex multi‑GPU setups.This PR implements that stricter behaviour.
What this PR changes
_TempCacheDirbehaviour Insrc/datasets/fingerprint.py:Continue to:
TMPDIRfrom the environmenttempfile.mkdtemp(...)soTMPDIRis honoured even iftempfile.gettempdir()was already cachedNew behaviour (in response to review on
#7890):TMPDIRis set, but the directory cannot be created, we now re‑raise anOSErrorwith a clear, actionable message:TMPDIRis set but points to something that is not a directory, we also raiseOSErrorwith guidance:TMPDIRis not set, behaviour is unchanged: we passdir=Noneand lettempfileuse the system default temp directory.This aligns with the @stas00’s suggestion that TMPDIR should be treated as a strict API contract: if the user chooses a TMPDIR, we either use it or clearly fail, rather than silently falling back.
Tests
In
tests/test_fingerprint.py:Updated tests that previously expected warning‑and‑fallback to now expect hard failures:
test_temp_cache_dir_tmpdir_creation_failureunittest.mock.patchto forceos.makedirsto raiseOSError("Permission denied")_TempCacheDir()raisesOSErrorand that the message contains both “TMPDIR is set to” and “could not be created”test_temp_cache_dir_tmpdir_not_directoryTMPDIRto a regular file and asserts that_TempCacheDir()raisesOSErrorwith a message mentioning “is not a directory”Left the positive‑path tests in place:
test_temp_cache_dir_with_tmpdir_nonexistent– verifies that a non‑existentTMPDIRis created and usedtest_temp_cache_dir_with_tmpdir_existing– verifies that an existingTMPDIRdirectory is used as the base for the temp cache dirtest_temp_cache_dir_without_tmpdir– verifies behaviour whenTMPDIRis not set (default temp directory)Kept the earlier fix to
test_fingerprint_in_multiprocessing, which now usesPool.mapand asserts that fingerprints are stable across processes.Rationale
TMPDIRas part of the API for cache placement means:/tmppartitions.#7890that “warnings are very easy to miss in complex applications where there are already dozens of warnings multiplied by multiple GPU processes”.Testing
pytest tests/test_fingerprint.pymake style