Fix cache versioning when BLACK_CACHE_DIR is set (#3937)
This commit is contained in:
parent
a69bda3b9b
commit
5d5bf6e087
@ -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 -->
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user