Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- jupyter/lib/python3.11/site-packages/pip/_internal/commands/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/commands/__pycache__/uninstall.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/base.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/installed.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/sdist.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/wheel.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/collector.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/package_finder.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/sources.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/_json.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/base.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/pkg_resources.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__init__.py +6 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/_compat.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/_dists.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/_envs.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_compat.py +55 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_dists.py +227 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_envs.py +189 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/check.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/freeze.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/prepare.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__init__.py +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/build_tracker.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/metadata.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/metadata_editable.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/metadata_legacy.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/wheel.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/wheel_editable.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/wheel_legacy.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/build_tracker.py +139 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/metadata.py +39 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/metadata_editable.py +41 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/metadata_legacy.py +74 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/wheel.py +37 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/wheel_editable.py +46 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/wheel_legacy.py +102 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__init__.py +2 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__pycache__/__init__.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__pycache__/editable_legacy.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__pycache__/wheel.cpython-311.pyc +0 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/editable_legacy.py +46 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/wheel.py +734 -0
- jupyter/lib/python3.11/site-packages/pip/_internal/utils/__pycache__/__init__.cpython-311.pyc +0 -0
jupyter/lib/python3.11/site-packages/pip/_internal/commands/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (4.47 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/commands/__pycache__/uninstall.cpython-311.pyc
ADDED
|
Binary file (5.16 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.05 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (3.14 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/installed.cpython-311.pyc
ADDED
|
Binary file (1.86 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/sdist.cpython-311.pyc
ADDED
|
Binary file (9.38 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/distributions/__pycache__/wheel.cpython-311.pyc
ADDED
|
Binary file (2.45 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (256 Bytes). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/collector.cpython-311.pyc
ADDED
|
Binary file (24.6 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/package_finder.cpython-311.pyc
ADDED
|
Binary file (44.2 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/index/__pycache__/sources.cpython-311.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (6.52 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/_json.cpython-311.pyc
ADDED
|
Binary file (3.58 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (38.7 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/pkg_resources.cpython-311.pyc
ADDED
|
Binary file (17.6 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._dists import Distribution
|
| 2 |
+
from ._envs import Environment
|
| 3 |
+
|
| 4 |
+
__all__ = ["NAME", "Distribution", "Environment"]
|
| 5 |
+
|
| 6 |
+
NAME = "importlib"
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (407 Bytes). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/_compat.cpython-311.pyc
ADDED
|
Binary file (3.58 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/_dists.cpython-311.pyc
ADDED
|
Binary file (14.9 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/__pycache__/_envs.cpython-311.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_compat.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.metadata
|
| 2 |
+
from typing import Any, Optional, Protocol, cast
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class BadMetadata(ValueError):
|
| 6 |
+
def __init__(self, dist: importlib.metadata.Distribution, *, reason: str) -> None:
|
| 7 |
+
self.dist = dist
|
| 8 |
+
self.reason = reason
|
| 9 |
+
|
| 10 |
+
def __str__(self) -> str:
|
| 11 |
+
return f"Bad metadata in {self.dist} ({self.reason})"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class BasePath(Protocol):
|
| 15 |
+
"""A protocol that various path objects conform.
|
| 16 |
+
|
| 17 |
+
This exists because importlib.metadata uses both ``pathlib.Path`` and
|
| 18 |
+
``zipfile.Path``, and we need a common base for type hints (Union does not
|
| 19 |
+
work well since ``zipfile.Path`` is too new for our linter setup).
|
| 20 |
+
|
| 21 |
+
This does not mean to be exhaustive, but only contains things that present
|
| 22 |
+
in both classes *that we need*.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
@property
|
| 26 |
+
def name(self) -> str:
|
| 27 |
+
raise NotImplementedError()
|
| 28 |
+
|
| 29 |
+
@property
|
| 30 |
+
def parent(self) -> "BasePath":
|
| 31 |
+
raise NotImplementedError()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def get_info_location(d: importlib.metadata.Distribution) -> Optional[BasePath]:
|
| 35 |
+
"""Find the path to the distribution's metadata directory.
|
| 36 |
+
|
| 37 |
+
HACK: This relies on importlib.metadata's private ``_path`` attribute. Not
|
| 38 |
+
all distributions exist on disk, so importlib.metadata is correct to not
|
| 39 |
+
expose the attribute as public. But pip's code base is old and not as clean,
|
| 40 |
+
so we do this to avoid having to rewrite too many things. Hopefully we can
|
| 41 |
+
eliminate this some day.
|
| 42 |
+
"""
|
| 43 |
+
return getattr(d, "_path", None)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def get_dist_name(dist: importlib.metadata.Distribution) -> str:
|
| 47 |
+
"""Get the distribution's project name.
|
| 48 |
+
|
| 49 |
+
The ``name`` attribute is only available in Python 3.10 or later. We are
|
| 50 |
+
targeting exactly that, but Mypy does not know this.
|
| 51 |
+
"""
|
| 52 |
+
name = cast(Any, dist).name
|
| 53 |
+
if not isinstance(name, str):
|
| 54 |
+
raise BadMetadata(dist, reason="invalid metadata entry 'name'")
|
| 55 |
+
return name
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_dists.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import email.message
|
| 2 |
+
import importlib.metadata
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import zipfile
|
| 6 |
+
from typing import (
|
| 7 |
+
Collection,
|
| 8 |
+
Dict,
|
| 9 |
+
Iterable,
|
| 10 |
+
Iterator,
|
| 11 |
+
Mapping,
|
| 12 |
+
Optional,
|
| 13 |
+
Sequence,
|
| 14 |
+
cast,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
from pip._vendor.packaging.requirements import Requirement
|
| 18 |
+
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
| 19 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 20 |
+
|
| 21 |
+
from pip._internal.exceptions import InvalidWheel, UnsupportedWheel
|
| 22 |
+
from pip._internal.metadata.base import (
|
| 23 |
+
BaseDistribution,
|
| 24 |
+
BaseEntryPoint,
|
| 25 |
+
DistributionVersion,
|
| 26 |
+
InfoPath,
|
| 27 |
+
Wheel,
|
| 28 |
+
)
|
| 29 |
+
from pip._internal.utils.misc import normalize_path
|
| 30 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 31 |
+
from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file
|
| 32 |
+
|
| 33 |
+
from ._compat import BasePath, get_dist_name
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class WheelDistribution(importlib.metadata.Distribution):
|
| 37 |
+
"""An ``importlib.metadata.Distribution`` read from a wheel.
|
| 38 |
+
|
| 39 |
+
Although ``importlib.metadata.PathDistribution`` accepts ``zipfile.Path``,
|
| 40 |
+
its implementation is too "lazy" for pip's needs (we can't keep the ZipFile
|
| 41 |
+
handle open for the entire lifetime of the distribution object).
|
| 42 |
+
|
| 43 |
+
This implementation eagerly reads the entire metadata directory into the
|
| 44 |
+
memory instead, and operates from that.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
def __init__(
|
| 48 |
+
self,
|
| 49 |
+
files: Mapping[pathlib.PurePosixPath, bytes],
|
| 50 |
+
info_location: pathlib.PurePosixPath,
|
| 51 |
+
) -> None:
|
| 52 |
+
self._files = files
|
| 53 |
+
self.info_location = info_location
|
| 54 |
+
|
| 55 |
+
@classmethod
|
| 56 |
+
def from_zipfile(
|
| 57 |
+
cls,
|
| 58 |
+
zf: zipfile.ZipFile,
|
| 59 |
+
name: str,
|
| 60 |
+
location: str,
|
| 61 |
+
) -> "WheelDistribution":
|
| 62 |
+
info_dir, _ = parse_wheel(zf, name)
|
| 63 |
+
paths = (
|
| 64 |
+
(name, pathlib.PurePosixPath(name.split("/", 1)[-1]))
|
| 65 |
+
for name in zf.namelist()
|
| 66 |
+
if name.startswith(f"{info_dir}/")
|
| 67 |
+
)
|
| 68 |
+
files = {
|
| 69 |
+
relpath: read_wheel_metadata_file(zf, fullpath)
|
| 70 |
+
for fullpath, relpath in paths
|
| 71 |
+
}
|
| 72 |
+
info_location = pathlib.PurePosixPath(location, info_dir)
|
| 73 |
+
return cls(files, info_location)
|
| 74 |
+
|
| 75 |
+
def iterdir(self, path: InfoPath) -> Iterator[pathlib.PurePosixPath]:
|
| 76 |
+
# Only allow iterating through the metadata directory.
|
| 77 |
+
if pathlib.PurePosixPath(str(path)) in self._files:
|
| 78 |
+
return iter(self._files)
|
| 79 |
+
raise FileNotFoundError(path)
|
| 80 |
+
|
| 81 |
+
def read_text(self, filename: str) -> Optional[str]:
|
| 82 |
+
try:
|
| 83 |
+
data = self._files[pathlib.PurePosixPath(filename)]
|
| 84 |
+
except KeyError:
|
| 85 |
+
return None
|
| 86 |
+
try:
|
| 87 |
+
text = data.decode("utf-8")
|
| 88 |
+
except UnicodeDecodeError as e:
|
| 89 |
+
wheel = self.info_location.parent
|
| 90 |
+
error = f"Error decoding metadata for {wheel}: {e} in {filename} file"
|
| 91 |
+
raise UnsupportedWheel(error)
|
| 92 |
+
return text
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class Distribution(BaseDistribution):
|
| 96 |
+
def __init__(
|
| 97 |
+
self,
|
| 98 |
+
dist: importlib.metadata.Distribution,
|
| 99 |
+
info_location: Optional[BasePath],
|
| 100 |
+
installed_location: Optional[BasePath],
|
| 101 |
+
) -> None:
|
| 102 |
+
self._dist = dist
|
| 103 |
+
self._info_location = info_location
|
| 104 |
+
self._installed_location = installed_location
|
| 105 |
+
|
| 106 |
+
@classmethod
|
| 107 |
+
def from_directory(cls, directory: str) -> BaseDistribution:
|
| 108 |
+
info_location = pathlib.Path(directory)
|
| 109 |
+
dist = importlib.metadata.Distribution.at(info_location)
|
| 110 |
+
return cls(dist, info_location, info_location.parent)
|
| 111 |
+
|
| 112 |
+
@classmethod
|
| 113 |
+
def from_metadata_file_contents(
|
| 114 |
+
cls,
|
| 115 |
+
metadata_contents: bytes,
|
| 116 |
+
filename: str,
|
| 117 |
+
project_name: str,
|
| 118 |
+
) -> BaseDistribution:
|
| 119 |
+
# Generate temp dir to contain the metadata file, and write the file contents.
|
| 120 |
+
temp_dir = pathlib.Path(
|
| 121 |
+
TempDirectory(kind="metadata", globally_managed=True).path
|
| 122 |
+
)
|
| 123 |
+
metadata_path = temp_dir / "METADATA"
|
| 124 |
+
metadata_path.write_bytes(metadata_contents)
|
| 125 |
+
# Construct dist pointing to the newly created directory.
|
| 126 |
+
dist = importlib.metadata.Distribution.at(metadata_path.parent)
|
| 127 |
+
return cls(dist, metadata_path.parent, None)
|
| 128 |
+
|
| 129 |
+
@classmethod
|
| 130 |
+
def from_wheel(cls, wheel: Wheel, name: str) -> BaseDistribution:
|
| 131 |
+
try:
|
| 132 |
+
with wheel.as_zipfile() as zf:
|
| 133 |
+
dist = WheelDistribution.from_zipfile(zf, name, wheel.location)
|
| 134 |
+
except zipfile.BadZipFile as e:
|
| 135 |
+
raise InvalidWheel(wheel.location, name) from e
|
| 136 |
+
except UnsupportedWheel as e:
|
| 137 |
+
raise UnsupportedWheel(f"{name} has an invalid wheel, {e}")
|
| 138 |
+
return cls(dist, dist.info_location, pathlib.PurePosixPath(wheel.location))
|
| 139 |
+
|
| 140 |
+
@property
|
| 141 |
+
def location(self) -> Optional[str]:
|
| 142 |
+
if self._info_location is None:
|
| 143 |
+
return None
|
| 144 |
+
return str(self._info_location.parent)
|
| 145 |
+
|
| 146 |
+
@property
|
| 147 |
+
def info_location(self) -> Optional[str]:
|
| 148 |
+
if self._info_location is None:
|
| 149 |
+
return None
|
| 150 |
+
return str(self._info_location)
|
| 151 |
+
|
| 152 |
+
@property
|
| 153 |
+
def installed_location(self) -> Optional[str]:
|
| 154 |
+
if self._installed_location is None:
|
| 155 |
+
return None
|
| 156 |
+
return normalize_path(str(self._installed_location))
|
| 157 |
+
|
| 158 |
+
def _get_dist_name_from_location(self) -> Optional[str]:
|
| 159 |
+
"""Try to get the name from the metadata directory name.
|
| 160 |
+
|
| 161 |
+
This is much faster than reading metadata.
|
| 162 |
+
"""
|
| 163 |
+
if self._info_location is None:
|
| 164 |
+
return None
|
| 165 |
+
stem, suffix = os.path.splitext(self._info_location.name)
|
| 166 |
+
if suffix not in (".dist-info", ".egg-info"):
|
| 167 |
+
return None
|
| 168 |
+
return stem.split("-", 1)[0]
|
| 169 |
+
|
| 170 |
+
@property
|
| 171 |
+
def canonical_name(self) -> NormalizedName:
|
| 172 |
+
name = self._get_dist_name_from_location() or get_dist_name(self._dist)
|
| 173 |
+
return canonicalize_name(name)
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
def version(self) -> DistributionVersion:
|
| 177 |
+
return parse_version(self._dist.version)
|
| 178 |
+
|
| 179 |
+
def is_file(self, path: InfoPath) -> bool:
|
| 180 |
+
return self._dist.read_text(str(path)) is not None
|
| 181 |
+
|
| 182 |
+
def iter_distutils_script_names(self) -> Iterator[str]:
|
| 183 |
+
# A distutils installation is always "flat" (not in e.g. egg form), so
|
| 184 |
+
# if this distribution's info location is NOT a pathlib.Path (but e.g.
|
| 185 |
+
# zipfile.Path), it can never contain any distutils scripts.
|
| 186 |
+
if not isinstance(self._info_location, pathlib.Path):
|
| 187 |
+
return
|
| 188 |
+
for child in self._info_location.joinpath("scripts").iterdir():
|
| 189 |
+
yield child.name
|
| 190 |
+
|
| 191 |
+
def read_text(self, path: InfoPath) -> str:
|
| 192 |
+
content = self._dist.read_text(str(path))
|
| 193 |
+
if content is None:
|
| 194 |
+
raise FileNotFoundError(path)
|
| 195 |
+
return content
|
| 196 |
+
|
| 197 |
+
def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
|
| 198 |
+
# importlib.metadata's EntryPoint structure sasitfies BaseEntryPoint.
|
| 199 |
+
return self._dist.entry_points
|
| 200 |
+
|
| 201 |
+
def _metadata_impl(self) -> email.message.Message:
|
| 202 |
+
# From Python 3.10+, importlib.metadata declares PackageMetadata as the
|
| 203 |
+
# return type. This protocol is unfortunately a disaster now and misses
|
| 204 |
+
# a ton of fields that we need, including get() and get_payload(). We
|
| 205 |
+
# rely on the implementation that the object is actually a Message now,
|
| 206 |
+
# until upstream can improve the protocol. (python/cpython#94952)
|
| 207 |
+
return cast(email.message.Message, self._dist.metadata)
|
| 208 |
+
|
| 209 |
+
def iter_provided_extras(self) -> Iterable[str]:
|
| 210 |
+
return self.metadata.get_all("Provides-Extra", [])
|
| 211 |
+
|
| 212 |
+
def is_extra_provided(self, extra: str) -> bool:
|
| 213 |
+
return any(
|
| 214 |
+
canonicalize_name(provided_extra) == canonicalize_name(extra)
|
| 215 |
+
for provided_extra in self.metadata.get_all("Provides-Extra", [])
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]:
|
| 219 |
+
contexts: Sequence[Dict[str, str]] = [{"extra": e} for e in extras]
|
| 220 |
+
for req_string in self.metadata.get_all("Requires-Dist", []):
|
| 221 |
+
req = Requirement(req_string)
|
| 222 |
+
if not req.marker:
|
| 223 |
+
yield req
|
| 224 |
+
elif not extras and req.marker.evaluate({"extra": ""}):
|
| 225 |
+
yield req
|
| 226 |
+
elif any(req.marker.evaluate(context) for context in contexts):
|
| 227 |
+
yield req
|
jupyter/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_envs.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import importlib.metadata
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import pathlib
|
| 6 |
+
import sys
|
| 7 |
+
import zipfile
|
| 8 |
+
import zipimport
|
| 9 |
+
from typing import Iterator, List, Optional, Sequence, Set, Tuple
|
| 10 |
+
|
| 11 |
+
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
| 12 |
+
|
| 13 |
+
from pip._internal.metadata.base import BaseDistribution, BaseEnvironment
|
| 14 |
+
from pip._internal.models.wheel import Wheel
|
| 15 |
+
from pip._internal.utils.deprecation import deprecated
|
| 16 |
+
from pip._internal.utils.filetypes import WHEEL_EXTENSION
|
| 17 |
+
|
| 18 |
+
from ._compat import BadMetadata, BasePath, get_dist_name, get_info_location
|
| 19 |
+
from ._dists import Distribution
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _looks_like_wheel(location: str) -> bool:
|
| 25 |
+
if not location.endswith(WHEEL_EXTENSION):
|
| 26 |
+
return False
|
| 27 |
+
if not os.path.isfile(location):
|
| 28 |
+
return False
|
| 29 |
+
if not Wheel.wheel_file_re.match(os.path.basename(location)):
|
| 30 |
+
return False
|
| 31 |
+
return zipfile.is_zipfile(location)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class _DistributionFinder:
|
| 35 |
+
"""Finder to locate distributions.
|
| 36 |
+
|
| 37 |
+
The main purpose of this class is to memoize found distributions' names, so
|
| 38 |
+
only one distribution is returned for each package name. At lot of pip code
|
| 39 |
+
assumes this (because it is setuptools's behavior), and not doing the same
|
| 40 |
+
can potentially cause a distribution in lower precedence path to override a
|
| 41 |
+
higher precedence one if the caller is not careful.
|
| 42 |
+
|
| 43 |
+
Eventually we probably want to make it possible to see lower precedence
|
| 44 |
+
installations as well. It's useful feature, after all.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
FoundResult = Tuple[importlib.metadata.Distribution, Optional[BasePath]]
|
| 48 |
+
|
| 49 |
+
def __init__(self) -> None:
|
| 50 |
+
self._found_names: Set[NormalizedName] = set()
|
| 51 |
+
|
| 52 |
+
def _find_impl(self, location: str) -> Iterator[FoundResult]:
|
| 53 |
+
"""Find distributions in a location."""
|
| 54 |
+
# Skip looking inside a wheel. Since a package inside a wheel is not
|
| 55 |
+
# always valid (due to .data directories etc.), its .dist-info entry
|
| 56 |
+
# should not be considered an installed distribution.
|
| 57 |
+
if _looks_like_wheel(location):
|
| 58 |
+
return
|
| 59 |
+
# To know exactly where we find a distribution, we have to feed in the
|
| 60 |
+
# paths one by one, instead of dumping the list to importlib.metadata.
|
| 61 |
+
for dist in importlib.metadata.distributions(path=[location]):
|
| 62 |
+
info_location = get_info_location(dist)
|
| 63 |
+
try:
|
| 64 |
+
raw_name = get_dist_name(dist)
|
| 65 |
+
except BadMetadata as e:
|
| 66 |
+
logger.warning("Skipping %s due to %s", info_location, e.reason)
|
| 67 |
+
continue
|
| 68 |
+
normalized_name = canonicalize_name(raw_name)
|
| 69 |
+
if normalized_name in self._found_names:
|
| 70 |
+
continue
|
| 71 |
+
self._found_names.add(normalized_name)
|
| 72 |
+
yield dist, info_location
|
| 73 |
+
|
| 74 |
+
def find(self, location: str) -> Iterator[BaseDistribution]:
|
| 75 |
+
"""Find distributions in a location.
|
| 76 |
+
|
| 77 |
+
The path can be either a directory, or a ZIP archive.
|
| 78 |
+
"""
|
| 79 |
+
for dist, info_location in self._find_impl(location):
|
| 80 |
+
if info_location is None:
|
| 81 |
+
installed_location: Optional[BasePath] = None
|
| 82 |
+
else:
|
| 83 |
+
installed_location = info_location.parent
|
| 84 |
+
yield Distribution(dist, info_location, installed_location)
|
| 85 |
+
|
| 86 |
+
def find_linked(self, location: str) -> Iterator[BaseDistribution]:
|
| 87 |
+
"""Read location in egg-link files and return distributions in there.
|
| 88 |
+
|
| 89 |
+
The path should be a directory; otherwise this returns nothing. This
|
| 90 |
+
follows how setuptools does this for compatibility. The first non-empty
|
| 91 |
+
line in the egg-link is read as a path (resolved against the egg-link's
|
| 92 |
+
containing directory if relative). Distributions found at that linked
|
| 93 |
+
location are returned.
|
| 94 |
+
"""
|
| 95 |
+
path = pathlib.Path(location)
|
| 96 |
+
if not path.is_dir():
|
| 97 |
+
return
|
| 98 |
+
for child in path.iterdir():
|
| 99 |
+
if child.suffix != ".egg-link":
|
| 100 |
+
continue
|
| 101 |
+
with child.open() as f:
|
| 102 |
+
lines = (line.strip() for line in f)
|
| 103 |
+
target_rel = next((line for line in lines if line), "")
|
| 104 |
+
if not target_rel:
|
| 105 |
+
continue
|
| 106 |
+
target_location = str(path.joinpath(target_rel))
|
| 107 |
+
for dist, info_location in self._find_impl(target_location):
|
| 108 |
+
yield Distribution(dist, info_location, path)
|
| 109 |
+
|
| 110 |
+
def _find_eggs_in_dir(self, location: str) -> Iterator[BaseDistribution]:
|
| 111 |
+
from pip._vendor.pkg_resources import find_distributions
|
| 112 |
+
|
| 113 |
+
from pip._internal.metadata import pkg_resources as legacy
|
| 114 |
+
|
| 115 |
+
with os.scandir(location) as it:
|
| 116 |
+
for entry in it:
|
| 117 |
+
if not entry.name.endswith(".egg"):
|
| 118 |
+
continue
|
| 119 |
+
for dist in find_distributions(entry.path):
|
| 120 |
+
yield legacy.Distribution(dist)
|
| 121 |
+
|
| 122 |
+
def _find_eggs_in_zip(self, location: str) -> Iterator[BaseDistribution]:
|
| 123 |
+
from pip._vendor.pkg_resources import find_eggs_in_zip
|
| 124 |
+
|
| 125 |
+
from pip._internal.metadata import pkg_resources as legacy
|
| 126 |
+
|
| 127 |
+
try:
|
| 128 |
+
importer = zipimport.zipimporter(location)
|
| 129 |
+
except zipimport.ZipImportError:
|
| 130 |
+
return
|
| 131 |
+
for dist in find_eggs_in_zip(importer, location):
|
| 132 |
+
yield legacy.Distribution(dist)
|
| 133 |
+
|
| 134 |
+
def find_eggs(self, location: str) -> Iterator[BaseDistribution]:
|
| 135 |
+
"""Find eggs in a location.
|
| 136 |
+
|
| 137 |
+
This actually uses the old *pkg_resources* backend. We likely want to
|
| 138 |
+
deprecate this so we can eventually remove the *pkg_resources*
|
| 139 |
+
dependency entirely. Before that, this should first emit a deprecation
|
| 140 |
+
warning for some versions when using the fallback since importing
|
| 141 |
+
*pkg_resources* is slow for those who don't need it.
|
| 142 |
+
"""
|
| 143 |
+
if os.path.isdir(location):
|
| 144 |
+
yield from self._find_eggs_in_dir(location)
|
| 145 |
+
if zipfile.is_zipfile(location):
|
| 146 |
+
yield from self._find_eggs_in_zip(location)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@functools.lru_cache(maxsize=None) # Warn a distribution exactly once.
|
| 150 |
+
def _emit_egg_deprecation(location: Optional[str]) -> None:
|
| 151 |
+
deprecated(
|
| 152 |
+
reason=f"Loading egg at {location} is deprecated.",
|
| 153 |
+
replacement="to use pip for package installation.",
|
| 154 |
+
gone_in="24.3",
|
| 155 |
+
issue=12330,
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class Environment(BaseEnvironment):
|
| 160 |
+
def __init__(self, paths: Sequence[str]) -> None:
|
| 161 |
+
self._paths = paths
|
| 162 |
+
|
| 163 |
+
@classmethod
|
| 164 |
+
def default(cls) -> BaseEnvironment:
|
| 165 |
+
return cls(sys.path)
|
| 166 |
+
|
| 167 |
+
@classmethod
|
| 168 |
+
def from_paths(cls, paths: Optional[List[str]]) -> BaseEnvironment:
|
| 169 |
+
if paths is None:
|
| 170 |
+
return cls(sys.path)
|
| 171 |
+
return cls(paths)
|
| 172 |
+
|
| 173 |
+
def _iter_distributions(self) -> Iterator[BaseDistribution]:
|
| 174 |
+
finder = _DistributionFinder()
|
| 175 |
+
for location in self._paths:
|
| 176 |
+
yield from finder.find(location)
|
| 177 |
+
for dist in finder.find_eggs(location):
|
| 178 |
+
_emit_egg_deprecation(dist.location)
|
| 179 |
+
yield dist
|
| 180 |
+
# This must go last because that's how pkg_resources tie-breaks.
|
| 181 |
+
yield from finder.find_linked(location)
|
| 182 |
+
|
| 183 |
+
def get_distribution(self, name: str) -> Optional[BaseDistribution]:
|
| 184 |
+
matches = (
|
| 185 |
+
distribution
|
| 186 |
+
for distribution in self.iter_all_distributions()
|
| 187 |
+
if distribution.canonical_name == canonicalize_name(name)
|
| 188 |
+
)
|
| 189 |
+
return next(matches, None)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (216 Bytes). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/check.cpython-311.pyc
ADDED
|
Binary file (8.48 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/freeze.cpython-311.pyc
ADDED
|
Binary file (11.6 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/__pycache__/prepare.cpython-311.pyc
ADDED
|
Binary file (27.8 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__init__.py
ADDED
|
File without changes
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (222 Bytes). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/build_tracker.cpython-311.pyc
ADDED
|
Binary file (8.94 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/metadata.cpython-311.pyc
ADDED
|
Binary file (2.29 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/metadata_editable.cpython-311.pyc
ADDED
|
Binary file (2.33 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/metadata_legacy.cpython-311.pyc
ADDED
|
Binary file (3.73 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/wheel.cpython-311.pyc
ADDED
|
Binary file (1.96 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/wheel_editable.cpython-311.pyc
ADDED
|
Binary file (2.4 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/__pycache__/wheel_legacy.cpython-311.pyc
ADDED
|
Binary file (4.51 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/build_tracker.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
+
import hashlib
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
from types import TracebackType
|
| 6 |
+
from typing import Dict, Generator, Optional, Set, Type, Union
|
| 7 |
+
|
| 8 |
+
from pip._internal.models.link import Link
|
| 9 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 10 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 11 |
+
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@contextlib.contextmanager
|
| 16 |
+
def update_env_context_manager(**changes: str) -> Generator[None, None, None]:
|
| 17 |
+
target = os.environ
|
| 18 |
+
|
| 19 |
+
# Save values from the target and change them.
|
| 20 |
+
non_existent_marker = object()
|
| 21 |
+
saved_values: Dict[str, Union[object, str]] = {}
|
| 22 |
+
for name, new_value in changes.items():
|
| 23 |
+
try:
|
| 24 |
+
saved_values[name] = target[name]
|
| 25 |
+
except KeyError:
|
| 26 |
+
saved_values[name] = non_existent_marker
|
| 27 |
+
target[name] = new_value
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
yield
|
| 31 |
+
finally:
|
| 32 |
+
# Restore original values in the target.
|
| 33 |
+
for name, original_value in saved_values.items():
|
| 34 |
+
if original_value is non_existent_marker:
|
| 35 |
+
del target[name]
|
| 36 |
+
else:
|
| 37 |
+
assert isinstance(original_value, str) # for mypy
|
| 38 |
+
target[name] = original_value
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@contextlib.contextmanager
|
| 42 |
+
def get_build_tracker() -> Generator["BuildTracker", None, None]:
|
| 43 |
+
root = os.environ.get("PIP_BUILD_TRACKER")
|
| 44 |
+
with contextlib.ExitStack() as ctx:
|
| 45 |
+
if root is None:
|
| 46 |
+
root = ctx.enter_context(TempDirectory(kind="build-tracker")).path
|
| 47 |
+
ctx.enter_context(update_env_context_manager(PIP_BUILD_TRACKER=root))
|
| 48 |
+
logger.debug("Initialized build tracking at %s", root)
|
| 49 |
+
|
| 50 |
+
with BuildTracker(root) as tracker:
|
| 51 |
+
yield tracker
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class TrackerId(str):
|
| 55 |
+
"""Uniquely identifying string provided to the build tracker."""
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class BuildTracker:
|
| 59 |
+
"""Ensure that an sdist cannot request itself as a setup requirement.
|
| 60 |
+
|
| 61 |
+
When an sdist is prepared, it identifies its setup requirements in the
|
| 62 |
+
context of ``BuildTracker.track()``. If a requirement shows up recursively, this
|
| 63 |
+
raises an exception.
|
| 64 |
+
|
| 65 |
+
This stops fork bombs embedded in malicious packages."""
|
| 66 |
+
|
| 67 |
+
def __init__(self, root: str) -> None:
|
| 68 |
+
self._root = root
|
| 69 |
+
self._entries: Dict[TrackerId, InstallRequirement] = {}
|
| 70 |
+
logger.debug("Created build tracker: %s", self._root)
|
| 71 |
+
|
| 72 |
+
def __enter__(self) -> "BuildTracker":
|
| 73 |
+
logger.debug("Entered build tracker: %s", self._root)
|
| 74 |
+
return self
|
| 75 |
+
|
| 76 |
+
def __exit__(
|
| 77 |
+
self,
|
| 78 |
+
exc_type: Optional[Type[BaseException]],
|
| 79 |
+
exc_val: Optional[BaseException],
|
| 80 |
+
exc_tb: Optional[TracebackType],
|
| 81 |
+
) -> None:
|
| 82 |
+
self.cleanup()
|
| 83 |
+
|
| 84 |
+
def _entry_path(self, key: TrackerId) -> str:
|
| 85 |
+
hashed = hashlib.sha224(key.encode()).hexdigest()
|
| 86 |
+
return os.path.join(self._root, hashed)
|
| 87 |
+
|
| 88 |
+
def add(self, req: InstallRequirement, key: TrackerId) -> None:
|
| 89 |
+
"""Add an InstallRequirement to build tracking."""
|
| 90 |
+
|
| 91 |
+
# Get the file to write information about this requirement.
|
| 92 |
+
entry_path = self._entry_path(key)
|
| 93 |
+
|
| 94 |
+
# Try reading from the file. If it exists and can be read from, a build
|
| 95 |
+
# is already in progress, so a LookupError is raised.
|
| 96 |
+
try:
|
| 97 |
+
with open(entry_path) as fp:
|
| 98 |
+
contents = fp.read()
|
| 99 |
+
except FileNotFoundError:
|
| 100 |
+
pass
|
| 101 |
+
else:
|
| 102 |
+
message = "{} is already being built: {}".format(req.link, contents)
|
| 103 |
+
raise LookupError(message)
|
| 104 |
+
|
| 105 |
+
# If we're here, req should really not be building already.
|
| 106 |
+
assert key not in self._entries
|
| 107 |
+
|
| 108 |
+
# Start tracking this requirement.
|
| 109 |
+
with open(entry_path, "w", encoding="utf-8") as fp:
|
| 110 |
+
fp.write(str(req))
|
| 111 |
+
self._entries[key] = req
|
| 112 |
+
|
| 113 |
+
logger.debug("Added %s to build tracker %r", req, self._root)
|
| 114 |
+
|
| 115 |
+
def remove(self, req: InstallRequirement, key: TrackerId) -> None:
|
| 116 |
+
"""Remove an InstallRequirement from build tracking."""
|
| 117 |
+
|
| 118 |
+
# Delete the created file and the corresponding entry.
|
| 119 |
+
os.unlink(self._entry_path(key))
|
| 120 |
+
del self._entries[key]
|
| 121 |
+
|
| 122 |
+
logger.debug("Removed %s from build tracker %r", req, self._root)
|
| 123 |
+
|
| 124 |
+
def cleanup(self) -> None:
|
| 125 |
+
for key, req in list(self._entries.items()):
|
| 126 |
+
self.remove(req, key)
|
| 127 |
+
|
| 128 |
+
logger.debug("Removed build tracker: %r", self._root)
|
| 129 |
+
|
| 130 |
+
@contextlib.contextmanager
|
| 131 |
+
def track(self, req: InstallRequirement, key: str) -> Generator[None, None, None]:
|
| 132 |
+
"""Ensure that `key` cannot install itself as a setup requirement.
|
| 133 |
+
|
| 134 |
+
:raises LookupError: If `key` was already provided in a parent invocation of
|
| 135 |
+
the context introduced by this method."""
|
| 136 |
+
tracker_id = TrackerId(key)
|
| 137 |
+
self.add(req, tracker_id)
|
| 138 |
+
yield
|
| 139 |
+
self.remove(req, tracker_id)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/metadata.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Metadata generation logic for source distributions.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from pip._vendor.pyproject_hooks import BuildBackendHookCaller
|
| 7 |
+
|
| 8 |
+
from pip._internal.build_env import BuildEnvironment
|
| 9 |
+
from pip._internal.exceptions import (
|
| 10 |
+
InstallationSubprocessError,
|
| 11 |
+
MetadataGenerationFailed,
|
| 12 |
+
)
|
| 13 |
+
from pip._internal.utils.subprocess import runner_with_spinner_message
|
| 14 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def generate_metadata(
|
| 18 |
+
build_env: BuildEnvironment, backend: BuildBackendHookCaller, details: str
|
| 19 |
+
) -> str:
|
| 20 |
+
"""Generate metadata using mechanisms described in PEP 517.
|
| 21 |
+
|
| 22 |
+
Returns the generated metadata directory.
|
| 23 |
+
"""
|
| 24 |
+
metadata_tmpdir = TempDirectory(kind="modern-metadata", globally_managed=True)
|
| 25 |
+
|
| 26 |
+
metadata_dir = metadata_tmpdir.path
|
| 27 |
+
|
| 28 |
+
with build_env:
|
| 29 |
+
# Note that BuildBackendHookCaller implements a fallback for
|
| 30 |
+
# prepare_metadata_for_build_wheel, so we don't have to
|
| 31 |
+
# consider the possibility that this hook doesn't exist.
|
| 32 |
+
runner = runner_with_spinner_message("Preparing metadata (pyproject.toml)")
|
| 33 |
+
with backend.subprocess_runner(runner):
|
| 34 |
+
try:
|
| 35 |
+
distinfo_dir = backend.prepare_metadata_for_build_wheel(metadata_dir)
|
| 36 |
+
except InstallationSubprocessError as error:
|
| 37 |
+
raise MetadataGenerationFailed(package_details=details) from error
|
| 38 |
+
|
| 39 |
+
return os.path.join(metadata_dir, distinfo_dir)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/metadata_editable.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Metadata generation logic for source distributions.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from pip._vendor.pyproject_hooks import BuildBackendHookCaller
|
| 7 |
+
|
| 8 |
+
from pip._internal.build_env import BuildEnvironment
|
| 9 |
+
from pip._internal.exceptions import (
|
| 10 |
+
InstallationSubprocessError,
|
| 11 |
+
MetadataGenerationFailed,
|
| 12 |
+
)
|
| 13 |
+
from pip._internal.utils.subprocess import runner_with_spinner_message
|
| 14 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def generate_editable_metadata(
|
| 18 |
+
build_env: BuildEnvironment, backend: BuildBackendHookCaller, details: str
|
| 19 |
+
) -> str:
|
| 20 |
+
"""Generate metadata using mechanisms described in PEP 660.
|
| 21 |
+
|
| 22 |
+
Returns the generated metadata directory.
|
| 23 |
+
"""
|
| 24 |
+
metadata_tmpdir = TempDirectory(kind="modern-metadata", globally_managed=True)
|
| 25 |
+
|
| 26 |
+
metadata_dir = metadata_tmpdir.path
|
| 27 |
+
|
| 28 |
+
with build_env:
|
| 29 |
+
# Note that BuildBackendHookCaller implements a fallback for
|
| 30 |
+
# prepare_metadata_for_build_wheel/editable, so we don't have to
|
| 31 |
+
# consider the possibility that this hook doesn't exist.
|
| 32 |
+
runner = runner_with_spinner_message(
|
| 33 |
+
"Preparing editable metadata (pyproject.toml)"
|
| 34 |
+
)
|
| 35 |
+
with backend.subprocess_runner(runner):
|
| 36 |
+
try:
|
| 37 |
+
distinfo_dir = backend.prepare_metadata_for_build_editable(metadata_dir)
|
| 38 |
+
except InstallationSubprocessError as error:
|
| 39 |
+
raise MetadataGenerationFailed(package_details=details) from error
|
| 40 |
+
|
| 41 |
+
return os.path.join(metadata_dir, distinfo_dir)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/metadata_legacy.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Metadata generation logic for legacy source distributions.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
from pip._internal.build_env import BuildEnvironment
|
| 8 |
+
from pip._internal.cli.spinners import open_spinner
|
| 9 |
+
from pip._internal.exceptions import (
|
| 10 |
+
InstallationError,
|
| 11 |
+
InstallationSubprocessError,
|
| 12 |
+
MetadataGenerationFailed,
|
| 13 |
+
)
|
| 14 |
+
from pip._internal.utils.setuptools_build import make_setuptools_egg_info_args
|
| 15 |
+
from pip._internal.utils.subprocess import call_subprocess
|
| 16 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 17 |
+
|
| 18 |
+
logger = logging.getLogger(__name__)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _find_egg_info(directory: str) -> str:
|
| 22 |
+
"""Find an .egg-info subdirectory in `directory`."""
|
| 23 |
+
filenames = [f for f in os.listdir(directory) if f.endswith(".egg-info")]
|
| 24 |
+
|
| 25 |
+
if not filenames:
|
| 26 |
+
raise InstallationError(f"No .egg-info directory found in {directory}")
|
| 27 |
+
|
| 28 |
+
if len(filenames) > 1:
|
| 29 |
+
raise InstallationError(
|
| 30 |
+
"More than one .egg-info directory found in {}".format(directory)
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
return os.path.join(directory, filenames[0])
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def generate_metadata(
|
| 37 |
+
build_env: BuildEnvironment,
|
| 38 |
+
setup_py_path: str,
|
| 39 |
+
source_dir: str,
|
| 40 |
+
isolated: bool,
|
| 41 |
+
details: str,
|
| 42 |
+
) -> str:
|
| 43 |
+
"""Generate metadata using setup.py-based defacto mechanisms.
|
| 44 |
+
|
| 45 |
+
Returns the generated metadata directory.
|
| 46 |
+
"""
|
| 47 |
+
logger.debug(
|
| 48 |
+
"Running setup.py (path:%s) egg_info for package %s",
|
| 49 |
+
setup_py_path,
|
| 50 |
+
details,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
egg_info_dir = TempDirectory(kind="pip-egg-info", globally_managed=True).path
|
| 54 |
+
|
| 55 |
+
args = make_setuptools_egg_info_args(
|
| 56 |
+
setup_py_path,
|
| 57 |
+
egg_info_dir=egg_info_dir,
|
| 58 |
+
no_user_config=isolated,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
with build_env:
|
| 62 |
+
with open_spinner("Preparing metadata (setup.py)") as spinner:
|
| 63 |
+
try:
|
| 64 |
+
call_subprocess(
|
| 65 |
+
args,
|
| 66 |
+
cwd=source_dir,
|
| 67 |
+
command_desc="python setup.py egg_info",
|
| 68 |
+
spinner=spinner,
|
| 69 |
+
)
|
| 70 |
+
except InstallationSubprocessError as error:
|
| 71 |
+
raise MetadataGenerationFailed(package_details=details) from error
|
| 72 |
+
|
| 73 |
+
# Return the .egg-info directory.
|
| 74 |
+
return _find_egg_info(egg_info_dir)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/wheel.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
from pip._vendor.pyproject_hooks import BuildBackendHookCaller
|
| 6 |
+
|
| 7 |
+
from pip._internal.utils.subprocess import runner_with_spinner_message
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def build_wheel_pep517(
|
| 13 |
+
name: str,
|
| 14 |
+
backend: BuildBackendHookCaller,
|
| 15 |
+
metadata_directory: str,
|
| 16 |
+
tempd: str,
|
| 17 |
+
) -> Optional[str]:
|
| 18 |
+
"""Build one InstallRequirement using the PEP 517 build process.
|
| 19 |
+
|
| 20 |
+
Returns path to wheel if successfully built. Otherwise, returns None.
|
| 21 |
+
"""
|
| 22 |
+
assert metadata_directory is not None
|
| 23 |
+
try:
|
| 24 |
+
logger.debug("Destination directory: %s", tempd)
|
| 25 |
+
|
| 26 |
+
runner = runner_with_spinner_message(
|
| 27 |
+
f"Building wheel for {name} (pyproject.toml)"
|
| 28 |
+
)
|
| 29 |
+
with backend.subprocess_runner(runner):
|
| 30 |
+
wheel_name = backend.build_wheel(
|
| 31 |
+
tempd,
|
| 32 |
+
metadata_directory=metadata_directory,
|
| 33 |
+
)
|
| 34 |
+
except Exception:
|
| 35 |
+
logger.error("Failed building wheel for %s", name)
|
| 36 |
+
return None
|
| 37 |
+
return os.path.join(tempd, wheel_name)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/wheel_editable.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
from pip._vendor.pyproject_hooks import BuildBackendHookCaller, HookMissing
|
| 6 |
+
|
| 7 |
+
from pip._internal.utils.subprocess import runner_with_spinner_message
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def build_wheel_editable(
|
| 13 |
+
name: str,
|
| 14 |
+
backend: BuildBackendHookCaller,
|
| 15 |
+
metadata_directory: str,
|
| 16 |
+
tempd: str,
|
| 17 |
+
) -> Optional[str]:
|
| 18 |
+
"""Build one InstallRequirement using the PEP 660 build process.
|
| 19 |
+
|
| 20 |
+
Returns path to wheel if successfully built. Otherwise, returns None.
|
| 21 |
+
"""
|
| 22 |
+
assert metadata_directory is not None
|
| 23 |
+
try:
|
| 24 |
+
logger.debug("Destination directory: %s", tempd)
|
| 25 |
+
|
| 26 |
+
runner = runner_with_spinner_message(
|
| 27 |
+
f"Building editable for {name} (pyproject.toml)"
|
| 28 |
+
)
|
| 29 |
+
with backend.subprocess_runner(runner):
|
| 30 |
+
try:
|
| 31 |
+
wheel_name = backend.build_editable(
|
| 32 |
+
tempd,
|
| 33 |
+
metadata_directory=metadata_directory,
|
| 34 |
+
)
|
| 35 |
+
except HookMissing as e:
|
| 36 |
+
logger.error(
|
| 37 |
+
"Cannot build editable %s because the build "
|
| 38 |
+
"backend does not have the %s hook",
|
| 39 |
+
name,
|
| 40 |
+
e,
|
| 41 |
+
)
|
| 42 |
+
return None
|
| 43 |
+
except Exception:
|
| 44 |
+
logger.error("Failed building editable for %s", name)
|
| 45 |
+
return None
|
| 46 |
+
return os.path.join(tempd, wheel_name)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/build/wheel_legacy.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os.path
|
| 3 |
+
from typing import List, Optional
|
| 4 |
+
|
| 5 |
+
from pip._internal.cli.spinners import open_spinner
|
| 6 |
+
from pip._internal.utils.setuptools_build import make_setuptools_bdist_wheel_args
|
| 7 |
+
from pip._internal.utils.subprocess import call_subprocess, format_command_args
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def format_command_result(
|
| 13 |
+
command_args: List[str],
|
| 14 |
+
command_output: str,
|
| 15 |
+
) -> str:
|
| 16 |
+
"""Format command information for logging."""
|
| 17 |
+
command_desc = format_command_args(command_args)
|
| 18 |
+
text = f"Command arguments: {command_desc}\n"
|
| 19 |
+
|
| 20 |
+
if not command_output:
|
| 21 |
+
text += "Command output: None"
|
| 22 |
+
elif logger.getEffectiveLevel() > logging.DEBUG:
|
| 23 |
+
text += "Command output: [use --verbose to show]"
|
| 24 |
+
else:
|
| 25 |
+
if not command_output.endswith("\n"):
|
| 26 |
+
command_output += "\n"
|
| 27 |
+
text += f"Command output:\n{command_output}"
|
| 28 |
+
|
| 29 |
+
return text
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def get_legacy_build_wheel_path(
|
| 33 |
+
names: List[str],
|
| 34 |
+
temp_dir: str,
|
| 35 |
+
name: str,
|
| 36 |
+
command_args: List[str],
|
| 37 |
+
command_output: str,
|
| 38 |
+
) -> Optional[str]:
|
| 39 |
+
"""Return the path to the wheel in the temporary build directory."""
|
| 40 |
+
# Sort for determinism.
|
| 41 |
+
names = sorted(names)
|
| 42 |
+
if not names:
|
| 43 |
+
msg = ("Legacy build of wheel for {!r} created no files.\n").format(name)
|
| 44 |
+
msg += format_command_result(command_args, command_output)
|
| 45 |
+
logger.warning(msg)
|
| 46 |
+
return None
|
| 47 |
+
|
| 48 |
+
if len(names) > 1:
|
| 49 |
+
msg = (
|
| 50 |
+
"Legacy build of wheel for {!r} created more than one file.\n"
|
| 51 |
+
"Filenames (choosing first): {}\n"
|
| 52 |
+
).format(name, names)
|
| 53 |
+
msg += format_command_result(command_args, command_output)
|
| 54 |
+
logger.warning(msg)
|
| 55 |
+
|
| 56 |
+
return os.path.join(temp_dir, names[0])
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def build_wheel_legacy(
|
| 60 |
+
name: str,
|
| 61 |
+
setup_py_path: str,
|
| 62 |
+
source_dir: str,
|
| 63 |
+
global_options: List[str],
|
| 64 |
+
build_options: List[str],
|
| 65 |
+
tempd: str,
|
| 66 |
+
) -> Optional[str]:
|
| 67 |
+
"""Build one unpacked package using the "legacy" build process.
|
| 68 |
+
|
| 69 |
+
Returns path to wheel if successfully built. Otherwise, returns None.
|
| 70 |
+
"""
|
| 71 |
+
wheel_args = make_setuptools_bdist_wheel_args(
|
| 72 |
+
setup_py_path,
|
| 73 |
+
global_options=global_options,
|
| 74 |
+
build_options=build_options,
|
| 75 |
+
destination_dir=tempd,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
spin_message = f"Building wheel for {name} (setup.py)"
|
| 79 |
+
with open_spinner(spin_message) as spinner:
|
| 80 |
+
logger.debug("Destination directory: %s", tempd)
|
| 81 |
+
|
| 82 |
+
try:
|
| 83 |
+
output = call_subprocess(
|
| 84 |
+
wheel_args,
|
| 85 |
+
command_desc="python setup.py bdist_wheel",
|
| 86 |
+
cwd=source_dir,
|
| 87 |
+
spinner=spinner,
|
| 88 |
+
)
|
| 89 |
+
except Exception:
|
| 90 |
+
spinner.finish("error")
|
| 91 |
+
logger.error("Failed building wheel for %s", name)
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
names = os.listdir(tempd)
|
| 95 |
+
wheel_path = get_legacy_build_wheel_path(
|
| 96 |
+
names=names,
|
| 97 |
+
temp_dir=tempd,
|
| 98 |
+
name=name,
|
| 99 |
+
command_args=wheel_args,
|
| 100 |
+
command_output=output,
|
| 101 |
+
)
|
| 102 |
+
return wheel_path
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""For modules related to installing packages.
|
| 2 |
+
"""
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (290 Bytes). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__pycache__/editable_legacy.cpython-311.pyc
ADDED
|
Binary file (2.2 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/__pycache__/wheel.cpython-311.pyc
ADDED
|
Binary file (40.2 kB). View file
|
|
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/editable_legacy.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Legacy editable installation process, i.e. `setup.py develop`.
|
| 2 |
+
"""
|
| 3 |
+
import logging
|
| 4 |
+
from typing import Optional, Sequence
|
| 5 |
+
|
| 6 |
+
from pip._internal.build_env import BuildEnvironment
|
| 7 |
+
from pip._internal.utils.logging import indent_log
|
| 8 |
+
from pip._internal.utils.setuptools_build import make_setuptools_develop_args
|
| 9 |
+
from pip._internal.utils.subprocess import call_subprocess
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def install_editable(
|
| 15 |
+
*,
|
| 16 |
+
global_options: Sequence[str],
|
| 17 |
+
prefix: Optional[str],
|
| 18 |
+
home: Optional[str],
|
| 19 |
+
use_user_site: bool,
|
| 20 |
+
name: str,
|
| 21 |
+
setup_py_path: str,
|
| 22 |
+
isolated: bool,
|
| 23 |
+
build_env: BuildEnvironment,
|
| 24 |
+
unpacked_source_directory: str,
|
| 25 |
+
) -> None:
|
| 26 |
+
"""Install a package in editable mode. Most arguments are pass-through
|
| 27 |
+
to setuptools.
|
| 28 |
+
"""
|
| 29 |
+
logger.info("Running setup.py develop for %s", name)
|
| 30 |
+
|
| 31 |
+
args = make_setuptools_develop_args(
|
| 32 |
+
setup_py_path,
|
| 33 |
+
global_options=global_options,
|
| 34 |
+
no_user_config=isolated,
|
| 35 |
+
prefix=prefix,
|
| 36 |
+
home=home,
|
| 37 |
+
use_user_site=use_user_site,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
with indent_log():
|
| 41 |
+
with build_env:
|
| 42 |
+
call_subprocess(
|
| 43 |
+
args,
|
| 44 |
+
command_desc="python setup.py develop",
|
| 45 |
+
cwd=unpacked_source_directory,
|
| 46 |
+
)
|
jupyter/lib/python3.11/site-packages/pip/_internal/operations/install/wheel.py
ADDED
|
@@ -0,0 +1,734 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support for installing and building the "wheel" binary package format.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import collections
|
| 5 |
+
import compileall
|
| 6 |
+
import contextlib
|
| 7 |
+
import csv
|
| 8 |
+
import importlib
|
| 9 |
+
import logging
|
| 10 |
+
import os.path
|
| 11 |
+
import re
|
| 12 |
+
import shutil
|
| 13 |
+
import sys
|
| 14 |
+
import warnings
|
| 15 |
+
from base64 import urlsafe_b64encode
|
| 16 |
+
from email.message import Message
|
| 17 |
+
from itertools import chain, filterfalse, starmap
|
| 18 |
+
from typing import (
|
| 19 |
+
IO,
|
| 20 |
+
TYPE_CHECKING,
|
| 21 |
+
Any,
|
| 22 |
+
BinaryIO,
|
| 23 |
+
Callable,
|
| 24 |
+
Dict,
|
| 25 |
+
Generator,
|
| 26 |
+
Iterable,
|
| 27 |
+
Iterator,
|
| 28 |
+
List,
|
| 29 |
+
NewType,
|
| 30 |
+
Optional,
|
| 31 |
+
Sequence,
|
| 32 |
+
Set,
|
| 33 |
+
Tuple,
|
| 34 |
+
Union,
|
| 35 |
+
cast,
|
| 36 |
+
)
|
| 37 |
+
from zipfile import ZipFile, ZipInfo
|
| 38 |
+
|
| 39 |
+
from pip._vendor.distlib.scripts import ScriptMaker
|
| 40 |
+
from pip._vendor.distlib.util import get_export_entry
|
| 41 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 42 |
+
|
| 43 |
+
from pip._internal.exceptions import InstallationError
|
| 44 |
+
from pip._internal.locations import get_major_minor_version
|
| 45 |
+
from pip._internal.metadata import (
|
| 46 |
+
BaseDistribution,
|
| 47 |
+
FilesystemWheel,
|
| 48 |
+
get_wheel_distribution,
|
| 49 |
+
)
|
| 50 |
+
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
|
| 51 |
+
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
| 52 |
+
from pip._internal.utils.filesystem import adjacent_tmp_file, replace
|
| 53 |
+
from pip._internal.utils.misc import captured_stdout, ensure_dir, hash_file, partition
|
| 54 |
+
from pip._internal.utils.unpacking import (
|
| 55 |
+
current_umask,
|
| 56 |
+
is_within_directory,
|
| 57 |
+
set_extracted_file_to_default_mode_plus_executable,
|
| 58 |
+
zip_item_is_executable,
|
| 59 |
+
)
|
| 60 |
+
from pip._internal.utils.wheel import parse_wheel
|
| 61 |
+
|
| 62 |
+
if TYPE_CHECKING:
|
| 63 |
+
from typing import Protocol
|
| 64 |
+
|
| 65 |
+
class File(Protocol):
|
| 66 |
+
src_record_path: "RecordPath"
|
| 67 |
+
dest_path: str
|
| 68 |
+
changed: bool
|
| 69 |
+
|
| 70 |
+
def save(self) -> None:
|
| 71 |
+
pass
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
logger = logging.getLogger(__name__)
|
| 75 |
+
|
| 76 |
+
RecordPath = NewType("RecordPath", str)
|
| 77 |
+
InstalledCSVRow = Tuple[RecordPath, str, Union[int, str]]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def rehash(path: str, blocksize: int = 1 << 20) -> Tuple[str, str]:
|
| 81 |
+
"""Return (encoded_digest, length) for path using hashlib.sha256()"""
|
| 82 |
+
h, length = hash_file(path, blocksize)
|
| 83 |
+
digest = "sha256=" + urlsafe_b64encode(h.digest()).decode("latin1").rstrip("=")
|
| 84 |
+
return (digest, str(length))
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def csv_io_kwargs(mode: str) -> Dict[str, Any]:
|
| 88 |
+
"""Return keyword arguments to properly open a CSV file
|
| 89 |
+
in the given mode.
|
| 90 |
+
"""
|
| 91 |
+
return {"mode": mode, "newline": "", "encoding": "utf-8"}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def fix_script(path: str) -> bool:
|
| 95 |
+
"""Replace #!python with #!/path/to/python
|
| 96 |
+
Return True if file was changed.
|
| 97 |
+
"""
|
| 98 |
+
# XXX RECORD hashes will need to be updated
|
| 99 |
+
assert os.path.isfile(path)
|
| 100 |
+
|
| 101 |
+
with open(path, "rb") as script:
|
| 102 |
+
firstline = script.readline()
|
| 103 |
+
if not firstline.startswith(b"#!python"):
|
| 104 |
+
return False
|
| 105 |
+
exename = sys.executable.encode(sys.getfilesystemencoding())
|
| 106 |
+
firstline = b"#!" + exename + os.linesep.encode("ascii")
|
| 107 |
+
rest = script.read()
|
| 108 |
+
with open(path, "wb") as script:
|
| 109 |
+
script.write(firstline)
|
| 110 |
+
script.write(rest)
|
| 111 |
+
return True
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def wheel_root_is_purelib(metadata: Message) -> bool:
|
| 115 |
+
return metadata.get("Root-Is-Purelib", "").lower() == "true"
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def get_entrypoints(dist: BaseDistribution) -> Tuple[Dict[str, str], Dict[str, str]]:
|
| 119 |
+
console_scripts = {}
|
| 120 |
+
gui_scripts = {}
|
| 121 |
+
for entry_point in dist.iter_entry_points():
|
| 122 |
+
if entry_point.group == "console_scripts":
|
| 123 |
+
console_scripts[entry_point.name] = entry_point.value
|
| 124 |
+
elif entry_point.group == "gui_scripts":
|
| 125 |
+
gui_scripts[entry_point.name] = entry_point.value
|
| 126 |
+
return console_scripts, gui_scripts
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def message_about_scripts_not_on_PATH(scripts: Sequence[str]) -> Optional[str]:
|
| 130 |
+
"""Determine if any scripts are not on PATH and format a warning.
|
| 131 |
+
Returns a warning message if one or more scripts are not on PATH,
|
| 132 |
+
otherwise None.
|
| 133 |
+
"""
|
| 134 |
+
if not scripts:
|
| 135 |
+
return None
|
| 136 |
+
|
| 137 |
+
# Group scripts by the path they were installed in
|
| 138 |
+
grouped_by_dir: Dict[str, Set[str]] = collections.defaultdict(set)
|
| 139 |
+
for destfile in scripts:
|
| 140 |
+
parent_dir = os.path.dirname(destfile)
|
| 141 |
+
script_name = os.path.basename(destfile)
|
| 142 |
+
grouped_by_dir[parent_dir].add(script_name)
|
| 143 |
+
|
| 144 |
+
# We don't want to warn for directories that are on PATH.
|
| 145 |
+
not_warn_dirs = [
|
| 146 |
+
os.path.normcase(os.path.normpath(i)).rstrip(os.sep)
|
| 147 |
+
for i in os.environ.get("PATH", "").split(os.pathsep)
|
| 148 |
+
]
|
| 149 |
+
# If an executable sits with sys.executable, we don't warn for it.
|
| 150 |
+
# This covers the case of venv invocations without activating the venv.
|
| 151 |
+
not_warn_dirs.append(
|
| 152 |
+
os.path.normcase(os.path.normpath(os.path.dirname(sys.executable)))
|
| 153 |
+
)
|
| 154 |
+
warn_for: Dict[str, Set[str]] = {
|
| 155 |
+
parent_dir: scripts
|
| 156 |
+
for parent_dir, scripts in grouped_by_dir.items()
|
| 157 |
+
if os.path.normcase(os.path.normpath(parent_dir)) not in not_warn_dirs
|
| 158 |
+
}
|
| 159 |
+
if not warn_for:
|
| 160 |
+
return None
|
| 161 |
+
|
| 162 |
+
# Format a message
|
| 163 |
+
msg_lines = []
|
| 164 |
+
for parent_dir, dir_scripts in warn_for.items():
|
| 165 |
+
sorted_scripts: List[str] = sorted(dir_scripts)
|
| 166 |
+
if len(sorted_scripts) == 1:
|
| 167 |
+
start_text = f"script {sorted_scripts[0]} is"
|
| 168 |
+
else:
|
| 169 |
+
start_text = "scripts {} are".format(
|
| 170 |
+
", ".join(sorted_scripts[:-1]) + " and " + sorted_scripts[-1]
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
msg_lines.append(
|
| 174 |
+
f"The {start_text} installed in '{parent_dir}' which is not on PATH."
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
last_line_fmt = (
|
| 178 |
+
"Consider adding {} to PATH or, if you prefer "
|
| 179 |
+
"to suppress this warning, use --no-warn-script-location."
|
| 180 |
+
)
|
| 181 |
+
if len(msg_lines) == 1:
|
| 182 |
+
msg_lines.append(last_line_fmt.format("this directory"))
|
| 183 |
+
else:
|
| 184 |
+
msg_lines.append(last_line_fmt.format("these directories"))
|
| 185 |
+
|
| 186 |
+
# Add a note if any directory starts with ~
|
| 187 |
+
warn_for_tilde = any(
|
| 188 |
+
i[0] == "~" for i in os.environ.get("PATH", "").split(os.pathsep) if i
|
| 189 |
+
)
|
| 190 |
+
if warn_for_tilde:
|
| 191 |
+
tilde_warning_msg = (
|
| 192 |
+
"NOTE: The current PATH contains path(s) starting with `~`, "
|
| 193 |
+
"which may not be expanded by all applications."
|
| 194 |
+
)
|
| 195 |
+
msg_lines.append(tilde_warning_msg)
|
| 196 |
+
|
| 197 |
+
# Returns the formatted multiline message
|
| 198 |
+
return "\n".join(msg_lines)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def _normalized_outrows(
|
| 202 |
+
outrows: Iterable[InstalledCSVRow],
|
| 203 |
+
) -> List[Tuple[str, str, str]]:
|
| 204 |
+
"""Normalize the given rows of a RECORD file.
|
| 205 |
+
|
| 206 |
+
Items in each row are converted into str. Rows are then sorted to make
|
| 207 |
+
the value more predictable for tests.
|
| 208 |
+
|
| 209 |
+
Each row is a 3-tuple (path, hash, size) and corresponds to a record of
|
| 210 |
+
a RECORD file (see PEP 376 and PEP 427 for details). For the rows
|
| 211 |
+
passed to this function, the size can be an integer as an int or string,
|
| 212 |
+
or the empty string.
|
| 213 |
+
"""
|
| 214 |
+
# Normally, there should only be one row per path, in which case the
|
| 215 |
+
# second and third elements don't come into play when sorting.
|
| 216 |
+
# However, in cases in the wild where a path might happen to occur twice,
|
| 217 |
+
# we don't want the sort operation to trigger an error (but still want
|
| 218 |
+
# determinism). Since the third element can be an int or string, we
|
| 219 |
+
# coerce each element to a string to avoid a TypeError in this case.
|
| 220 |
+
# For additional background, see--
|
| 221 |
+
# https://github.com/pypa/pip/issues/5868
|
| 222 |
+
return sorted(
|
| 223 |
+
(record_path, hash_, str(size)) for record_path, hash_, size in outrows
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def _record_to_fs_path(record_path: RecordPath, lib_dir: str) -> str:
|
| 228 |
+
return os.path.join(lib_dir, record_path)
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def _fs_to_record_path(path: str, lib_dir: str) -> RecordPath:
|
| 232 |
+
# On Windows, do not handle relative paths if they belong to different
|
| 233 |
+
# logical disks
|
| 234 |
+
if os.path.splitdrive(path)[0].lower() == os.path.splitdrive(lib_dir)[0].lower():
|
| 235 |
+
path = os.path.relpath(path, lib_dir)
|
| 236 |
+
|
| 237 |
+
path = path.replace(os.path.sep, "/")
|
| 238 |
+
return cast("RecordPath", path)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def get_csv_rows_for_installed(
|
| 242 |
+
old_csv_rows: List[List[str]],
|
| 243 |
+
installed: Dict[RecordPath, RecordPath],
|
| 244 |
+
changed: Set[RecordPath],
|
| 245 |
+
generated: List[str],
|
| 246 |
+
lib_dir: str,
|
| 247 |
+
) -> List[InstalledCSVRow]:
|
| 248 |
+
"""
|
| 249 |
+
:param installed: A map from archive RECORD path to installation RECORD
|
| 250 |
+
path.
|
| 251 |
+
"""
|
| 252 |
+
installed_rows: List[InstalledCSVRow] = []
|
| 253 |
+
for row in old_csv_rows:
|
| 254 |
+
if len(row) > 3:
|
| 255 |
+
logger.warning("RECORD line has more than three elements: %s", row)
|
| 256 |
+
old_record_path = cast("RecordPath", row[0])
|
| 257 |
+
new_record_path = installed.pop(old_record_path, old_record_path)
|
| 258 |
+
if new_record_path in changed:
|
| 259 |
+
digest, length = rehash(_record_to_fs_path(new_record_path, lib_dir))
|
| 260 |
+
else:
|
| 261 |
+
digest = row[1] if len(row) > 1 else ""
|
| 262 |
+
length = row[2] if len(row) > 2 else ""
|
| 263 |
+
installed_rows.append((new_record_path, digest, length))
|
| 264 |
+
for f in generated:
|
| 265 |
+
path = _fs_to_record_path(f, lib_dir)
|
| 266 |
+
digest, length = rehash(f)
|
| 267 |
+
installed_rows.append((path, digest, length))
|
| 268 |
+
return installed_rows + [
|
| 269 |
+
(installed_record_path, "", "") for installed_record_path in installed.values()
|
| 270 |
+
]
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def get_console_script_specs(console: Dict[str, str]) -> List[str]:
|
| 274 |
+
"""
|
| 275 |
+
Given the mapping from entrypoint name to callable, return the relevant
|
| 276 |
+
console script specs.
|
| 277 |
+
"""
|
| 278 |
+
# Don't mutate caller's version
|
| 279 |
+
console = console.copy()
|
| 280 |
+
|
| 281 |
+
scripts_to_generate = []
|
| 282 |
+
|
| 283 |
+
# Special case pip and setuptools to generate versioned wrappers
|
| 284 |
+
#
|
| 285 |
+
# The issue is that some projects (specifically, pip and setuptools) use
|
| 286 |
+
# code in setup.py to create "versioned" entry points - pip2.7 on Python
|
| 287 |
+
# 2.7, pip3.3 on Python 3.3, etc. But these entry points are baked into
|
| 288 |
+
# the wheel metadata at build time, and so if the wheel is installed with
|
| 289 |
+
# a *different* version of Python the entry points will be wrong. The
|
| 290 |
+
# correct fix for this is to enhance the metadata to be able to describe
|
| 291 |
+
# such versioned entry points, but that won't happen till Metadata 2.0 is
|
| 292 |
+
# available.
|
| 293 |
+
# In the meantime, projects using versioned entry points will either have
|
| 294 |
+
# incorrect versioned entry points, or they will not be able to distribute
|
| 295 |
+
# "universal" wheels (i.e., they will need a wheel per Python version).
|
| 296 |
+
#
|
| 297 |
+
# Because setuptools and pip are bundled with _ensurepip and virtualenv,
|
| 298 |
+
# we need to use universal wheels. So, as a stopgap until Metadata 2.0, we
|
| 299 |
+
# override the versioned entry points in the wheel and generate the
|
| 300 |
+
# correct ones. This code is purely a short-term measure until Metadata 2.0
|
| 301 |
+
# is available.
|
| 302 |
+
#
|
| 303 |
+
# To add the level of hack in this section of code, in order to support
|
| 304 |
+
# ensurepip this code will look for an ``ENSUREPIP_OPTIONS`` environment
|
| 305 |
+
# variable which will control which version scripts get installed.
|
| 306 |
+
#
|
| 307 |
+
# ENSUREPIP_OPTIONS=altinstall
|
| 308 |
+
# - Only pipX.Y and easy_install-X.Y will be generated and installed
|
| 309 |
+
# ENSUREPIP_OPTIONS=install
|
| 310 |
+
# - pipX.Y, pipX, easy_install-X.Y will be generated and installed. Note
|
| 311 |
+
# that this option is technically if ENSUREPIP_OPTIONS is set and is
|
| 312 |
+
# not altinstall
|
| 313 |
+
# DEFAULT
|
| 314 |
+
# - The default behavior is to install pip, pipX, pipX.Y, easy_install
|
| 315 |
+
# and easy_install-X.Y.
|
| 316 |
+
pip_script = console.pop("pip", None)
|
| 317 |
+
if pip_script:
|
| 318 |
+
if "ENSUREPIP_OPTIONS" not in os.environ:
|
| 319 |
+
scripts_to_generate.append("pip = " + pip_script)
|
| 320 |
+
|
| 321 |
+
if os.environ.get("ENSUREPIP_OPTIONS", "") != "altinstall":
|
| 322 |
+
scripts_to_generate.append(f"pip{sys.version_info[0]} = {pip_script}")
|
| 323 |
+
|
| 324 |
+
scripts_to_generate.append(f"pip{get_major_minor_version()} = {pip_script}")
|
| 325 |
+
# Delete any other versioned pip entry points
|
| 326 |
+
pip_ep = [k for k in console if re.match(r"pip(\d+(\.\d+)?)?$", k)]
|
| 327 |
+
for k in pip_ep:
|
| 328 |
+
del console[k]
|
| 329 |
+
easy_install_script = console.pop("easy_install", None)
|
| 330 |
+
if easy_install_script:
|
| 331 |
+
if "ENSUREPIP_OPTIONS" not in os.environ:
|
| 332 |
+
scripts_to_generate.append("easy_install = " + easy_install_script)
|
| 333 |
+
|
| 334 |
+
scripts_to_generate.append(
|
| 335 |
+
f"easy_install-{get_major_minor_version()} = {easy_install_script}"
|
| 336 |
+
)
|
| 337 |
+
# Delete any other versioned easy_install entry points
|
| 338 |
+
easy_install_ep = [
|
| 339 |
+
k for k in console if re.match(r"easy_install(-\d+\.\d+)?$", k)
|
| 340 |
+
]
|
| 341 |
+
for k in easy_install_ep:
|
| 342 |
+
del console[k]
|
| 343 |
+
|
| 344 |
+
# Generate the console entry points specified in the wheel
|
| 345 |
+
scripts_to_generate.extend(starmap("{} = {}".format, console.items()))
|
| 346 |
+
|
| 347 |
+
return scripts_to_generate
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
class ZipBackedFile:
|
| 351 |
+
def __init__(
|
| 352 |
+
self, src_record_path: RecordPath, dest_path: str, zip_file: ZipFile
|
| 353 |
+
) -> None:
|
| 354 |
+
self.src_record_path = src_record_path
|
| 355 |
+
self.dest_path = dest_path
|
| 356 |
+
self._zip_file = zip_file
|
| 357 |
+
self.changed = False
|
| 358 |
+
|
| 359 |
+
def _getinfo(self) -> ZipInfo:
|
| 360 |
+
return self._zip_file.getinfo(self.src_record_path)
|
| 361 |
+
|
| 362 |
+
def save(self) -> None:
|
| 363 |
+
# directory creation is lazy and after file filtering
|
| 364 |
+
# to ensure we don't install empty dirs; empty dirs can't be
|
| 365 |
+
# uninstalled.
|
| 366 |
+
parent_dir = os.path.dirname(self.dest_path)
|
| 367 |
+
ensure_dir(parent_dir)
|
| 368 |
+
|
| 369 |
+
# When we open the output file below, any existing file is truncated
|
| 370 |
+
# before we start writing the new contents. This is fine in most
|
| 371 |
+
# cases, but can cause a segfault if pip has loaded a shared
|
| 372 |
+
# object (e.g. from pyopenssl through its vendored urllib3)
|
| 373 |
+
# Since the shared object is mmap'd an attempt to call a
|
| 374 |
+
# symbol in it will then cause a segfault. Unlinking the file
|
| 375 |
+
# allows writing of new contents while allowing the process to
|
| 376 |
+
# continue to use the old copy.
|
| 377 |
+
if os.path.exists(self.dest_path):
|
| 378 |
+
os.unlink(self.dest_path)
|
| 379 |
+
|
| 380 |
+
zipinfo = self._getinfo()
|
| 381 |
+
|
| 382 |
+
with self._zip_file.open(zipinfo) as f:
|
| 383 |
+
with open(self.dest_path, "wb") as dest:
|
| 384 |
+
shutil.copyfileobj(f, dest)
|
| 385 |
+
|
| 386 |
+
if zip_item_is_executable(zipinfo):
|
| 387 |
+
set_extracted_file_to_default_mode_plus_executable(self.dest_path)
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
class ScriptFile:
|
| 391 |
+
def __init__(self, file: "File") -> None:
|
| 392 |
+
self._file = file
|
| 393 |
+
self.src_record_path = self._file.src_record_path
|
| 394 |
+
self.dest_path = self._file.dest_path
|
| 395 |
+
self.changed = False
|
| 396 |
+
|
| 397 |
+
def save(self) -> None:
|
| 398 |
+
self._file.save()
|
| 399 |
+
self.changed = fix_script(self.dest_path)
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
class MissingCallableSuffix(InstallationError):
|
| 403 |
+
def __init__(self, entry_point: str) -> None:
|
| 404 |
+
super().__init__(
|
| 405 |
+
f"Invalid script entry point: {entry_point} - A callable "
|
| 406 |
+
"suffix is required. Cf https://packaging.python.org/"
|
| 407 |
+
"specifications/entry-points/#use-for-scripts for more "
|
| 408 |
+
"information."
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
def _raise_for_invalid_entrypoint(specification: str) -> None:
|
| 413 |
+
entry = get_export_entry(specification)
|
| 414 |
+
if entry is not None and entry.suffix is None:
|
| 415 |
+
raise MissingCallableSuffix(str(entry))
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
class PipScriptMaker(ScriptMaker):
|
| 419 |
+
def make(
|
| 420 |
+
self, specification: str, options: Optional[Dict[str, Any]] = None
|
| 421 |
+
) -> List[str]:
|
| 422 |
+
_raise_for_invalid_entrypoint(specification)
|
| 423 |
+
return super().make(specification, options)
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
def _install_wheel(
|
| 427 |
+
name: str,
|
| 428 |
+
wheel_zip: ZipFile,
|
| 429 |
+
wheel_path: str,
|
| 430 |
+
scheme: Scheme,
|
| 431 |
+
pycompile: bool = True,
|
| 432 |
+
warn_script_location: bool = True,
|
| 433 |
+
direct_url: Optional[DirectUrl] = None,
|
| 434 |
+
requested: bool = False,
|
| 435 |
+
) -> None:
|
| 436 |
+
"""Install a wheel.
|
| 437 |
+
|
| 438 |
+
:param name: Name of the project to install
|
| 439 |
+
:param wheel_zip: open ZipFile for wheel being installed
|
| 440 |
+
:param scheme: Distutils scheme dictating the install directories
|
| 441 |
+
:param req_description: String used in place of the requirement, for
|
| 442 |
+
logging
|
| 443 |
+
:param pycompile: Whether to byte-compile installed Python files
|
| 444 |
+
:param warn_script_location: Whether to check that scripts are installed
|
| 445 |
+
into a directory on PATH
|
| 446 |
+
:raises UnsupportedWheel:
|
| 447 |
+
* when the directory holds an unpacked wheel with incompatible
|
| 448 |
+
Wheel-Version
|
| 449 |
+
* when the .dist-info dir does not match the wheel
|
| 450 |
+
"""
|
| 451 |
+
info_dir, metadata = parse_wheel(wheel_zip, name)
|
| 452 |
+
|
| 453 |
+
if wheel_root_is_purelib(metadata):
|
| 454 |
+
lib_dir = scheme.purelib
|
| 455 |
+
else:
|
| 456 |
+
lib_dir = scheme.platlib
|
| 457 |
+
|
| 458 |
+
# Record details of the files moved
|
| 459 |
+
# installed = files copied from the wheel to the destination
|
| 460 |
+
# changed = files changed while installing (scripts #! line typically)
|
| 461 |
+
# generated = files newly generated during the install (script wrappers)
|
| 462 |
+
installed: Dict[RecordPath, RecordPath] = {}
|
| 463 |
+
changed: Set[RecordPath] = set()
|
| 464 |
+
generated: List[str] = []
|
| 465 |
+
|
| 466 |
+
def record_installed(
|
| 467 |
+
srcfile: RecordPath, destfile: str, modified: bool = False
|
| 468 |
+
) -> None:
|
| 469 |
+
"""Map archive RECORD paths to installation RECORD paths."""
|
| 470 |
+
newpath = _fs_to_record_path(destfile, lib_dir)
|
| 471 |
+
installed[srcfile] = newpath
|
| 472 |
+
if modified:
|
| 473 |
+
changed.add(newpath)
|
| 474 |
+
|
| 475 |
+
def is_dir_path(path: RecordPath) -> bool:
|
| 476 |
+
return path.endswith("/")
|
| 477 |
+
|
| 478 |
+
def assert_no_path_traversal(dest_dir_path: str, target_path: str) -> None:
|
| 479 |
+
if not is_within_directory(dest_dir_path, target_path):
|
| 480 |
+
message = (
|
| 481 |
+
"The wheel {!r} has a file {!r} trying to install"
|
| 482 |
+
" outside the target directory {!r}"
|
| 483 |
+
)
|
| 484 |
+
raise InstallationError(
|
| 485 |
+
message.format(wheel_path, target_path, dest_dir_path)
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
def root_scheme_file_maker(
|
| 489 |
+
zip_file: ZipFile, dest: str
|
| 490 |
+
) -> Callable[[RecordPath], "File"]:
|
| 491 |
+
def make_root_scheme_file(record_path: RecordPath) -> "File":
|
| 492 |
+
normed_path = os.path.normpath(record_path)
|
| 493 |
+
dest_path = os.path.join(dest, normed_path)
|
| 494 |
+
assert_no_path_traversal(dest, dest_path)
|
| 495 |
+
return ZipBackedFile(record_path, dest_path, zip_file)
|
| 496 |
+
|
| 497 |
+
return make_root_scheme_file
|
| 498 |
+
|
| 499 |
+
def data_scheme_file_maker(
|
| 500 |
+
zip_file: ZipFile, scheme: Scheme
|
| 501 |
+
) -> Callable[[RecordPath], "File"]:
|
| 502 |
+
scheme_paths = {key: getattr(scheme, key) for key in SCHEME_KEYS}
|
| 503 |
+
|
| 504 |
+
def make_data_scheme_file(record_path: RecordPath) -> "File":
|
| 505 |
+
normed_path = os.path.normpath(record_path)
|
| 506 |
+
try:
|
| 507 |
+
_, scheme_key, dest_subpath = normed_path.split(os.path.sep, 2)
|
| 508 |
+
except ValueError:
|
| 509 |
+
message = (
|
| 510 |
+
"Unexpected file in {}: {!r}. .data directory contents"
|
| 511 |
+
" should be named like: '<scheme key>/<path>'."
|
| 512 |
+
).format(wheel_path, record_path)
|
| 513 |
+
raise InstallationError(message)
|
| 514 |
+
|
| 515 |
+
try:
|
| 516 |
+
scheme_path = scheme_paths[scheme_key]
|
| 517 |
+
except KeyError:
|
| 518 |
+
valid_scheme_keys = ", ".join(sorted(scheme_paths))
|
| 519 |
+
message = (
|
| 520 |
+
"Unknown scheme key used in {}: {} (for file {!r}). .data"
|
| 521 |
+
" directory contents should be in subdirectories named"
|
| 522 |
+
" with a valid scheme key ({})"
|
| 523 |
+
).format(wheel_path, scheme_key, record_path, valid_scheme_keys)
|
| 524 |
+
raise InstallationError(message)
|
| 525 |
+
|
| 526 |
+
dest_path = os.path.join(scheme_path, dest_subpath)
|
| 527 |
+
assert_no_path_traversal(scheme_path, dest_path)
|
| 528 |
+
return ZipBackedFile(record_path, dest_path, zip_file)
|
| 529 |
+
|
| 530 |
+
return make_data_scheme_file
|
| 531 |
+
|
| 532 |
+
def is_data_scheme_path(path: RecordPath) -> bool:
|
| 533 |
+
return path.split("/", 1)[0].endswith(".data")
|
| 534 |
+
|
| 535 |
+
paths = cast(List[RecordPath], wheel_zip.namelist())
|
| 536 |
+
file_paths = filterfalse(is_dir_path, paths)
|
| 537 |
+
root_scheme_paths, data_scheme_paths = partition(is_data_scheme_path, file_paths)
|
| 538 |
+
|
| 539 |
+
make_root_scheme_file = root_scheme_file_maker(wheel_zip, lib_dir)
|
| 540 |
+
files: Iterator[File] = map(make_root_scheme_file, root_scheme_paths)
|
| 541 |
+
|
| 542 |
+
def is_script_scheme_path(path: RecordPath) -> bool:
|
| 543 |
+
parts = path.split("/", 2)
|
| 544 |
+
return len(parts) > 2 and parts[0].endswith(".data") and parts[1] == "scripts"
|
| 545 |
+
|
| 546 |
+
other_scheme_paths, script_scheme_paths = partition(
|
| 547 |
+
is_script_scheme_path, data_scheme_paths
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
make_data_scheme_file = data_scheme_file_maker(wheel_zip, scheme)
|
| 551 |
+
other_scheme_files = map(make_data_scheme_file, other_scheme_paths)
|
| 552 |
+
files = chain(files, other_scheme_files)
|
| 553 |
+
|
| 554 |
+
# Get the defined entry points
|
| 555 |
+
distribution = get_wheel_distribution(
|
| 556 |
+
FilesystemWheel(wheel_path),
|
| 557 |
+
canonicalize_name(name),
|
| 558 |
+
)
|
| 559 |
+
console, gui = get_entrypoints(distribution)
|
| 560 |
+
|
| 561 |
+
def is_entrypoint_wrapper(file: "File") -> bool:
|
| 562 |
+
# EP, EP.exe and EP-script.py are scripts generated for
|
| 563 |
+
# entry point EP by setuptools
|
| 564 |
+
path = file.dest_path
|
| 565 |
+
name = os.path.basename(path)
|
| 566 |
+
if name.lower().endswith(".exe"):
|
| 567 |
+
matchname = name[:-4]
|
| 568 |
+
elif name.lower().endswith("-script.py"):
|
| 569 |
+
matchname = name[:-10]
|
| 570 |
+
elif name.lower().endswith(".pya"):
|
| 571 |
+
matchname = name[:-4]
|
| 572 |
+
else:
|
| 573 |
+
matchname = name
|
| 574 |
+
# Ignore setuptools-generated scripts
|
| 575 |
+
return matchname in console or matchname in gui
|
| 576 |
+
|
| 577 |
+
script_scheme_files: Iterator[File] = map(
|
| 578 |
+
make_data_scheme_file, script_scheme_paths
|
| 579 |
+
)
|
| 580 |
+
script_scheme_files = filterfalse(is_entrypoint_wrapper, script_scheme_files)
|
| 581 |
+
script_scheme_files = map(ScriptFile, script_scheme_files)
|
| 582 |
+
files = chain(files, script_scheme_files)
|
| 583 |
+
|
| 584 |
+
for file in files:
|
| 585 |
+
file.save()
|
| 586 |
+
record_installed(file.src_record_path, file.dest_path, file.changed)
|
| 587 |
+
|
| 588 |
+
def pyc_source_file_paths() -> Generator[str, None, None]:
|
| 589 |
+
# We de-duplicate installation paths, since there can be overlap (e.g.
|
| 590 |
+
# file in .data maps to same location as file in wheel root).
|
| 591 |
+
# Sorting installation paths makes it easier to reproduce and debug
|
| 592 |
+
# issues related to permissions on existing files.
|
| 593 |
+
for installed_path in sorted(set(installed.values())):
|
| 594 |
+
full_installed_path = os.path.join(lib_dir, installed_path)
|
| 595 |
+
if not os.path.isfile(full_installed_path):
|
| 596 |
+
continue
|
| 597 |
+
if not full_installed_path.endswith(".py"):
|
| 598 |
+
continue
|
| 599 |
+
yield full_installed_path
|
| 600 |
+
|
| 601 |
+
def pyc_output_path(path: str) -> str:
|
| 602 |
+
"""Return the path the pyc file would have been written to."""
|
| 603 |
+
return importlib.util.cache_from_source(path)
|
| 604 |
+
|
| 605 |
+
# Compile all of the pyc files for the installed files
|
| 606 |
+
if pycompile:
|
| 607 |
+
with captured_stdout() as stdout:
|
| 608 |
+
with warnings.catch_warnings():
|
| 609 |
+
warnings.filterwarnings("ignore")
|
| 610 |
+
for path in pyc_source_file_paths():
|
| 611 |
+
success = compileall.compile_file(path, force=True, quiet=True)
|
| 612 |
+
if success:
|
| 613 |
+
pyc_path = pyc_output_path(path)
|
| 614 |
+
assert os.path.exists(pyc_path)
|
| 615 |
+
pyc_record_path = cast(
|
| 616 |
+
"RecordPath", pyc_path.replace(os.path.sep, "/")
|
| 617 |
+
)
|
| 618 |
+
record_installed(pyc_record_path, pyc_path)
|
| 619 |
+
logger.debug(stdout.getvalue())
|
| 620 |
+
|
| 621 |
+
maker = PipScriptMaker(None, scheme.scripts)
|
| 622 |
+
|
| 623 |
+
# Ensure old scripts are overwritten.
|
| 624 |
+
# See https://github.com/pypa/pip/issues/1800
|
| 625 |
+
maker.clobber = True
|
| 626 |
+
|
| 627 |
+
# Ensure we don't generate any variants for scripts because this is almost
|
| 628 |
+
# never what somebody wants.
|
| 629 |
+
# See https://bitbucket.org/pypa/distlib/issue/35/
|
| 630 |
+
maker.variants = {""}
|
| 631 |
+
|
| 632 |
+
# This is required because otherwise distlib creates scripts that are not
|
| 633 |
+
# executable.
|
| 634 |
+
# See https://bitbucket.org/pypa/distlib/issue/32/
|
| 635 |
+
maker.set_mode = True
|
| 636 |
+
|
| 637 |
+
# Generate the console and GUI entry points specified in the wheel
|
| 638 |
+
scripts_to_generate = get_console_script_specs(console)
|
| 639 |
+
|
| 640 |
+
gui_scripts_to_generate = list(starmap("{} = {}".format, gui.items()))
|
| 641 |
+
|
| 642 |
+
generated_console_scripts = maker.make_multiple(scripts_to_generate)
|
| 643 |
+
generated.extend(generated_console_scripts)
|
| 644 |
+
|
| 645 |
+
generated.extend(maker.make_multiple(gui_scripts_to_generate, {"gui": True}))
|
| 646 |
+
|
| 647 |
+
if warn_script_location:
|
| 648 |
+
msg = message_about_scripts_not_on_PATH(generated_console_scripts)
|
| 649 |
+
if msg is not None:
|
| 650 |
+
logger.warning(msg)
|
| 651 |
+
|
| 652 |
+
generated_file_mode = 0o666 & ~current_umask()
|
| 653 |
+
|
| 654 |
+
@contextlib.contextmanager
|
| 655 |
+
def _generate_file(path: str, **kwargs: Any) -> Generator[BinaryIO, None, None]:
|
| 656 |
+
with adjacent_tmp_file(path, **kwargs) as f:
|
| 657 |
+
yield f
|
| 658 |
+
os.chmod(f.name, generated_file_mode)
|
| 659 |
+
replace(f.name, path)
|
| 660 |
+
|
| 661 |
+
dest_info_dir = os.path.join(lib_dir, info_dir)
|
| 662 |
+
|
| 663 |
+
# Record pip as the installer
|
| 664 |
+
installer_path = os.path.join(dest_info_dir, "INSTALLER")
|
| 665 |
+
with _generate_file(installer_path) as installer_file:
|
| 666 |
+
installer_file.write(b"pip\n")
|
| 667 |
+
generated.append(installer_path)
|
| 668 |
+
|
| 669 |
+
# Record the PEP 610 direct URL reference
|
| 670 |
+
if direct_url is not None:
|
| 671 |
+
direct_url_path = os.path.join(dest_info_dir, DIRECT_URL_METADATA_NAME)
|
| 672 |
+
with _generate_file(direct_url_path) as direct_url_file:
|
| 673 |
+
direct_url_file.write(direct_url.to_json().encode("utf-8"))
|
| 674 |
+
generated.append(direct_url_path)
|
| 675 |
+
|
| 676 |
+
# Record the REQUESTED file
|
| 677 |
+
if requested:
|
| 678 |
+
requested_path = os.path.join(dest_info_dir, "REQUESTED")
|
| 679 |
+
with open(requested_path, "wb"):
|
| 680 |
+
pass
|
| 681 |
+
generated.append(requested_path)
|
| 682 |
+
|
| 683 |
+
record_text = distribution.read_text("RECORD")
|
| 684 |
+
record_rows = list(csv.reader(record_text.splitlines()))
|
| 685 |
+
|
| 686 |
+
rows = get_csv_rows_for_installed(
|
| 687 |
+
record_rows,
|
| 688 |
+
installed=installed,
|
| 689 |
+
changed=changed,
|
| 690 |
+
generated=generated,
|
| 691 |
+
lib_dir=lib_dir,
|
| 692 |
+
)
|
| 693 |
+
|
| 694 |
+
# Record details of all files installed
|
| 695 |
+
record_path = os.path.join(dest_info_dir, "RECORD")
|
| 696 |
+
|
| 697 |
+
with _generate_file(record_path, **csv_io_kwargs("w")) as record_file:
|
| 698 |
+
# Explicitly cast to typing.IO[str] as a workaround for the mypy error:
|
| 699 |
+
# "writer" has incompatible type "BinaryIO"; expected "_Writer"
|
| 700 |
+
writer = csv.writer(cast("IO[str]", record_file))
|
| 701 |
+
writer.writerows(_normalized_outrows(rows))
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
@contextlib.contextmanager
|
| 705 |
+
def req_error_context(req_description: str) -> Generator[None, None, None]:
|
| 706 |
+
try:
|
| 707 |
+
yield
|
| 708 |
+
except InstallationError as e:
|
| 709 |
+
message = f"For req: {req_description}. {e.args[0]}"
|
| 710 |
+
raise InstallationError(message) from e
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def install_wheel(
|
| 714 |
+
name: str,
|
| 715 |
+
wheel_path: str,
|
| 716 |
+
scheme: Scheme,
|
| 717 |
+
req_description: str,
|
| 718 |
+
pycompile: bool = True,
|
| 719 |
+
warn_script_location: bool = True,
|
| 720 |
+
direct_url: Optional[DirectUrl] = None,
|
| 721 |
+
requested: bool = False,
|
| 722 |
+
) -> None:
|
| 723 |
+
with ZipFile(wheel_path, allowZip64=True) as z:
|
| 724 |
+
with req_error_context(req_description):
|
| 725 |
+
_install_wheel(
|
| 726 |
+
name=name,
|
| 727 |
+
wheel_zip=z,
|
| 728 |
+
wheel_path=wheel_path,
|
| 729 |
+
scheme=scheme,
|
| 730 |
+
pycompile=pycompile,
|
| 731 |
+
warn_script_location=warn_script_location,
|
| 732 |
+
direct_url=direct_url,
|
| 733 |
+
requested=requested,
|
| 734 |
+
)
|
jupyter/lib/python3.11/site-packages/pip/_internal/utils/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|