diff options
author | Dominic Davis-Foster <dominic@davis-foster.co.uk> | 2021-07-24 23:18:35 +0100 |
---|---|---|
committer | Dominic Davis-Foster <dominic@davis-foster.co.uk> | 2021-09-30 15:34:35 +0100 |
commit | ae6cf66c79734924544c4d5312dc0ca6072f324b (patch) | |
tree | 23bda98066ab7cb23765d0452c194e2fd581fb86 /tools | |
parent | 0225b2a55ed60cddc22bd6a735dad09f8174499f (diff) | |
download | pip-ae6cf66c79734924544c4d5312dc0ca6072f324b.tar.gz |
Switch from appdirs to platformdirs
Diffstat (limited to 'tools')
-rw-r--r-- | tools/vendoring/patches/appdirs.patch | 115 | ||||
-rw-r--r-- | tools/vendoring/patches/pkg_resources.patch | 22 | ||||
-rw-r--r-- | tools/vendoring/patches/platformdirs.patch | 20 |
3 files changed, 42 insertions, 115 deletions
diff --git a/tools/vendoring/patches/appdirs.patch b/tools/vendoring/patches/appdirs.patch deleted file mode 100644 index 69afd3e86..000000000 --- a/tools/vendoring/patches/appdirs.patch +++ /dev/null @@ -1,115 +0,0 @@ -diff --git a/src/pip/_vendor/appdirs.py b/src/pip/_vendor/appdirs.py -index ae67001a..3a52b758 100644 ---- a/src/pip/_vendor/appdirs.py -+++ b/src/pip/_vendor/appdirs.py -@@ -37,6 +37,10 @@ if sys.platform.startswith('java'): - # are actually checked for and the rest of the module expects - # *sys.platform* style strings. - system = 'linux2' -+elif sys.platform == 'cli' and os.name == 'nt': -+ # Detect Windows in IronPython to match pip._internal.utils.compat.WINDOWS -+ # Discussion: <https://github.com/pypa/pip/pull/7501> -+ system = 'win32' - else: - system = sys.platform - -@@ -64,7 +68,7 @@ def user_data_dir(appname=None, appauthor=None, version=None, roaming=False): - for a discussion of issues. - - Typical user data directories are: -- Mac OS X: ~/Library/Application Support/<AppName> -+ Mac OS X: ~/Library/Application Support/<AppName> # or ~/.config/<AppName>, if the other does not exist - Unix: ~/.local/share/<AppName> # or in $XDG_DATA_HOME, if defined - Win XP (not roaming): C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName> - Win XP (roaming): C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName> -@@ -150,7 +154,7 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False): - if appname: - if version: - appname = os.path.join(appname, version) -- pathlist = [os.sep.join([x, appname]) for x in pathlist] -+ pathlist = [os.path.join(x, appname) for x in pathlist] - - if multipath: - path = os.pathsep.join(pathlist) -@@ -203,6 +203,8 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False): - return path - - -+# for the discussion regarding site_config_dir locations -+# see <https://github.com/pypa/pip/issues/1733> - 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. - -@@ -238,14 +244,15 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) - if appname and version: - path = os.path.join(path, version) - else: -- # XDG default for $XDG_CONFIG_DIRS -+ # XDG default for $XDG_CONFIG_DIRS (missing or empty) -+ # see <https://github.com/pypa/pip/pull/7501#discussion_r360624829> - # 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)] -+ path = os.getenv('XDG_CONFIG_DIRS') or '/etc/xdg' -+ 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) -- pathlist = [os.sep.join([x, appname]) for x in pathlist] -+ pathlist = [os.path.join(x, appname) for x in pathlist] - - if multipath: - path = os.pathsep.join(pathlist) -@@ -291,6 +300,10 @@ def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True): - if appauthor is None: - appauthor = appname - path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA")) -+ # When using Python 2, return paths as bytes on Windows like we do on -+ # other operating systems. See helper function docs for more details. -+ if not PY3 and isinstance(path, unicode): -+ path = _win_path_to_bytes(path) - if appname: - if appauthor is not False: - path = os.path.join(path, appauthor, appname) -@@ -557,18 +570,32 @@ def _get_win_folder_with_jna(csidl_name): - - if system == "win32": - try: -- import win32com.shell -- _get_win_folder = _get_win_folder_with_pywin32 -+ from ctypes import windll -+ _get_win_folder = _get_win_folder_with_ctypes - except ImportError: - try: -- from ctypes import windll -- _get_win_folder = _get_win_folder_with_ctypes -+ import com.sun.jna -+ _get_win_folder = _get_win_folder_with_jna - except ImportError: -- try: -- import com.sun.jna -- _get_win_folder = _get_win_folder_with_jna -- except ImportError: -- _get_win_folder = _get_win_folder_from_registry -+ _get_win_folder = _get_win_folder_from_registry -+ -+ -+def _win_path_to_bytes(path): -+ """Encode Windows paths to bytes. Only used on Python 2. -+ -+ Motivation is to be consistent with other operating systems where paths -+ are also returned as bytes. This avoids problems mixing bytes and Unicode -+ elsewhere in the codebase. For more details and discussion see -+ <https://github.com/pypa/pip/issues/3463>. -+ -+ If encoding using ASCII and MBCS fails, return the original Unicode path. -+ """ -+ for encoding in ('ASCII', 'MBCS'): -+ try: -+ return path.encode(encoding) -+ except (UnicodeEncodeError, LookupError): -+ pass -+ return path - - - #---- self test code diff --git a/tools/vendoring/patches/pkg_resources.patch b/tools/vendoring/patches/pkg_resources.patch new file mode 100644 index 000000000..eea49e475 --- /dev/null +++ b/tools/vendoring/patches/pkg_resources.patch @@ -0,0 +1,22 @@ +diff --git a/src/pip/_vendor/pkg_resources/__init__.py b/src/pip/_vendor/pkg_resources/__init__.py +index a457ff27e..4cd562cf9 100644 +--- a/src/pip/_vendor/pkg_resources/__init__.py ++++ b/src/pip/_vendor/pkg_resources/__init__.py +@@ -77,7 +77,7 @@ + importlib_machinery = None + + from . import py31compat +-from pip._vendor import appdirs ++from pip._vendor import platformdirs + from pip._vendor import packaging + __import__('pip._vendor.packaging.version') + __import__('pip._vendor.packaging.specifiers') +@@ -1310,7 +1310,7 @@ + """ + return ( + os.environ.get('PYTHON_EGG_CACHE') +- or appdirs.user_cache_dir(appname='Python-Eggs') ++ or platformdirs.user_cache_dir(appname='Python-Eggs') + ) + + diff --git a/tools/vendoring/patches/platformdirs.patch b/tools/vendoring/patches/platformdirs.patch new file mode 100644 index 000000000..008312441 --- /dev/null +++ b/tools/vendoring/patches/platformdirs.patch @@ -0,0 +1,20 @@ +diff --git a/src/pip/_vendor/platformdirs.py b/src/pip/_vendor/platformdirs.py +index 23c6af8c7..3b8ef8ad8 100644 +--- a/src/pip/_vendor/platformdirs.py ++++ b/src/pip/_vendor/platformdirs.py +@@ -327,12 +327,10 @@ else: + return path + + def _site_config_dir_impl(appname=None, appauthor=None, version=None, multipath=False): +- # XDG default for $XDG_CONFIG_DIRS ++ # XDG default for $XDG_CONFIG_DIRSS (missing or empty) ++ # see <https://github.com/pypa/pip/pull/7501#discussion_r360624829> + # only first, if multipath is False +- if 'XDG_CONFIG_DIRS' in os.environ: +- path = os.environ['XDG_CONFIG_DIRS'] +- else: +- path = '/etc/xdg' ++ path = os.getenv('XDG_CONFIG_DIRS') or '/etc/xdg' + + pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] + if appname: |