Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d5bf6e

Browse files
authored
Fix cache versioning when BLACK_CACHE_DIR is set (psf#3937)
1 parent a69bda3 commit 5d5bf6e

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
<!-- Changes to how Black can be configured -->
2626

27+
- Fix cache versioning logic when `BLACK_CACHE_DIR` is set (#3937)
28+
2729
### Packaging
2830

2931
<!-- Changes to how Black is packaged, such as dependency requirements -->

src/black/cache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def get_cache_dir() -> Path:
3636
repeated calls.
3737
"""
3838
# NOTE: Function mostly exists as a clean way to test getting the cache directory.
39-
default_cache_dir = user_cache_dir("black", version=__version__)
39+
default_cache_dir = user_cache_dir("black")
4040
cache_dir = Path(os.environ.get("BLACK_CACHE_DIR", default_cache_dir))
41+
cache_dir = cache_dir / __version__
4142
return cache_dir
4243

4344

tests/test_black.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,11 +1963,11 @@ def test_get_cache_dir(
19631963
# If BLACK_CACHE_DIR is not set, use user_cache_dir
19641964
monkeypatch.delenv("BLACK_CACHE_DIR", raising=False)
19651965
with patch_user_cache_dir:
1966-
assert get_cache_dir() == workspace1
1966+
assert get_cache_dir().parent == workspace1
19671967

19681968
# If it is set, use the path provided in the env var.
19691969
monkeypatch.setenv("BLACK_CACHE_DIR", str(workspace2))
1970-
assert get_cache_dir() == workspace2
1970+
assert get_cache_dir().parent == workspace2
19711971

19721972
def test_cache_broken_file(self) -> None:
19731973
mode = DEFAULT_MODE

0 commit comments

Comments
 (0)