Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor pip==24.2 #6211

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def handle_exception(exc_type, exception, traceback, hook=sys.excepthook):
sys.excepthook = handle_exception


class PipenvException:
class PipenvException(Exception):
message = "[bold][red]ERROR[/red][/bold]: {}"

def __init__(self, message=None, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/patched.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pip==24.0
pip==24.2
safety==2.3.2
14 changes: 0 additions & 14 deletions pipenv/patched/pip/COPYING

This file was deleted.

2 changes: 1 addition & 1 deletion pipenv/patched/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.2"


def main(args: Optional[List[str]] = None) -> int:
Expand Down
3 changes: 2 additions & 1 deletion pipenv/patched/pip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import importlib.util
import sys
spec = importlib.util.spec_from_file_location(
"pipenv", location=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "__init__.py"))
"pipenv",
location=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "__init__.py"))
pipenv = importlib.util.module_from_spec(spec)
sys.modules["pipenv"] = pipenv
spec.loader.exec_module(pipenv)
Expand Down
4 changes: 2 additions & 2 deletions pipenv/patched/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 pipenv/patched/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
8 changes: 6 additions & 2 deletions pipenv/patched/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type, Union

from pipenv.patched.pip._vendor.certifi import where
from pipenv.patched.pip._vendor.packaging.requirements import Requirement
from pipenv.patched.pip._vendor.packaging.version import Version

from pipenv.patched.pip import __file__ as pip_location
from pipenv.patched.pip._internal.cli.spinners import open_spinner
from pipenv.patched.pip._internal.locations import get_platlib, get_purelib, get_scheme
from pipenv.patched.pip._internal.metadata import get_default_environment, get_environment
from pipenv.patched.pip._internal.utils.logging import VERBOSE
from pipenv.patched.pip._internal.utils.packaging import get_requirement
from pipenv.patched.pip._internal.utils.subprocess import call_subprocess
from pipenv.patched.pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds

Expand Down Expand Up @@ -183,7 +184,7 @@ def check_requirements(
else get_default_environment()
)
for req_str in reqs:
req = Requirement(req_str)
req = get_requirement(req_str)
# We're explicitly evaluating with an empty extra value, since build
# environments are not provided any mechanism to select specific extras.
if req.marker is not None and not req.marker.evaluate({"extra": ""}):
Expand Down Expand Up @@ -240,8 +241,11 @@ def _install_requirements(
"--prefix",
prefix.path,
"--no-warn-script-location",
"--disable-pip-version-check",
]
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 pipenv/patched/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 pipenv/patched/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
127 changes: 61 additions & 66 deletions pipenv/patched/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Base Command class, and related routines"""

import functools
import logging
import logging.config
import optparse
import os
import sys
import traceback
from optparse import Values
from typing import Any, Callable, List, Optional, Tuple
from typing import List, Optional, Tuple

from pipenv.patched.pip._vendor.rich import reconfigure
from pipenv.patched.pip._vendor.rich import traceback as rich_traceback

from pipenv.patched.pip._internal.cli import cmdoptions
Expand All @@ -28,7 +28,6 @@
InstallationError,
NetworkConnectionError,
PreviousBuildDirError,
UninstallationError,
)
from pipenv.patched.pip._internal.utils.filesystem import check_path_owner
from pipenv.patched.pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
Expand Down Expand Up @@ -91,6 +90,63 @@ def handle_pip_version_check(self, options: Values) -> None:
def run(self, options: Values, args: List[str]) -> int:
raise NotImplementedError

def _run_wrapper(self, level_number: int, options: Values, args: List[str]) -> int:
def _inner_run() -> int:
try:
return self.run(options, args)
finally:
self.handle_pip_version_check(options)

if options.debug_mode:
rich_traceback.install(show_locals=True)
return _inner_run()

try:
status = _inner_run()
assert isinstance(status, int)
return status
except DiagnosticPipError as exc:
logger.error("%s", exc, extra={"rich": True})
logger.debug("Exception information:", exc_info=True)

return ERROR
except PreviousBuildDirError as exc:
logger.critical(str(exc))
logger.debug("Exception information:", exc_info=True)

return PREVIOUS_BUILD_DIR_ERROR
except (
InstallationError,
BadCommand,
NetworkConnectionError,
) as exc:
logger.critical(str(exc))
logger.debug("Exception information:", exc_info=True)

return ERROR
except CommandError as exc:
logger.critical("%s", exc)
logger.debug("Exception information:", exc_info=True)

return ERROR
except BrokenStdoutLoggingError:
# Bypass our logger and write any remaining messages to
# stderr because stdout no longer works.
print("ERROR: Pipe to stdout was broken", file=sys.stderr)
if level_number <= logging.DEBUG:
traceback.print_exc(file=sys.stderr)

return ERROR
except KeyboardInterrupt:
logger.critical("Operation cancelled by user")
logger.debug("Exception information:", exc_info=True)

return ERROR
except BaseException:
logger.critical("Exception:", exc_info=True)

return UNKNOWN_ERROR

def parse_args(self, args: List[str]) -> Tuple[Values, List[str]]:
# factored out for testability
return self.parser.parse_args(args)
Expand All @@ -116,6 +172,7 @@ def _main(self, args: List[str]) -> int:
# Set verbosity so that it can be used elsewhere.
self.verbosity = options.verbose - options.quiet

reconfigure(no_color=options.no_color)
level_number = setup_logging(
verbosity=self.verbosity,
no_color=options.no_color,
Expand Down Expand Up @@ -171,66 +228,4 @@ def _main(self, args: List[str]) -> int:
)
options.cache_dir = None

def intercepts_unhandled_exc(
run_func: Callable[..., int]
) -> Callable[..., int]:
@functools.wraps(run_func)
def exc_logging_wrapper(*args: Any) -> int:
try:
status = run_func(*args)
assert isinstance(status, int)
return status
except DiagnosticPipError as exc:
logger.error("%s", exc, extra={"rich": True})
logger.debug("Exception information:", exc_info=True)

return ERROR
except PreviousBuildDirError as exc:
logger.critical(str(exc))
logger.debug("Exception information:", exc_info=True)

return PREVIOUS_BUILD_DIR_ERROR
except (
InstallationError,
UninstallationError,
BadCommand,
NetworkConnectionError,
) as exc:
logger.critical(str(exc))
logger.debug("Exception information:", exc_info=True)

return ERROR
except CommandError as exc:
logger.critical("%s", exc)
logger.debug("Exception information:", exc_info=True)

return ERROR
except BrokenStdoutLoggingError:
# Bypass our logger and write any remaining messages to
# stderr because stdout no longer works.
print("ERROR: Pipe to stdout was broken", file=sys.stderr)
if level_number <= logging.DEBUG:
traceback.print_exc(file=sys.stderr)

return ERROR
except KeyboardInterrupt:
logger.critical("Operation cancelled by user")
logger.debug("Exception information:", exc_info=True)

return ERROR
except BaseException:
logger.critical("Exception:", exc_info=True)

return UNKNOWN_ERROR

return exc_logging_wrapper

try:
if not options.debug_mode:
run = intercepts_unhandled_exc(self.run)
else:
run = self.run
rich_traceback.install(show_locals=True)
return run(options, args)
finally:
self.handle_pip_version_check(options)
return self._run_wrapper(level_number, options, args)
9 changes: 5 additions & 4 deletions pipenv/patched/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 Expand Up @@ -996,6 +996,7 @@ def check_list_path_option(options: Values) -> None:

# Features that are now always on. A warning is printed if they are used.
ALWAYS_ENABLED_FEATURES = [
"truststore", # always on since 24.2
"no-binary-enable-wheel-cache", # always on since 23.1
]

Expand All @@ -1008,7 +1009,6 @@ def check_list_path_option(options: Values) -> None:
default=[],
choices=[
"fast-deps",
"truststore",
]
+ ALWAYS_ENABLED_FEATURES,
help="Enable new functionality, that may be backward incompatible.",
Expand All @@ -1023,6 +1023,7 @@ def check_list_path_option(options: Values) -> None:
default=[],
choices=[
"legacy-resolver",
"legacy-certs",
],
help=("Enable deprecated functionality, that will be removed in the future."),
)
Expand Down
Loading
Loading