Skip to content

Commit

Permalink
Change user_log_dir to point to user_state_dir on Linux per the XDG s…
Browse files Browse the repository at this point in the history
…pec (#108)

Fixes #106
  • Loading branch information
lordwelch authored Dec 7, 2022
1 parent 1992217 commit 1433ba9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
platformdirs Changelog
======================

platformdirs 2.6.0 (2022-12-06)
-------------------------------
- **BREAKING** Correct the log directory on Linux/Unix from
XDG_CACHE_HOME to XDG_STATE_HOME per the XDG spec

platformdirs 2.5.4 (2022-11-12)
-------------------------------
- Fix licesing metadata
Expand Down
4 changes: 2 additions & 2 deletions src/platformdirs/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def user_state_dir(self) -> str:
@property
def user_log_dir(self) -> str:
"""
:return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``log`` in it
:return: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in it
"""
path = self.user_cache_dir
path = self.user_state_dir
if self.opinion:
path = os.path.join(path, "log")
return path
Expand Down
6 changes: 6 additions & 0 deletions tests/test_comp_with_appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def test_compatibility(params: dict[str, Any], func: str) -> None:
}
if func in msg: # pragma: no cover
pytest.skip(f"`appdirs.{func}` {msg[func]} on macOS") # pragma: no cover
if sys.platform == "linux":
msg = { # pragma: no cover
"user_log_dir": "Uses XDG_STATE_DIR instead of appdirs.user_data_dir per the XDG spec",
}
if func in msg: # pragma: no cover
pytest.skip(f"`appdirs.{func}` {msg[func]} on Linux") # pragma: no cover

new = getattr(platformdirs, func)(*params)
old = getattr(appdirs, func)(*params)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _func_to_path(func: str) -> XDGVariable | None:
"site_config_dir": XDGVariable("XDG_CONFIG_DIRS", "/etc/xdg"),
"user_cache_dir": XDGVariable("XDG_CACHE_HOME", "~/.cache"),
"user_state_dir": XDGVariable("XDG_STATE_HOME", "~/.local/state"),
"user_log_dir": XDGVariable("XDG_CACHE_HOME", "~/.cache"),
"user_log_dir": XDGVariable("XDG_STATE_HOME", "~/.local/state"),
"user_runtime_dir": XDGVariable("XDG_RUNTIME_DIR", "/run/user/1234"),
}
return mapping.get(func)
Expand Down

0 comments on commit 1433ba9

Please sign in to comment.