Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration files may now also be stored under sys.prefix #6268

Merged
merged 8 commits into from
Mar 7, 2019
1 change: 1 addition & 0 deletions news/5060.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Configuration files may now also be stored under ``sys.prefix``
5 changes: 5 additions & 0 deletions src/pip/_internal/utils/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ def site_config_dirs(appname):
# always look in /etc directly as well
pathlist.append('/etc')

# allow configuration in sys.prefix without any appname
# but put it first so that it is not preferred for "pip config set"
# see <https://github.com/pypa/pip/issues/5060>
pathlist.insert(0, sys.prefix)
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved

return pathlist


Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def _get_win_folder(base):
monkeypatch.setattr(appdirs, "WINDOWS", True)
monkeypatch.setattr(os, "path", ntpath)

assert appdirs.site_config_dirs("pip") == ["C:\\ProgramData\\pip"]
assert appdirs.site_config_dirs("pip") == [sys.prefix,
"C:\\ProgramData\\pip"]
assert _get_win_folder.calls == [pretend.call("CSIDL_COMMON_APPDATA")]

def test_site_config_dirs_osx(self, monkeypatch):
Expand All @@ -110,7 +111,7 @@ def test_site_config_dirs_osx(self, monkeypatch):
monkeypatch.setattr(sys, "platform", "darwin")

assert appdirs.site_config_dirs("pip") == \
["/Library/Application Support/pip"]
[sys.prefix, "/Library/Application Support/pip"]

def test_site_config_dirs_linux(self, monkeypatch):
monkeypatch.setattr(appdirs, "WINDOWS", False)
Expand All @@ -119,8 +120,9 @@ def test_site_config_dirs_linux(self, monkeypatch):
monkeypatch.setattr(sys, "platform", "linux2")

assert appdirs.site_config_dirs("pip") == [
sys.prefix,
'/etc/xdg/pip',
'/etc'
'/etc',
]

def test_site_config_dirs_linux_override(self, monkeypatch):
Expand All @@ -131,10 +133,11 @@ def test_site_config_dirs_linux_override(self, monkeypatch):
monkeypatch.setattr(sys, "platform", "linux2")

assert appdirs.site_config_dirs("pip") == [
sys.prefix,
'/spam/pip',
'/etc/pip',
'/etc/xdg/pip',
'/etc'
'/etc',
]


Expand Down