Skip to content

Commit d97fd0b

Browse files
authored
Handle multiple paths in appdirs.site_config_dirs on MacOS (#13280)
This occurs when using Homebrew, for example.
1 parent 147dc0b commit d97fd0b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

news/12903.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support multiple global configuration paths returned by ``platformdirs`` on MacOS.

src/pip/_internal/utils/appdirs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def user_config_dir(appname: str, roaming: bool = True) -> str:
4242
# see <https://github.com/pypa/pip/issues/1733>
4343
def site_config_dirs(appname: str) -> List[str]:
4444
if sys.platform == "darwin":
45-
return [_appdirs.site_data_dir(appname, appauthor=False, multipath=True)]
45+
dirval = _appdirs.site_data_dir(appname, appauthor=False, multipath=True)
46+
return dirval.split(os.pathsep)
4647

4748
dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
4849
if sys.platform == "win32":

tests/unit/test_appdirs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ def test_site_config_dirs_osx(self, monkeypatch: pytest.MonkeyPatch) -> None:
109109
"/Library/Application Support/pip",
110110
]
111111

112+
@pytest.mark.skipif(sys.platform != "darwin", reason="MacOS-only test")
113+
def test_site_config_dirs_osx_homebrew(
114+
self, monkeypatch: pytest.MonkeyPatch
115+
) -> None:
116+
monkeypatch.setattr(sys, "prefix", "/opt/homebrew/")
117+
118+
assert appdirs.site_config_dirs("pip") == [
119+
"/opt/homebrew/share/pip",
120+
"/Library/Application Support/pip",
121+
]
122+
112123
@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only test")
113124
def test_site_config_dirs_linux(self, monkeypatch: pytest.MonkeyPatch) -> None:
114125
monkeypatch.delenv("XDG_CONFIG_DIRS", raising=False)

0 commit comments

Comments
 (0)