summaryrefslogtreecommitdiff
path: root/tools/vendoring
diff options
context:
space:
mode:
authorPradyun Gedam <pradyunsg@users.noreply.github.com>2021-04-01 23:25:09 +0100
committerPradyun Gedam <pradyunsg@users.noreply.github.com>2021-04-01 23:25:09 +0100
commit147b9147826fe4752fe8b1edfd91d6f43e952eaa (patch)
tree936b710dd86aa9526e39f635cb92d3598914cb7a /tools/vendoring
parent1720aee672601bf6c2d2a04377d3f0c4ecba1923 (diff)
downloadpip-147b9147826fe4752fe8b1edfd91d6f43e952eaa.tar.gz
Get rid of the tools/automation folder
It was an unnecessary level added to the folder hierarchy.
Diffstat (limited to 'tools/vendoring')
-rw-r--r--tools/vendoring/patches/appdirs.patch115
-rw-r--r--tools/vendoring/patches/certifi.patch13
-rw-r--r--tools/vendoring/patches/requests.patch62
3 files changed, 190 insertions, 0 deletions
diff --git a/tools/vendoring/patches/appdirs.patch b/tools/vendoring/patches/appdirs.patch
new file mode 100644
index 000000000..69afd3e86
--- /dev/null
+++ b/tools/vendoring/patches/appdirs.patch
@@ -0,0 +1,115 @@
+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/certifi.patch b/tools/vendoring/patches/certifi.patch
new file mode 100644
index 000000000..9d5395a7b
--- /dev/null
+++ b/tools/vendoring/patches/certifi.patch
@@ -0,0 +1,13 @@
+diff --git a/src/pip/_vendor/certifi/core.py b/src/pip/_vendor/certifi/core.py
+index 5d2b8cd32..8987449f6 100644
+--- a/src/pip/_vendor/certifi/core.py
++++ b/src/pip/_vendor/certifi/core.py
+@@ -33,7 +33,7 @@ try:
+ # We also have to hold onto the actual context manager, because
+ # it will do the cleanup whenever it gets garbage collected, so
+ # we will also store that at the global level as well.
+- _CACERT_CTX = get_path("certifi", "cacert.pem")
++ _CACERT_CTX = get_path("pip._vendor.certifi", "cacert.pem")
+ _CACERT_PATH = str(_CACERT_CTX.__enter__())
+
+ return _CACERT_PATH
diff --git a/tools/vendoring/patches/requests.patch b/tools/vendoring/patches/requests.patch
new file mode 100644
index 000000000..08795ad3a
--- /dev/null
+++ b/tools/vendoring/patches/requests.patch
@@ -0,0 +1,62 @@
+diff --git a/src/pip/_vendor/requests/packages.py b/src/pip/_vendor/requests/packages.py
+index 6336a07d..9582fa73 100644
+--- a/src/pip/_vendor/requests/packages.py
++++ b/src/pip/_vendor/requests/packages.py
+@@ -4,11 +4,13 @@ import sys
+ # I don't like it either. Just look the other way. :)
+
+ for package in ('urllib3', 'idna', 'chardet'):
+- locals()[package] = __import__(package)
++ vendored_package = "pip._vendor." + package
++ locals()[package] = __import__(vendored_package)
+ # This traversal is apparently necessary such that the identities are
+ # preserved (requests.packages.urllib3.* is urllib3.*)
+ for mod in list(sys.modules):
+- if mod == package or mod.startswith(package + '.'):
+- sys.modules['requests.packages.' + mod] = sys.modules[mod]
++ if mod == vendored_package or mod.startswith(vendored_package + '.'):
++ unprefixed_mod = mod[len("pip._vendor."):]
++ sys.modules['pip._vendor.requests.packages.' + unprefixed_mod] = sys.modules[mod]
+
+ # Kinda cool, though, right?
+
+diff --git a/src/pip/_vendor/requests/__init__.py b/src/pip/_vendor/requests/__init__.py
+index dc83261a8..517458b5a 100644
+--- a/src/pip/_vendor/requests/__init__.py
++++ b/src/pip/_vendor/requests/__init__.py
+@@ -94,6 +94,11 @@ except (AssertionError, ValueError):
+ # if the standard library doesn't support SNI or the
+ # 'ssl' library isn't available.
+ try:
++ # Note: This logic prevents upgrading cryptography on Windows, if imported
++ # as part of pip.
++ from pip._internal.utils.compat import WINDOWS
++ if not WINDOWS:
++ raise ImportError("pip internals: don't import cryptography on Windows")
+ try:
+ import ssl
+ except ImportError:
+
+diff --git a/src/pip/_vendor/requests/compat.py b/src/pip/_vendor/requests/compat.py
+index eb6530d..353ec29 100644
+--- a/src/pip/_vendor/requests/compat.py
++++ b/src/pip/_vendor/requests/compat.py
+@@ -25,10 +25,14 @@
+ #: Python 3.x?
+ is_py3 = (_ver[0] == 3)
+
+-try:
+- import simplejson as json
+-except ImportError:
+- import json
++# Note: We've patched out simplejson support in pip because it prevents
++# upgrading simplejson on Windows.
++# try:
++# import simplejson as json
++# except (ImportError, SyntaxError):
++# # simplejson does not support Python 3.2, it throws a SyntaxError
++# # because of u'...' Unicode literals.
++import json
+
+ # ---------
+ # Specifics