bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -80,7 +80,7 @@ def _emit_pkg_resources_deprecation_if_needed() -> None:
|
||||
"to use the default importlib.metadata backend, "
|
||||
"by unsetting the _PIP_USE_IMPORTLIB_METADATA environment variable"
|
||||
),
|
||||
gone_in="26.3",
|
||||
gone_in="27.0",
|
||||
issue=13317,
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ from typing import (
|
||||
Any,
|
||||
NamedTuple,
|
||||
Protocol,
|
||||
Union,
|
||||
)
|
||||
|
||||
from pip._vendor.packaging.requirements import Requirement
|
||||
@@ -29,14 +28,21 @@ from pip._internal.models.direct_url import (
|
||||
DirectUrl,
|
||||
DirectUrlValidationError,
|
||||
)
|
||||
from pip._internal.utils.compat import stdlib_pkgs # TODO: Move definition here.
|
||||
from pip._internal.utils.egg_link import egg_link_path_from_sys_path
|
||||
from pip._internal.utils.misc import is_local, normalize_path
|
||||
from pip._internal.utils.urls import url_to_path
|
||||
|
||||
from ._json import msg_to_json
|
||||
|
||||
InfoPath = Union[str, pathlib.PurePath]
|
||||
# packages in the stdlib that may have installation metadata, but should not be
|
||||
# considered 'installed'. this theoretically could be determined based on
|
||||
# dist.location (py27:`sysconfig.get_paths()['stdlib']`,
|
||||
# py26:sysconfig.get_config_vars('LIBDEST')), but fear platform variation may
|
||||
# make this ineffective, so hard-coding
|
||||
stdlib_pkgs = {"python", "wsgiref", "argparse"}
|
||||
|
||||
|
||||
InfoPath = str | pathlib.PurePath
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -152,14 +158,13 @@ class BaseDistribution(Protocol):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@functools.cached_property
|
||||
def editable_project_location(self) -> str | None:
|
||||
"""The project location for editable distributions.
|
||||
|
||||
This is the directory where pyproject.toml or setup.py is located.
|
||||
None if the distribution is not installed in editable mode.
|
||||
"""
|
||||
# TODO: this property is relatively costly to compute, memoize it ?
|
||||
direct_url = self.direct_url
|
||||
if direct_url:
|
||||
if direct_url.is_local_editable():
|
||||
@@ -617,11 +622,29 @@ class BaseEnvironment:
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
if not project_name_valid:
|
||||
logger.warning(
|
||||
"Ignoring invalid distribution %s (%s)",
|
||||
dist.canonical_name,
|
||||
dist.location,
|
||||
# Check the directory name rather than the distribution name,
|
||||
# since the pkg_resources (default below 3.11) backend normalizes
|
||||
# the leading tilde to a dash.
|
||||
# TODO: use dist.canonical_name for this check once
|
||||
# pkg_resources support is dropped (#13317).
|
||||
info_location = dist.info_location
|
||||
leftover_name = (
|
||||
pathlib.Path(info_location).name if info_location else ""
|
||||
)
|
||||
if leftover_name.startswith("~"):
|
||||
logger.warning(
|
||||
"Ignoring incompletely removed distribution %s (%s); "
|
||||
"'~'-prefixed leftover directories are the result of a "
|
||||
"previous incomplete installation, and can be deleted",
|
||||
leftover_name,
|
||||
dist.location,
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Ignoring invalid distribution %s (%s)",
|
||||
dist.canonical_name,
|
||||
dist.location,
|
||||
)
|
||||
continue
|
||||
yield dist
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
||||
from pip._vendor.packaging.version import Version
|
||||
from pip._vendor.packaging.version import parse as parse_version
|
||||
|
||||
from pip._internal.exceptions import InvalidWheel, UnsupportedWheel
|
||||
from pip._internal.exceptions import InstallationError, InvalidWheel, UnsupportedWheel
|
||||
from pip._internal.metadata.base import (
|
||||
BaseDistribution,
|
||||
BaseEntryPoint,
|
||||
@@ -177,7 +177,7 @@ class Distribution(BaseDistribution):
|
||||
|
||||
@property
|
||||
def raw_version(self) -> str:
|
||||
return self._dist.version
|
||||
return self.metadata["Version"]
|
||||
|
||||
def is_file(self, path: InfoPath) -> bool:
|
||||
return self._dist.read_text(str(path)) is not None
|
||||
@@ -199,7 +199,13 @@ class Distribution(BaseDistribution):
|
||||
|
||||
def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
|
||||
# importlib.metadata's EntryPoint structure satisfies BaseEntryPoint.
|
||||
return self._dist.entry_points
|
||||
try:
|
||||
return self._dist.entry_points
|
||||
except ValueError as e:
|
||||
# Python 3.15+ validates entry points while parsing.
|
||||
raise InstallationError(
|
||||
f"Error parsing entry points for {self.raw_name}: {e}"
|
||||
) from e
|
||||
|
||||
def _metadata_impl(self) -> email.message.Message:
|
||||
# From Python 3.10+, importlib.metadata declares PackageMetadata as the
|
||||
@@ -207,7 +213,13 @@ class Distribution(BaseDistribution):
|
||||
# a ton of fields that we need, including get() and get_payload(). We
|
||||
# rely on the implementation that the object is actually a Message now,
|
||||
# until upstream can improve the protocol. (python/cpython#94952)
|
||||
return cast(email.message.Message, self._dist.metadata)
|
||||
metadata = self._dist.metadata
|
||||
# From Python 3.15+, importlib.metadata may return None when no
|
||||
# metadata file (METADATA or PKG-INFO) exists in the distribution
|
||||
# directory. (python/cpython#132947)
|
||||
if metadata is None:
|
||||
return email.message.Message()
|
||||
return cast(email.message.Message, metadata)
|
||||
|
||||
def iter_provided_extras(self) -> Iterable[NormalizedName]:
|
||||
return [
|
||||
|
||||
@@ -7,7 +7,6 @@ import pathlib
|
||||
import sys
|
||||
import zipfile
|
||||
from collections.abc import Iterator, Sequence
|
||||
from typing import Optional
|
||||
|
||||
from pip._vendor.packaging.utils import (
|
||||
InvalidWheelFilename,
|
||||
@@ -24,6 +23,10 @@ from ._dists import Distribution
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Used to avoid emitting duplicate invalid distribution metadata warnings for
|
||||
# the same dist-info directory.
|
||||
_warned_bad_metadata: set[BasePath | None] = set()
|
||||
|
||||
|
||||
def _looks_like_wheel(location: str) -> bool:
|
||||
if not location.endswith(WHEEL_EXTENSION):
|
||||
@@ -50,7 +53,7 @@ class _DistributionFinder:
|
||||
installations as well. It's useful feature, after all.
|
||||
"""
|
||||
|
||||
FoundResult = tuple[importlib.metadata.Distribution, Optional[BasePath]]
|
||||
FoundResult = tuple[importlib.metadata.Distribution, BasePath | None]
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._found_names: set[NormalizedName] = set()
|
||||
@@ -69,7 +72,9 @@ class _DistributionFinder:
|
||||
try:
|
||||
name = get_dist_canonical_name(dist)
|
||||
except BadMetadata as e:
|
||||
logger.warning("Skipping %s due to %s", info_location, e.reason)
|
||||
if info_location not in _warned_bad_metadata:
|
||||
logger.warning("Skipping %s due to %s", info_location, e.reason)
|
||||
_warned_bad_metadata.add(info_location)
|
||||
continue
|
||||
if name in self._found_names:
|
||||
continue
|
||||
|
||||
@@ -16,7 +16,12 @@ from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
||||
from pip._vendor.packaging.version import Version
|
||||
from pip._vendor.packaging.version import parse as parse_version
|
||||
|
||||
from pip._internal.exceptions import InvalidWheel, NoneMetadataError, UnsupportedWheel
|
||||
from pip._internal.exceptions import (
|
||||
InstallationError,
|
||||
InvalidWheel,
|
||||
NoneMetadataError,
|
||||
UnsupportedWheel,
|
||||
)
|
||||
from pip._internal.utils.egg_link import egg_link_path_from_location
|
||||
from pip._internal.utils.misc import display_path, normalize_path
|
||||
from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file
|
||||
@@ -208,7 +213,13 @@ class Distribution(BaseDistribution):
|
||||
return content
|
||||
|
||||
def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
|
||||
for group, entries in self._dist.get_entry_map().items():
|
||||
try:
|
||||
entry_map = self._dist.get_entry_map()
|
||||
except ValueError as e:
|
||||
raise InstallationError(
|
||||
f"Error parsing entry points for {self.raw_name}: {e}"
|
||||
) from e
|
||||
for group, entries in entry_map.items():
|
||||
for name, entry_point in entries.items():
|
||||
name, _, value = str(entry_point).partition("=")
|
||||
yield EntryPoint(name=name.strip(), value=value.strip(), group=group)
|
||||
|
||||
Reference in new issue
Block a user