Skip to content

Commit 4fcbe17

Browse files
Fix macos user_site_dir (#137)
1 parent 8725c9c commit 4fcbe17

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
platformdirs Changelog
22
======================
33

4+
platformdirs 3.0.0 (2023-02-06)
5+
-------------------------------
6+
- **BREAKING** Changed the config directory on macOS to point to ``*/Library/Application Support``
7+
- macOS: remove erroneous trailing slash from ``user_config_dir`` and ``user_data_dir``
8+
49
platformdirs 2.6.2 (2022-12-28)
510
-------------------------------
611
- Fix missing ``typing-extensions`` dependency.

src/platformdirs/macos.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MacOS(PlatformDirsABC):
1616
@property
1717
def user_data_dir(self) -> str:
1818
""":return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
19-
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support/"))
19+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support"))
2020

2121
@property
2222
def site_data_dir(self) -> str:
@@ -25,13 +25,13 @@ def site_data_dir(self) -> str:
2525

2626
@property
2727
def user_config_dir(self) -> str:
28-
""":return: config directory tied to the user, e.g. ``~/Library/Preferences/$appname/$version``"""
29-
return self._append_app_name_and_version(os.path.expanduser("~/Library/Preferences/"))
28+
""":return: config directory tied to the user, same as `user_data_dir`"""
29+
return self.user_data_dir
3030

3131
@property
3232
def site_config_dir(self) -> str:
33-
""":return: config directory shared by the users, e.g. ``/Library/Preferences/$appname``"""
34-
return self._append_app_name_and_version("/Library/Preferences")
33+
""":return: config directory shared by the users, same as `site_data_dir`"""
34+
return self.site_data_dir
3535

3636
@property
3737
def user_cache_dir(self) -> str:

tests/test_comp_with_appdirs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ def test_compatibility(params: dict[str, Any], func: str) -> None:
5757
if sys.platform == "darwin":
5858
msg = { # pragma: no cover
5959
"user_log_dir": "without appname produces NoneType error",
60-
"site_config_dir": "ignores the version argument",
61-
"user_config_dir": "uses Library/Preferences instead Application Support",
6260
}
6361
if func in msg: # pragma: no cover
6462
pytest.skip(f"`appdirs.{func}` {msg[func]} on macOS") # pragma: no cover
@@ -72,4 +70,4 @@ def test_compatibility(params: dict[str, Any], func: str) -> None:
7270
new = getattr(platformdirs, func)(*params)
7371
old = getattr(appdirs, func)(*params)
7472

75-
assert new == old
73+
assert new == old.rstrip("/")

tests/test_macos.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import annotations
2+
3+
import os
4+
from typing import Any
5+
6+
import pytest
7+
8+
from platformdirs.macos import MacOS
9+
10+
11+
@pytest.mark.parametrize(
12+
"params",
13+
[
14+
pytest.param({}, id="no_args"),
15+
pytest.param({"appname": "foo"}, id="app_name"),
16+
pytest.param({"appname": "foo", "version": "v1.0"}, id="app_name_version"),
17+
],
18+
)
19+
def test_macos(params: dict[str, Any], func: str) -> None:
20+
result = getattr(MacOS(**params), func)
21+
22+
home = os.path.expanduser("~")
23+
suffix_elements = tuple(params[i] for i in ("appname", "version") if i in params)
24+
suffix = os.sep.join(("",) + suffix_elements) if suffix_elements else ""
25+
26+
expected_map = {
27+
"user_data_dir": f"{home}/Library/Application Support{suffix}",
28+
"site_data_dir": f"/Library/Application Support{suffix}",
29+
"user_config_dir": f"{home}/Library/Application Support{suffix}",
30+
"site_config_dir": f"/Library/Application Support{suffix}",
31+
"user_cache_dir": f"{home}/Library/Caches{suffix}",
32+
"user_state_dir": f"{home}/Library/Application Support{suffix}",
33+
"user_log_dir": f"{home}/Library/Logs{suffix}",
34+
"user_documents_dir": f"{home}/Documents",
35+
"user_runtime_dir": f"{home}/Library/Caches/TemporaryItems{suffix}",
36+
}
37+
expected = expected_map[func]
38+
39+
assert result == expected

0 commit comments

Comments
 (0)