Skip to content

Commit

Permalink
Fix cache versioning when BLACK_CACHE_DIR is set (#3937)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Oct 10, 2023
1 parent a69bda3 commit 5d5bf6e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
3 changes: 2 additions & 1 deletion src/black/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d5bf6e

Please sign in to comment.