From 2ccc5c055db7247b4529569e9ddf3185b538060d Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 20 Dec 2019 14:36:30 +0800 Subject: [PATCH] Match site_config_dirs for empty XDG_CONFIG_DIRS --- src/pip/_vendor/appdirs.py | 2 +- tests/unit/test_appdirs.py | 8 ++++++++ tools/automation/vendoring/patches/appdirs.patch | 9 +++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/pip/_vendor/appdirs.py b/src/pip/_vendor/appdirs.py index 92b80251e..e9ff1aa4f 100644 --- a/src/pip/_vendor/appdirs.py +++ b/src/pip/_vendor/appdirs.py @@ -247,7 +247,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) # XDG default for $XDG_CONFIG_DIRS # only first, if multipath is False path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg') - pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] + pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) if x] if appname: if version: appname = os.path.join(appname, version) diff --git a/tests/unit/test_appdirs.py b/tests/unit/test_appdirs.py index 1a0146417..402d0db31 100644 --- a/tests/unit/test_appdirs.py +++ b/tests/unit/test_appdirs.py @@ -138,6 +138,14 @@ class TestSiteConfigDirs: '/etc' ] + def test_site_config_dirs_linux_empty(self, monkeypatch): + monkeypatch.setattr(_appdirs, "system", "linux2") + monkeypatch.setattr(os, "path", posixpath) + monkeypatch.setattr(os, "pathsep", ':') + monkeypatch.setenv("XDG_CONFIG_DIRS", "") + monkeypatch.setattr(sys, "platform", "linux2") + assert appdirs.site_config_dirs("pip") == ['/etc'] + class TestUserDataDir: diff --git a/tools/automation/vendoring/patches/appdirs.patch b/tools/automation/vendoring/patches/appdirs.patch index 136f34b48..6c6f37b45 100644 --- a/tools/automation/vendoring/patches/appdirs.patch +++ b/tools/automation/vendoring/patches/appdirs.patch @@ -1,5 +1,5 @@ diff --git a/src/pip/_vendor/appdirs.py b/src/pip/_vendor/appdirs.py -index ae67001a..92b80251 100644 +index ae67001a..e9ff1aa4 100644 --- a/src/pip/_vendor/appdirs.py +++ b/src/pip/_vendor/appdirs.py @@ -64,7 +64,7 @@ def user_data_dir(appname=None, appauthor=None, version=None, roaming=False): @@ -40,7 +40,12 @@ index ae67001a..92b80251 100644 def site_config_dir(appname=None, appauthor=None, version=None, multipath=False): r"""Return full path to the user-shared data dir for this application. -@@ -245,7 +251,9 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) +@@ -241,11 +247,13 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) + # XDG default for $XDG_CONFIG_DIRS + # only first, if multipath is False + path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg') +- pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] ++ pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) if x] if appname: if version: appname = os.path.join(appname, version)