saving dependency work

This commit is contained in:
2022-12-10 21:17:54 -06:00
parent bf923c3406
commit c2c19e5382
5636 changed files with 666283 additions and 8587 deletions
@@ -22,13 +22,14 @@ if MYPY_CHECK_RUNNING:
from typing import Callable, Optional, Protocol, Text, Tuple, TypeVar, Union
# Used in the @lru_cache polyfill.
F = TypeVar('F')
F = TypeVar("F")
class LruCache(Protocol):
def __call__(self, maxsize=None):
# type: (Optional[int]) -> Callable[[F], F]
raise NotImplementedError
try:
import ipaddress
except ImportError:
@@ -36,13 +37,20 @@ except ImportError:
from pip._vendor import ipaddress # type: ignore
except ImportError:
import ipaddr as ipaddress # type: ignore
ipaddress.ip_address = ipaddress.IPAddress # type: ignore
ipaddress.ip_network = ipaddress.IPNetwork # type: ignore
__all__ = [
"ipaddress", "uses_pycache", "console_to_str",
"get_path_uid", "stdlib_pkgs", "WINDOWS", "samefile", "get_terminal_size",
"ipaddress",
"uses_pycache",
"console_to_str",
"get_path_uid",
"stdlib_pkgs",
"WINDOWS",
"samefile",
"get_terminal_size",
]
@@ -73,7 +81,8 @@ if PY2:
raw_bytes = (err.object[i] for i in range(err.start, err.end))
# Python 2 gave us characters - convert to numeric bytes
raw_bytes = (ord(b) for b in raw_bytes)
return u"".join(map(u"\\x{:x}".format, raw_bytes)), err.end
return "".join(map("\\x{:x}".format, raw_bytes)), err.end
codecs.register_error(
"backslashreplace_decode",
backslashreplace_decode_fn,
@@ -87,11 +96,13 @@ def has_tls():
# type: () -> bool
try:
import _ssl # noqa: F401 # ignore unused
return True
except ImportError:
pass
from pip._vendor.urllib3.util import IS_PYOPENSSL
return IS_PYOPENSSL
@@ -131,8 +142,8 @@ def str_to_display(data, desc=None):
decoded_data = data.decode(encoding)
except UnicodeDecodeError:
logger.warning(
'%s does not appear to be encoded as %s',
desc or 'Bytes object',
"%s does not appear to be encoded as %s",
desc or "Bytes object",
encoding,
)
decoded_data = data.decode(encoding, errors=backslashreplace_decode)
@@ -149,14 +160,10 @@ def str_to_display(data, desc=None):
# or doesn't have an encoding attribute. Neither of these cases
# should occur in normal pip use, but there's no harm in checking
# in case people use pip in (unsupported) unusual situations.
output_encoding = getattr(getattr(sys, "__stderr__", None),
"encoding", None)
output_encoding = getattr(getattr(sys, "__stderr__", None), "encoding", None)
if output_encoding:
output_encoded = decoded_data.encode(
output_encoding,
errors="backslashreplace"
)
output_encoded = decoded_data.encode(output_encoding, errors="backslashreplace")
decoded_data = output_encoded.decode(output_encoding)
return decoded_data
@@ -164,9 +171,8 @@ def str_to_display(data, desc=None):
def console_to_str(data):
# type: (bytes) -> Text
"""Return a string, safe for output, of subprocess output.
"""
return str_to_display(data, desc='Subprocess output')
"""Return a string, safe for output, of subprocess output."""
return str_to_display(data, desc="Subprocess output")
def get_path_uid(path):
@@ -182,7 +188,7 @@ def get_path_uid(path):
:raises OSError: When path is a symlink or can't be read.
"""
if hasattr(os, 'O_NOFOLLOW'):
if hasattr(os, "O_NOFOLLOW"):
fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)
file_uid = os.fstat(fd).st_uid
os.close(fd)
@@ -194,8 +200,7 @@ def get_path_uid(path):
else:
# raise OSError for parity with os.O_NOFOLLOW above
raise OSError(
"{} is a symlink; Will not return uid for symlinks".format(
path)
"{} is a symlink; Will not return uid for symlinks".format(path)
)
return file_uid
@@ -208,7 +213,7 @@ def expanduser(path):
Includes a workaround for https://bugs.python.org/issue14768
"""
expanded = os.path.expanduser(path)
if path.startswith('~/') and expanded.startswith('//'):
if path.startswith("~/") and expanded.startswith("//"):
expanded = expanded[1:]
return expanded
@@ -222,14 +227,13 @@ stdlib_pkgs = {"python", "wsgiref", "argparse"}
# windows detection, covers cpython and ironpython
WINDOWS = (sys.platform.startswith("win") or
(sys.platform == 'cli' and os.name == 'nt'))
WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")
def samefile(file1, file2):
# type: (str, str) -> bool
"""Provide an alternative for os.path.samefile on Windows/Python2"""
if hasattr(os.path, 'samefile'):
if hasattr(os.path, "samefile"):
return os.path.samefile(file1, file2)
else:
path1 = os.path.normcase(os.path.abspath(file1))
@@ -237,7 +241,8 @@ def samefile(file1, file2):
return path1 == path2
if hasattr(shutil, 'get_terminal_size'):
if hasattr(shutil, "get_terminal_size"):
def get_terminal_size():
# type: () -> Tuple[int, int]
"""
@@ -245,27 +250,31 @@ if hasattr(shutil, 'get_terminal_size'):
in characters of the terminal window.
"""
return tuple(shutil.get_terminal_size()) # type: ignore
else:
def get_terminal_size():
# type: () -> Tuple[int, int]
"""
Returns a tuple (x, y) representing the width(x) and the height(y)
in characters of the terminal window.
"""
def ioctl_GWINSZ(fd):
try:
import fcntl
import struct
import termios
cr = struct.unpack_from(
'hh',
fcntl.ioctl(fd, termios.TIOCGWINSZ, '12345678')
"hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "12345678")
)
except Exception:
return None
if cr == (0, 0):
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
if sys.platform != "win32":
@@ -276,7 +285,7 @@ else:
except Exception:
pass
if not cr:
cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
cr = (os.environ.get("LINES", 25), os.environ.get("COLUMNS", 80))
return int(cr[1]), int(cr[0])
@@ -287,6 +296,7 @@ def noop_lru_cache(maxsize=None):
def _wrapper(f):
# type: (F) -> F
return f
return _wrapper