Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -1,12 +1,11 @@
"""Orchestrator for building wheels from InstallRequirements."""
from __future__ import annotations
"""Orchestrator for building wheels from InstallRequirements.
"""
import logging
import os.path
import re
from collections.abc import Iterable
from tempfile import TemporaryDirectory
import shutil
from typing import Iterable, List, Optional, Tuple
from pip._vendor.packaging.utils import canonicalize_name, canonicalize_version
from pip._vendor.packaging.version import InvalidVersion, Version
@ -18,9 +17,13 @@ from pip._internal.models.link import Link
from pip._internal.models.wheel import Wheel
from pip._internal.operations.build.wheel import build_wheel_pep517
from pip._internal.operations.build.wheel_editable import build_wheel_editable
from pip._internal.operations.build.wheel_legacy import build_wheel_legacy
from pip._internal.req.req_install import InstallRequirement
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import ensure_dir, hash_file
from pip._internal.utils.setuptools_build import make_setuptools_clean_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.urls import path_to_url
from pip._internal.vcs import vcs
@ -28,7 +31,7 @@ logger = logging.getLogger(__name__)
_egg_info_re = re.compile(r"([a-z0-9_.]+)-([a-z0-9_.!+-]+)", re.IGNORECASE)
BuildResult = tuple[list[InstallRequirement], list[InstallRequirement]]
BuildResult = Tuple[List[InstallRequirement], List[InstallRequirement]]
def _contains_egg_info(s: str) -> bool:
@ -39,12 +42,58 @@ def _contains_egg_info(s: str) -> bool:
return bool(_egg_info_re.search(s))
def _should_build(
req: InstallRequirement,
need_wheel: bool,
) -> bool:
"""Return whether an InstallRequirement should be built into a wheel."""
if req.constraint:
# never build requirements that are merely constraints
return False
if req.is_wheel:
if need_wheel:
logger.info(
"Skipping %s, due to already being wheel.",
req.name,
)
return False
if need_wheel:
# i.e. pip wheel, not pip install
return True
# From this point, this concerns the pip install command only
# (need_wheel=False).
if not req.source_dir:
return False
if req.editable:
# we only build PEP 660 editable requirements
return req.supports_pyproject_editable()
return True
def should_build_for_wheel_command(
req: InstallRequirement,
) -> bool:
return _should_build(req, need_wheel=True)
def should_build_for_install_command(
req: InstallRequirement,
) -> bool:
return _should_build(req, need_wheel=False)
def _should_cache(
req: InstallRequirement,
) -> bool | None:
) -> Optional[bool]:
"""
Return whether a built InstallRequirement can be stored in the persistent
wheel cache, assuming the wheel cache is available.
wheel cache, assuming the wheel cache is available, and _should_build()
has determined a wheel needs to be built.
"""
if req.editable or not req.source_dir:
# never cache editable requirements
@ -89,7 +138,7 @@ def _get_cache_dir(
def _verify_one(req: InstallRequirement, wheel_path: str) -> None:
canonical_name = canonicalize_name(req.name or "")
w = Wheel(os.path.basename(wheel_path))
if w.name != canonical_name:
if canonicalize_name(w.name) != canonical_name:
raise InvalidWheelFilename(
f"Wheel has unexpected file name: expected {canonical_name!r}, "
f"got {w.name!r}",
@ -119,8 +168,10 @@ def _build_one(
req: InstallRequirement,
output_dir: str,
verify: bool,
build_options: List[str],
global_options: List[str],
editable: bool,
) -> str | None:
) -> Optional[str]:
"""Build one wheel.
:return: The filename of the built wheel, or None if the build failed.
@ -139,7 +190,9 @@ def _build_one(
# Install build deps into temporary directory (PEP 518)
with req.build_env:
wheel_path = _build_one_inside_env(req, output_dir, editable)
wheel_path = _build_one_inside_env(
req, output_dir, build_options, global_options, editable
)
if wheel_path and verify:
try:
_verify_one(req, wheel_path)
@ -152,25 +205,45 @@ def _build_one(
def _build_one_inside_env(
req: InstallRequirement,
output_dir: str,
build_options: List[str],
global_options: List[str],
editable: bool,
) -> str | None:
with TemporaryDirectory(dir=output_dir) as wheel_directory:
) -> Optional[str]:
with TempDirectory(kind="wheel") as temp_dir:
assert req.name
assert req.metadata_directory
assert req.pep517_backend
if editable:
wheel_path = build_wheel_editable(
name=req.name,
backend=req.pep517_backend,
metadata_directory=req.metadata_directory,
wheel_directory=wheel_directory,
)
if req.use_pep517:
assert req.metadata_directory
assert req.pep517_backend
if global_options:
logger.warning(
"Ignoring --global-option when building %s using PEP 517", req.name
)
if build_options:
logger.warning(
"Ignoring --build-option when building %s using PEP 517", req.name
)
if editable:
wheel_path = build_wheel_editable(
name=req.name,
backend=req.pep517_backend,
metadata_directory=req.metadata_directory,
tempd=temp_dir.path,
)
else:
wheel_path = build_wheel_pep517(
name=req.name,
backend=req.pep517_backend,
metadata_directory=req.metadata_directory,
tempd=temp_dir.path,
)
else:
wheel_path = build_wheel_pep517(
wheel_path = build_wheel_legacy(
name=req.name,
backend=req.pep517_backend,
metadata_directory=req.metadata_directory,
wheel_directory=wheel_directory,
setup_py_path=req.setup_py_path,
source_dir=req.unpacked_source_directory,
global_options=global_options,
build_options=build_options,
tempd=temp_dir.path,
)
if wheel_path is not None:
@ -178,11 +251,7 @@ def _build_one_inside_env(
dest_path = os.path.join(output_dir, wheel_name)
try:
wheel_hash, length = hash_file(wheel_path)
# We can do a replace here because wheel_path is guaranteed to
# be in the same filesystem as output_dir. This will perform an
# atomic rename, which is necessary to avoid concurrency issues
# when populating the cache.
os.replace(wheel_path, dest_path)
shutil.move(wheel_path, dest_path)
logger.info(
"Created wheel for %s: filename=%s size=%d sha256=%s",
req.name,
@ -198,13 +267,35 @@ def _build_one_inside_env(
req.name,
e,
)
# Ignore return, we can't do anything else useful.
if not req.use_pep517:
_clean_one_legacy(req, global_options)
return None
def _clean_one_legacy(req: InstallRequirement, global_options: List[str]) -> bool:
clean_args = make_setuptools_clean_args(
req.setup_py_path,
global_options=global_options,
)
logger.info("Running setup.py clean for %s", req.name)
try:
call_subprocess(
clean_args, command_desc="python setup.py clean", cwd=req.source_dir
)
return True
except Exception:
logger.error("Failed cleaning build dir for %s", req.name)
return False
def build(
requirements: Iterable[InstallRequirement],
wheel_cache: WheelCache,
verify: bool,
build_options: List[str],
global_options: List[str],
) -> BuildResult:
"""Build wheels.
@ -229,6 +320,8 @@ def build(
req,
cache_dir,
verify,
build_options,
global_options,
req.editable and req.permit_editable_wheels,
)
if wheel_file: