Skip to content

Commit 80e46c9

Browse files
committed
chore: add a get_data_dir() function to core.dirs
This wraps `platformdirs.user_data_dir()`. It's going to be used as the place to store our global git hook. Changing the place of the global git hook is required to make the code testable. It is also going to fix the fact that having the global git hooks created in $HOME/.git/hooks was weird: for 99% of our users, $HOME is not a git repository.
1 parent c135c97 commit 80e46c9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ggshield/core/dirs.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from pathlib import Path
33

4-
from platformdirs import user_cache_dir, user_config_dir
4+
from platformdirs import user_cache_dir, user_config_dir, user_data_dir
55

66
from ggshield.utils.git_shell import NotAGitDirectory, get_git_root
77

@@ -34,6 +34,16 @@ def get_cache_dir() -> Path:
3434
return Path(user_cache_dir(appname=APPNAME, appauthor=APPAUTHOR))
3535

3636

37+
def get_data_dir() -> Path:
38+
try:
39+
# See tests/conftest.py for details
40+
return Path(os.environ["GG_DATA_DIR"])
41+
except KeyError:
42+
return Path(
43+
user_data_dir(appname=APPNAME, appauthor=APPAUTHOR)
44+
) # pragma: no cover
45+
46+
3747
def get_project_root_dir(path: Path) -> Path:
3848
"""
3949
Returns the source basedir required to find file within filesystem.

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def do_not_use_real_user_dirs(monkeypatch, tmp_path):
8686
"""
8787
monkeypatch.setenv("GG_CONFIG_DIR", str(tmp_path / "config"))
8888
monkeypatch.setenv("GG_CACHE_DIR", str(tmp_path / "cache"))
89+
monkeypatch.setenv("GG_DATA_DIR", str(tmp_path / "data"))
8990
monkeypatch.setenv("GG_USER_HOME_DIR", str(tmp_path / "home"))
9091

9192

0 commit comments

Comments
 (0)