Skip to content

Commit

Permalink
macOS use ~/.config/pip/pip.conf as well (pypa#4100)
Browse files Browse the repository at this point in the history
  • Loading branch information
atdaemon committed Jan 1, 2017
1 parent 5e242ad commit 60d5991
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ all users) configuration:
* On Unix the default configuration file is: :file:`$HOME/.config/pip/pip.conf`
which respects the ``XDG_CONFIG_HOME`` environment variable.
* On macOS the configuration file is
:file:`$HOME/Library/Application Support/pip/pip.conf`.
:file:`$HOME/Library/Application Support/pip/pip.conf`
if directory ``$HOME/Library/Application Support/pip`` exists
else :file:`$HOME/.config/pip/pip.conf`.
* On Windows the configuration file is :file:`%APPDATA%\\pip\\pip.ini`.

There are also a legacy per-user configuration file which is also respected,
Expand Down
8 changes: 8 additions & 0 deletions pip/utils/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def user_data_dir(appname, roaming=False):
Typical user data directories are:
macOS: ~/Library/Application Support/<AppName>
if it exists, else ~/.config/<AppName>
Unix: ~/.local/share/<AppName> # or in
$XDG_DATA_HOME, if defined
Win XP (not roaming): C:\Documents and Settings\<username>\ ...
Expand All @@ -93,6 +94,13 @@ def user_data_dir(appname, roaming=False):
path = os.path.join(
expanduser('~/Library/Application Support/'),
appname,
) if os.path.isdir(os.path.join(
expanduser('~/Library/Application Support/'),
appname,
)
) else os.path.join(
expanduser('~/.config/'),
appname,
)
else:
path = os.path.join(
Expand Down
16 changes: 12 additions & 4 deletions tests/unit/test_appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ def test_user_data_dir_osx(self, monkeypatch):
monkeypatch.setenv("HOME", "/home/test")
monkeypatch.setattr(sys, "platform", "darwin")

assert (appdirs.user_data_dir("pip") ==
"/home/test/Library/Application Support/pip")
if os.path.isdir('/home/test/Library/Application Support/'):
assert (appdirs.user_data_dir("pip") ==
"/home/test/Library/Application Support/pip")
else:
assert (appdirs.user_data_dir("pip") ==
"/home/test/.config/pip")

def test_user_data_dir_linux(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
Expand Down Expand Up @@ -262,8 +266,12 @@ def test_user_config_dir_osx(self, monkeypatch):
monkeypatch.setenv("HOME", "/home/test")
monkeypatch.setattr(sys, "platform", "darwin")

assert (appdirs.user_config_dir("pip") ==
"/home/test/Library/Application Support/pip")
if os.path.isdir('/home/test/Library/Application Support/'):
assert (appdirs.user_data_dir("pip") ==
"/home/test/Library/Application Support/pip")
else:
assert (appdirs.user_data_dir("pip") ==
"/home/test/.config/pip")

def test_user_config_dir_linux(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
Expand Down

0 comments on commit 60d5991

Please sign in to comment.