Fix cache versioning when BLACK_CACHE_DIR is set (#3937)

This commit is contained in:
Shantanu 2023-10-09 18:44:36 -07:00 committed by GitHub
parent a69bda3b9b
commit 5d5bf6e087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View File

@ -24,6 +24,8 @@
<!-- Changes to how Black can be configured -->
- Fix cache versioning logic when `BLACK_CACHE_DIR` is set (#3937)
### Packaging
<!-- Changes to how Black is packaged, such as dependency requirements -->

View File

@ -36,8 +36,9 @@ def get_cache_dir() -> Path:
repeated calls.
"""
# NOTE: Function mostly exists as a clean way to test getting the cache directory.
default_cache_dir = user_cache_dir("black", version=__version__)
default_cache_dir = user_cache_dir("black")
cache_dir = Path(os.environ.get("BLACK_CACHE_DIR", default_cache_dir))
cache_dir = cache_dir / __version__
return cache_dir

View File

@ -1963,11 +1963,11 @@ def test_get_cache_dir(
# If BLACK_CACHE_DIR is not set, use user_cache_dir
monkeypatch.delenv("BLACK_CACHE_DIR", raising=False)
with patch_user_cache_dir:
assert get_cache_dir() == workspace1
assert get_cache_dir().parent == workspace1
# If it is set, use the path provided in the env var.
monkeypatch.setenv("BLACK_CACHE_DIR", str(workspace2))
assert get_cache_dir() == workspace2
assert get_cache_dir().parent == workspace2
def test_cache_broken_file(self) -> None:
mode = DEFAULT_MODE