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 in pip==24.3.1 #6292

Merged
merged 2 commits into from
Nov 1, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6292.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vendor in ``pip==24.3.1``.
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.2
pip==24.3.1
safety==2.3.2
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.2"
__version__ = "24.3.1"


def main(args: Optional[List[str]] = None) -> int:
Expand Down
4 changes: 4 additions & 0 deletions pipenv/patched/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def _install_requirements(
prefix.path,
"--no-warn-script-location",
"--disable-pip-version-check",
# The prefix specified two lines above, thus
# target from config file or env var should be ignored
"--target",
"",
]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append("-vv")
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/cli/index_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SessionCommandMixin(CommandContextMixIn):

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

@classmethod
def _get_index_urls(cls, options: Values) -> Optional[List[str]]:
Expand Down
4 changes: 2 additions & 2 deletions pipenv/patched/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, Optional, Tuple
from typing import Any, Dict, Generator, List, NoReturn, Optional, Tuple

from pipenv.patched.pip._internal.cli.status_codes import UNKNOWN_ERROR
from pipenv.patched.pip._internal.configuration import Configuration, ConfigurationError
Expand Down Expand Up @@ -289,6 +289,6 @@ def get_default_values(self) -> optparse.Values:
defaults[option.dest] = option.check_value(opt_str, default)
return optparse.Values(defaults)

def error(self, msg: str) -> None:
def error(self, msg: str) -> NoReturn:
self.print_usage(sys.stderr)
self.exit(UNKNOWN_ERROR, f"{msg}\n")
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _rich_progress_bar(
iterable: Iterable[bytes],
*,
bar_type: str,
size: int,
size: Optional[int],
) -> Generator[bytes, None, None]:
assert bar_type == "on", "This should only be used in the default mode."

Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def run(self, options: Values, args: List[str]) -> int:
if options.excludes:
skip.update(canonicalize_name(n) for n in options.excludes)

packages: "_ProcessedDists" = [
packages: _ProcessedDists = [
cast("_DistWithLatestInfo", d)
for d in get_environment(options.path).iter_installed_distributions(
local_only=options.local,
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def transform_hits(hits: List[Dict[str, str]]) -> List["TransformedHit"]:
packages with the list of versions stored inline. This converts the
list from pypi into one we can use.
"""
packages: Dict[str, "TransformedHit"] = OrderedDict()
packages: Dict[str, TransformedHit] = OrderedDict()
for hit in hits:
name = hit["name"]
summary = hit["summary"]
Expand Down
34 changes: 33 additions & 1 deletion pipenv/patched/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from itertools import chain, groupby, repeat
from typing import TYPE_CHECKING, Dict, Iterator, List, Literal, Optional, Union

from pipenv.patched.pip._vendor.packaging.requirements import InvalidRequirement
from pipenv.patched.pip._vendor.packaging.version import InvalidVersion
from pipenv.patched.pip._vendor.rich.console import Console, ConsoleOptions, RenderResult
from pipenv.patched.pip._vendor.rich.markup import escape
from pipenv.patched.pip._vendor.rich.text import Text
Expand Down Expand Up @@ -429,7 +431,7 @@ class HashErrors(InstallationError):
"""Multiple HashError instances rolled into one for reporting"""

def __init__(self) -> None:
self.errors: List["HashError"] = []
self.errors: List[HashError] = []

def append(self, error: "HashError") -> None:
self.errors.append(error)
Expand Down Expand Up @@ -775,3 +777,33 @@ def __init__(self, *, distribution: "BaseDistribution") -> None:
),
hint_stmt=None,
)


class InvalidInstalledPackage(DiagnosticPipError):
reference = "invalid-installed-package"

def __init__(
self,
*,
dist: "BaseDistribution",
invalid_exc: Union[InvalidRequirement, InvalidVersion],
) -> None:
installed_location = dist.installed_location

if isinstance(invalid_exc, InvalidRequirement):
invalid_type = "requirement"
else:
invalid_type = "version"

super().__init__(
message=Text(
f"Cannot process installed package {dist} "
+ (f"in {installed_location!r} " if installed_location else "")
+ f"because it has an invalid {invalid_type}:\n{invalid_exc.args[0]}"
),
context=(
"Starting with pip 24.1, packages with invalid "
f"{invalid_type}s can not be processed."
),
hint_stmt="To proceed this package must be uninstalled.",
)
5 changes: 2 additions & 3 deletions pipenv/patched/pip/_internal/index/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from pipenv.patched.pip._vendor.packaging.utils import (
InvalidSdistFilename,
InvalidVersion,
InvalidWheelFilename,
canonicalize_name,
parse_sdist_filename,
Expand Down Expand Up @@ -68,10 +67,10 @@ def _scan_directory(self) -> None:
# otherwise not worth considering as a package
try:
project_filename = parse_wheel_filename(entry.name)[0]
except (InvalidWheelFilename, InvalidVersion):
except InvalidWheelFilename:
try:
project_filename = parse_sdist_filename(entry.name)[0]
except (InvalidSdistFilename, InvalidVersion):
except InvalidSdistFilename:
continue

self._project_name_to_urls[project_filename].append(url)
Expand Down
6 changes: 3 additions & 3 deletions pipenv/patched/pip/_internal/locations/_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from distutils.command.install import SCHEME_KEYS
from distutils.command.install import install as distutils_install_command
from distutils.sysconfig import get_python_lib
from typing import Dict, List, Optional, Union, cast
from typing import Dict, List, Optional, Union

from pipenv.patched.pip._internal.models.scheme import Scheme
from pipenv.patched.pip._internal.utils.compat import WINDOWS
Expand Down Expand Up @@ -64,7 +64,7 @@ def distutils_scheme(
obj: Optional[DistutilsCommand] = None
obj = d.get_command_obj("install", create=True)
assert obj is not None
i = cast(distutils_install_command, obj)
i: distutils_install_command = obj
# NOTE: setting user or home has the side-effect of creating the home dir
# or user base for installations during finalize_options()
# ideally, we'd prefer a scheme class that has no side-effects.
Expand All @@ -78,7 +78,7 @@ def distutils_scheme(
i.root = root or i.root
i.finalize_options()

scheme = {}
scheme: Dict[str, str] = {}
for key in SCHEME_KEYS:
scheme[key] = getattr(i, "install_" + key)

Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/metadata/importlib/_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _emit_egg_deprecation(location: Optional[str]) -> None:
deprecated(
reason=f"Loading egg at {location} is deprecated.",
replacement="to use pip for package installation",
gone_in="24.3",
gone_in="25.1",
issue=12330,
)

Expand Down
31 changes: 28 additions & 3 deletions pipenv/patched/pip/_internal/models/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
from typing import Dict, Iterable, List

from pipenv.patched.pip._vendor.packaging.tags import Tag
from pipenv.patched.pip._vendor.packaging.utils import (
InvalidWheelFilename as PackagingInvalidWheelName,
)
from pipenv.patched.pip._vendor.packaging.utils import parse_wheel_filename

from pipenv.patched.pip._internal.exceptions import InvalidWheelFilename
from pipenv.patched.pip._internal.utils.deprecation import deprecated


class Wheel:
Expand All @@ -29,9 +34,29 @@ def __init__(self, filename: str) -> None:
raise InvalidWheelFilename(f"{filename} is not a valid wheel filename.")
self.filename = filename
self.name = wheel_info.group("name").replace("_", "-")
# we'll assume "_" means "-" due to wheel naming scheme
# (https://github.com/pypa/pip/issues/1150)
self.version = wheel_info.group("ver").replace("_", "-")
_version = wheel_info.group("ver")
if "_" in _version:
try:
parse_wheel_filename(filename)
except PackagingInvalidWheelName as e:
deprecated(
reason=(
f"Wheel filename {filename!r} is not correctly normalised. "
"Future versions of pip will raise the following error:\n"
f"{e.args[0]}\n\n"
),
replacement=(
"to rename the wheel to use a correctly normalised "
"name (this may require updating the version in "
"the project metadata)"
),
gone_in="25.1",
issue=12938,
)

_version = _version.replace("_", "-")

self.version = _version
self.build_tag = wheel_info.group("build")
self.pyversions = wheel_info.group("pyver").split(".")
self.abis = wheel_info.group("abi").split(".")
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/network/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _check_zip(self) -> None:
try:
# For read-only ZIP files, ZipFile only needs
# methods read, seek, seekable and tell.
ZipFile(self) # type: ignore
ZipFile(self)
except BadZipFile:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _set_requirement_extras(req: Requirement, new_extras: Set[str]) -> Requireme
assert (
pre is not None and post is not None
), f"regex group selection for requirement {req} failed, this should never happen"
extras: str = "[%s]" % ",".join(sorted(new_extras)) if new_extras else ""
extras: str = "[{}]".format(",".join(sorted(new_extras)) if new_extras else "")
return get_requirement(f"{pre}{extras}{post}")


Expand Down
37 changes: 30 additions & 7 deletions pipenv/patched/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,15 @@ def parse(
self, filename: str, constraint: bool
) -> Generator[ParsedLine, None, None]:
"""Parse a given file, yielding parsed lines."""
yield from self._parse_and_recurse(filename, constraint)
yield from self._parse_and_recurse(
filename, constraint, [{os.path.abspath(filename): None}]
)

def _parse_and_recurse(
self, filename: str, constraint: bool
self,
filename: str,
constraint: bool,
parsed_files_stack: List[Dict[str, Optional[str]]],
) -> Generator[ParsedLine, None, None]:
for line in self._parse_file(filename, constraint):
if not line.is_requirement and (
Expand All @@ -353,12 +358,30 @@ def _parse_and_recurse(
# original file and nested file are paths
elif not SCHEME_RE.search(req_path):
# do a join so relative paths work
req_path = os.path.join(
os.path.dirname(filename),
req_path,
# and then abspath so that we can identify recursive references
req_path = os.path.abspath(
os.path.join(
os.path.dirname(filename),
req_path,
)
)

yield from self._parse_and_recurse(req_path, nested_constraint)
parsed_files = parsed_files_stack[0]
if req_path in parsed_files:
initial_file = parsed_files[req_path]
tail = (
f" and again in {initial_file}"
if initial_file is not None
else ""
)
raise RequirementsFileParseError(
f"{req_path} recursively references itself in {filename}{tail}"
)
# Keeping a track where was each file first included in
new_parsed_files = parsed_files.copy()
new_parsed_files[req_path] = filename
yield from self._parse_and_recurse(
req_path, nested_constraint, [new_parsed_files, *parsed_files_stack]
)
else:
yield line

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pipenv.patched.pip._internal.exceptions import (
HashError,
InstallationSubprocessError,
InvalidInstalledPackage,
MetadataInconsistent,
MetadataInvalid,
)
Expand Down Expand Up @@ -402,8 +403,12 @@ def format_for_error(self) -> str:
def iter_dependencies(self, with_requires: bool) -> Iterable[Optional[Requirement]]:
if not with_requires:
return
for r in self.dist.iter_dependencies():
yield from self._factory.make_requirements_from_spec(str(r), self._ireq)

try:
for r in self.dist.iter_dependencies():
yield from self._factory.make_requirements_from_spec(str(r), self._ireq)
except InvalidRequirement as exc:
raise InvalidInstalledPackage(dist=self.dist, invalid_exc=exc) from None

def get_install_requirement(self) -> Optional[InstallRequirement]:
return None
Expand Down
16 changes: 11 additions & 5 deletions pipenv/patched/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
from pipenv.patched.pip._vendor.packaging.requirements import InvalidRequirement
from pipenv.patched.pip._vendor.packaging.specifiers import SpecifierSet
from pipenv.patched.pip._vendor.packaging.utils import NormalizedName, canonicalize_name
from pipenv.patched.pip._vendor.packaging.version import Version
from pipenv.patched.pip._vendor.packaging.version import InvalidVersion, Version
from pipenv.patched.pip._vendor.resolvelib import ResolutionImpossible

from pipenv.patched.pip._internal.cache import CacheEntry, WheelCache
from pipenv.patched.pip._internal.exceptions import (
DistributionNotFound,
InstallationError,
InvalidInstalledPackage,
MetadataInconsistent,
MetadataInvalid,
UnsupportedPythonVersion,
Expand Down Expand Up @@ -283,10 +284,15 @@ def _get_installed_candidate() -> Optional[Candidate]:
installed_dist = self._installed_dists[name]
except KeyError:
return None
# Don't use the installed distribution if its version does not fit
# the current dependency graph.
if not specifier.contains(installed_dist.version, prereleases=True):
return None

try:
# Don't use the installed distribution if its version
# does not fit the current dependency graph.
if not specifier.contains(installed_dist.version, prereleases=True):
return None
except InvalidVersion as e:
raise InvalidInstalledPackage(dist=installed_dist, invalid_exc=e)

candidate = self._make_candidate_from_dist(
dist=installed_dist,
extras=extras,
Expand Down
Loading
Loading