Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/platformdirs/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def site_data_path(self) -> Path:
""":returns: data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
return self._first_item_as_path_if_multipath(self.site_data_dir)

@property
def site_config_path(self) -> Path:
""":returns: config path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
return self._first_item_as_path_if_multipath(self.site_config_dir)

@property
def user_config_dir(self) -> str:
""":returns: config directory tied to the user, same as `user_data_dir`"""
Expand Down
32 changes: 32 additions & 0 deletions tests/test_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def test_macos(mocker: MockerFixture, params: dict[str, Any], func: str) -> None
"site_runtime_dir",
"site_cache_path",
"site_data_path",
"site_config_path",
],
)
@pytest.mark.parametrize("multipath", [pytest.param(True, id="multipath"), pytest.param(False, id="singlepath")])
Expand Down Expand Up @@ -143,6 +144,7 @@ def test_macos_homebrew(mocker: MockerFixture, params: dict[str, Any], multipath
expected_path_map = {
"site_cache_path": Path(f"{prefix['homebrew_prefix']}/var/cache{suffix}"),
"site_data_path": Path(f"{prefix['homebrew_prefix']}/share{suffix}"),
"site_config_path": Path(f"{prefix['homebrew_prefix']}/share{suffix}"),
}
expected_map = {
"site_data_dir": f"{prefix['homebrew_prefix']}/share{suffix}",
Expand Down Expand Up @@ -376,3 +378,33 @@ def test_no_xdg_site_dirs_leak(monkeypatch: pytest.MonkeyPatch) -> None:
assert config_value in config_dirs
assert config_value not in data_dirs
assert data_value not in config_dirs


@pytest.mark.usefixtures("_clear_xdg_env")
def test_macos_site_runtime_path(mocker: MockerFixture) -> None:
py_version = sys.version_info
builtin_py_prefix = (
"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework"
f"/Versions/{py_version.major}.{py_version.minor}"
)
mocker.patch("sys.prefix", builtin_py_prefix)
result = MacOS(appname="foo").site_runtime_path
home = str(Path("~").expanduser())
assert result == Path(f"{home}/Library/Caches/TemporaryItems/foo")


@pytest.mark.usefixtures("_clear_xdg_env")
def test_macos_ensure_exists_preexisting_dir(mocker: MockerFixture, tmp_path: Path) -> None:
py_version = sys.version_info
builtin_py_prefix = (
"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework"
f"/Versions/{py_version.major}.{py_version.minor}"
)
mocker.patch("sys.prefix", builtin_py_prefix)
mocker.patch("platformdirs.macos.os.path.expanduser", lambda p: str(tmp_path / p.lstrip("~/")))
dirs = MacOS(appname="foo", ensure_exists=True)
first = dirs.user_data_dir
assert Path(first).exists()
# Calling again with an already-existing directory must not raise.
second = dirs.user_data_dir
assert first == second