Skip to content

Commit

Permalink
Fix macos user_site_dir (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann authored Feb 6, 2023
1 parent 8725c9c commit 4fcbe17
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 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 3.0.0 (2023-02-06)
-------------------------------
- **BREAKING** Changed the config directory on macOS to point to ``*/Library/Application Support``
- macOS: remove erroneous trailing slash from ``user_config_dir`` and ``user_data_dir``

platformdirs 2.6.2 (2022-12-28)
-------------------------------
- Fix missing ``typing-extensions`` dependency.
Expand Down
10 changes: 5 additions & 5 deletions src/platformdirs/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MacOS(PlatformDirsABC):
@property
def user_data_dir(self) -> str:
""":return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support/"))
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support"))

@property
def site_data_dir(self) -> str:
Expand All @@ -25,13 +25,13 @@ def site_data_dir(self) -> str:

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

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

@property
def user_cache_dir(self) -> str:
Expand Down
4 changes: 1 addition & 3 deletions tests/test_comp_with_appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def test_compatibility(params: dict[str, Any], func: str) -> None:
if sys.platform == "darwin":
msg = { # pragma: no cover
"user_log_dir": "without appname produces NoneType error",
"site_config_dir": "ignores the version argument",
"user_config_dir": "uses Library/Preferences instead Application Support",
}
if func in msg: # pragma: no cover
pytest.skip(f"`appdirs.{func}` {msg[func]} on macOS") # pragma: no cover
Expand All @@ -72,4 +70,4 @@ def test_compatibility(params: dict[str, Any], func: str) -> None:
new = getattr(platformdirs, func)(*params)
old = getattr(appdirs, func)(*params)

assert new == old
assert new == old.rstrip("/")
39 changes: 39 additions & 0 deletions tests/test_macos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations

import os
from typing import Any

import pytest

from platformdirs.macos import MacOS


@pytest.mark.parametrize(
"params",
[
pytest.param({}, id="no_args"),
pytest.param({"appname": "foo"}, id="app_name"),
pytest.param({"appname": "foo", "version": "v1.0"}, id="app_name_version"),
],
)
def test_macos(params: dict[str, Any], func: str) -> None:
result = getattr(MacOS(**params), func)

home = os.path.expanduser("~")
suffix_elements = tuple(params[i] for i in ("appname", "version") if i in params)
suffix = os.sep.join(("",) + suffix_elements) if suffix_elements else ""

expected_map = {
"user_data_dir": f"{home}/Library/Application Support{suffix}",
"site_data_dir": f"/Library/Application Support{suffix}",
"user_config_dir": f"{home}/Library/Application Support{suffix}",
"site_config_dir": f"/Library/Application Support{suffix}",
"user_cache_dir": f"{home}/Library/Caches{suffix}",
"user_state_dir": f"{home}/Library/Application Support{suffix}",
"user_log_dir": f"{home}/Library/Logs{suffix}",
"user_documents_dir": f"{home}/Documents",
"user_runtime_dir": f"{home}/Library/Caches/TemporaryItems{suffix}",
}
expected = expected_map[func]

assert result == expected

0 comments on commit 4fcbe17

Please sign in to comment.