cacheprovider: simplify cache directory creation#14121
Merged
RonnyPfannschmidt merged 3 commits intopytest-dev:mainfrom Jan 29, 2026
Merged
cacheprovider: simplify cache directory creation#14121RonnyPfannschmidt merged 3 commits intopytest-dev:mainfrom
RonnyPfannschmidt merged 3 commits intopytest-dev:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the cache directory creation logic in cacheprovider.py by extracting it into a dedicated _make_cachedir function, simplifying the code structure while maintaining atomic creation and proper race condition handling.
Changes:
- Consolidated file contents (README.md, .gitignore, CACHEDIR.TAG) into a single
CACHEDIR_FILESdictionary with bytes values - Extracted cache directory creation logic into a new
_make_cachedirfunction - Replaced
tempfile.TemporaryDirectorycontext manager withtempfile.mkdtemp+shutil.rmtreefor simpler cleanup
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b2505ff to
212c1e1
Compare
bluetech
reviewed
Jan 18, 2026
bluetech
approved these changes
Jan 18, 2026
Member
bluetech
left a comment
There was a problem hiding this comment.
OK, LGTM.
The except BaseException case is not covered, would be nice to add a test for it but OK if it's too hard.
nicoddemus
approved these changes
Jan 25, 2026
Refactor _ensure_cache_dir_and_supporting_files to use a dedicated _make_cachedir function that atomically creates the cache directory with its supporting files (README.md, .gitignore, CACHEDIR.TAG). - Store all file contents as bytes in CACHEDIR_FILES dict - Use tempfile.mkdtemp + shutil.rmtree instead of TemporaryDirectory - Simplify cleanup logic for race conditions Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Opus 4 <claude@anthropic.com>
Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Opus 4.5 <claude@anthropic.com>
Use a single finally block instead of duplicating cleanup logic in separate except blocks. The finally block always runs, ensuring cleanup whether the operation succeeds (rename moves dir away, rmtree is no-op), fails with a race condition (ENOTEMPTY/EEXIST), or any other exception. Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com> Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Opus 4.5 <claude@anthropic.com>
d23dfb6 to
f499184
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactor
_ensure_cache_dir_and_supporting_filesto use a dedicated_make_cachedirfunction that atomically creates the cache directory with its supporting files (README.md, .gitignore, CACHEDIR.TAG).CACHEDIR_FILESdicttempfile.mkdtemp+shutil.rmtreeinstead ofTemporaryDirectory