Skip to content

Commit

Permalink
Update pip to 24.1.1 and fix all pip._vendor prefixes
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaochao Dong (@damnever) <[email protected]>
  • Loading branch information
damnever committed Jul 4, 2024
1 parent 0402e3e commit 1ae3458
Show file tree
Hide file tree
Showing 285 changed files with 9,515 additions and 60,680 deletions.
2 changes: 1 addition & 1 deletion pigar/_vendor/pip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional

__version__ = "24.0"
__version__ = "24.1.1"


def main(args: Optional[List[str]] = None) -> int:
Expand Down
4 changes: 2 additions & 2 deletions pigar/_vendor/pip/__pip-runner__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import sys

# Copied from setup.py
PYTHON_REQUIRES = (3, 7)
# Copied from pyproject.toml
PYTHON_REQUIRES = (3, 8)


def version_str(version): # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion pigar/_vendor/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
_log.init_logging()


def main(args: (Optional[List[str]]) = None) -> int:
def main(args: Optional[List[str]] = None) -> int:
"""This is preserved for old console scripts that may still be referencing
it.
Expand Down
3 changes: 3 additions & 0 deletions pigar/_vendor/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pigar._vendor.pip._internal.cli.spinners import open_spinner
from pigar._vendor.pip._internal.locations import get_platlib, get_purelib, get_scheme
from pigar._vendor.pip._internal.metadata import get_default_environment, get_environment
from pigar._vendor.pip._internal.utils.logging import VERBOSE
from pigar._vendor.pip._internal.utils.subprocess import call_subprocess
from pigar._vendor.pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds

Expand Down Expand Up @@ -242,6 +243,8 @@ def _install_requirements(
"--no-warn-script-location",
]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append("-vv")
elif logger.getEffectiveLevel() <= VERBOSE:
args.append("-v")
for format_control in ("no_binary", "only_binary"):
formats = getattr(finder.format_control, format_control)
Expand Down
2 changes: 1 addition & 1 deletion pigar/_vendor/pip/_internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _get_cache_path_parts(self, link: Link) -> List[str]:
"""Get parts of part that must be os.path.joined with cache_dir"""

# We want to generate an url to use as our cache key, we don't want to
# just re-use the URL because it might have other items in the fragment
# just reuse the URL because it might have other items in the fragment
# and we don't care about those.
key_parts = {"url": link.url_without_fragment}
if link.hash_name is not None and link.hash is not None:
Expand Down
4 changes: 4 additions & 0 deletions pigar/_vendor/pip/_internal/cli/autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def autocomplete() -> None:
# Don't complete if user hasn't sourced bash_completion file.
if "PIP_AUTO_COMPLETE" not in os.environ:
return
# Don't complete if autocompletion environment variables
# are not present
if not os.environ.get("COMP_WORDS") or not os.environ.get("COMP_CWORD"):
return
cwords = os.environ["COMP_WORDS"].split()[1:]
cword = int(os.environ["COMP_CWORD"])
try:
Expand Down
2 changes: 0 additions & 2 deletions pigar/_vendor/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
InstallationError,
NetworkConnectionError,
PreviousBuildDirError,
UninstallationError,
)
from pigar._vendor.pip._internal.utils.filesystem import check_path_owner
from pigar._vendor.pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
Expand Down Expand Up @@ -192,7 +191,6 @@ def exc_logging_wrapper(*args: Any) -> int:
return PREVIOUS_BUILD_DIR_ERROR
except (
InstallationError,
UninstallationError,
BadCommand,
NetworkConnectionError,
) as exc:
Expand Down
6 changes: 3 additions & 3 deletions pigar/_vendor/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ class PipOption(Option):
"--progress-bar",
dest="progress_bar",
type="choice",
choices=["on", "off"],
choices=["on", "off", "raw"],
default="on",
help="Specify whether the progress bar should be used [on, off] (default: on)",
help="Specify whether the progress bar should be used [on, off, raw] (default: on)",
)

log: Callable[..., Option] = partial(
Expand Down Expand Up @@ -903,7 +903,7 @@ def _handle_config_settings(
dest="root_user_action",
default="warn",
choices=["warn", "ignore"],
help="Action if pip is run as a root user. By default, a warning message is shown.",
help="Action if pip is run as a root user [warn, ignore] (default: warn)",
)


Expand Down
172 changes: 172 additions & 0 deletions pigar/_vendor/pip/_internal/cli/index_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"""
Contains command classes which may interact with an index / the network.
Unlike its sister module, req_command, this module still uses lazy imports
so commands which don't always hit the network (e.g. list w/o --outdated or
--uptodate) don't need waste time importing PipSession and friends.
"""

import logging
import os
import sys
from optparse import Values
from typing import TYPE_CHECKING, List, Optional

from pigar._vendor.pip._internal.cli.base_command import Command
from pigar._vendor.pip._internal.cli.command_context import CommandContextMixIn
from pigar._vendor.pip._internal.exceptions import CommandError

if TYPE_CHECKING:
from ssl import SSLContext

from pigar._vendor.pip._internal.network.session import PipSession

logger = logging.getLogger(__name__)


def _create_truststore_ssl_context() -> Optional["SSLContext"]:
if sys.version_info < (3, 10):
raise CommandError("The truststore feature is only available for Python 3.10+")

try:
import ssl
except ImportError:
logger.warning("Disabling truststore since ssl support is missing")
return None

try:
from pigar._vendor.pip._vendor import truststore
except ImportError as e:
raise CommandError(f"The truststore feature is unavailable: {e}")

return truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)


class SessionCommandMixin(CommandContextMixIn):
"""
A class mixin for command classes needing _build_session().
"""

def __init__(self) -> None:
super().__init__()
self._session: Optional["PipSession"] = None

@classmethod
def _get_index_urls(cls, options: Values) -> Optional[List[str]]:
"""Return a list of index urls from user-provided options."""
index_urls = []
if not getattr(options, "no_index", False):
url = getattr(options, "index_url", None)
if url:
index_urls.append(url)
urls = getattr(options, "extra_index_urls", None)
if urls:
index_urls.extend(urls)
# Return None rather than an empty list
return index_urls or None

def get_default_session(self, options: Values) -> "PipSession":
"""Get a default-managed session."""
if self._session is None:
self._session = self.enter_context(self._build_session(options))
# there's no type annotation on requests.Session, so it's
# automatically ContextManager[Any] and self._session becomes Any,
# then https://github.com/python/mypy/issues/7696 kicks in
assert self._session is not None
return self._session

def _build_session(
self,
options: Values,
retries: Optional[int] = None,
timeout: Optional[int] = None,
fallback_to_certifi: bool = False,
) -> "PipSession":
from pigar._vendor.pip._internal.network.session import PipSession

cache_dir = options.cache_dir
assert not cache_dir or os.path.isabs(cache_dir)

if "truststore" in options.features_enabled:
try:
ssl_context = _create_truststore_ssl_context()
except Exception:
if not fallback_to_certifi:
raise
ssl_context = None
else:
ssl_context = None

session = PipSession(
cache=os.path.join(cache_dir, "http-v2") if cache_dir else None,
retries=retries if retries is not None else options.retries,
trusted_hosts=options.trusted_hosts,
index_urls=self._get_index_urls(options),
ssl_context=ssl_context,
)

# Handle custom ca-bundles from the user
if options.cert:
session.verify = options.cert

# Handle SSL client certificate
if options.client_cert:
session.cert = options.client_cert

# Handle timeouts
if options.timeout or timeout:
session.timeout = timeout if timeout is not None else options.timeout

# Handle configured proxies
if options.proxy:
session.proxies = {
"http": options.proxy,
"https": options.proxy,
}
session.trust_env = False

# Determine if we can prompt the user for authentication or not
session.auth.prompting = not options.no_input
session.auth.keyring_provider = options.keyring_provider

return session


def _pip_self_version_check(session: "PipSession", options: Values) -> None:
from pigar._vendor.pip._internal.self_outdated_check import pip_self_version_check as check

check(session, options)


class IndexGroupCommand(Command, SessionCommandMixin):
"""
Abstract base class for commands with the index_group options.
This also corresponds to the commands that permit the pip version check.
"""

def handle_pip_version_check(self, options: Values) -> None:
"""
Do the pip version check if not disabled.
This overrides the default behavior of not doing the check.
"""
# Make sure the index_group options are present.
assert hasattr(options, "no_index")

if options.disable_pip_version_check or options.no_index:
return

# Otherwise, check if we're using the latest version of pip available.
session = self._build_session(
options,
retries=0,
timeout=min(5, options.timeout),
# This is set to ensure the function does not fail when truststore is
# specified in use-feature but cannot be loaded. This usually raises a
# CommandError and shows a nice user-facing error, but this function is not
# called in that try-except block.
fallback_to_certifi=True,
)
with session:
_pip_self_version_check(session, options)
3 changes: 2 additions & 1 deletion pigar/_vendor/pip/_internal/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Primary application entrypoint.
"""

import locale
import logging
import os
Expand Down Expand Up @@ -49,7 +50,7 @@ def main(args: Optional[List[str]] = None) -> int:

# Suppress the pkg_resources deprecation warning
# Note - we use a module of .*pkg_resources to cover
# the normal case (pip._vendor.pkg_resources) and the
# the normal case (pigar._vendor.pip._vendor.pkg_resources) and the
# devendored case (a bare pkg_resources)
warnings.filterwarnings(
action="ignore", category=DeprecationWarning, module=".*pkg_resources"
Expand Down
6 changes: 3 additions & 3 deletions pigar/_vendor/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import textwrap
from contextlib import suppress
from typing import Any, Dict, Generator, List, Tuple
from typing import Any, Dict, Generator, List, Optional, Tuple

from pigar._vendor.pip._internal.cli.status_codes import UNKNOWN_ERROR
from pigar._vendor.pip._internal.configuration import Configuration, ConfigurationError
Expand Down Expand Up @@ -67,7 +67,7 @@ def format_usage(self, usage: str) -> str:
msg = "\nUsage: {}\n".format(self.indent_lines(textwrap.dedent(usage), " "))
return msg

def format_description(self, description: str) -> str:
def format_description(self, description: Optional[str]) -> str:
# leave full control over description to us
if description:
if hasattr(self.parser, "main"):
Expand All @@ -85,7 +85,7 @@ def format_description(self, description: str) -> str:
else:
return ""

def format_epilog(self, epilog: str) -> str:
def format_epilog(self, epilog: Optional[str]) -> str:
# leave full control over epilog to us
if epilog:
return epilog
Expand Down
26 changes: 26 additions & 0 deletions pigar/_vendor/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import sys
from typing import Callable, Generator, Iterable, Iterator, Optional, Tuple

from pigar._vendor.pip._vendor.rich.progress import (
Expand All @@ -14,6 +15,7 @@
TransferSpeedColumn,
)

from pigar._vendor.pip._internal.cli.spinners import RateLimiter
from pigar._vendor.pip._internal.utils.logging import get_indentation

DownloadProgressRenderer = Callable[[Iterable[bytes]], Iterator[bytes]]
Expand Down Expand Up @@ -55,6 +57,28 @@ def _rich_progress_bar(
progress.update(task_id, advance=len(chunk))


def _raw_progress_bar(
iterable: Iterable[bytes],
*,
size: Optional[int],
) -> Generator[bytes, None, None]:
def write_progress(current: int, total: int) -> None:
sys.stdout.write("Progress %d of %d\n" % (current, total))
sys.stdout.flush()

current = 0
total = size or 0
rate_limiter = RateLimiter(0.25)

write_progress(current, total)
for chunk in iterable:
current += len(chunk)
if rate_limiter.ready() or current == total:
write_progress(current, total)
rate_limiter.reset()
yield chunk


def get_download_progress_renderer(
*, bar_type: str, size: Optional[int] = None
) -> DownloadProgressRenderer:
Expand All @@ -64,5 +88,7 @@ def get_download_progress_renderer(
"""
if bar_type == "on":
return functools.partial(_rich_progress_bar, bar_type=bar_type, size=size)
elif bar_type == "raw":
return functools.partial(_raw_progress_bar, size=size)
else:
return iter # no-op, when passed an iterator
Loading

0 comments on commit 1ae3458

Please sign in to comment.