mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-15 16:10:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,18 +1,23 @@
|
|||
"""Orchestrator for building wheels from InstallRequirements.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
from typing import Any, Callable, Iterable, List, Optional, Tuple
|
||||
|
||||
from pip._vendor.packaging.utils import canonicalize_name, canonicalize_version
|
||||
from pip._vendor.packaging.version import InvalidVersion, Version
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import Iterable
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
from pip._internal.cache import WheelCache
|
||||
from pip._internal.exceptions import InvalidWheelFilename, UnsupportedWheel
|
||||
from pip._internal.metadata import FilesystemWheel, get_wheel_distribution
|
||||
from pip._internal.exceptions import InvalidWheelFilename
|
||||
from pip._internal.exceptions import UnsupportedWheel
|
||||
from pip._internal.metadata import FilesystemWheel
|
||||
from pip._internal.metadata import get_wheel_distribution
|
||||
from pip._internal.models.link import Link
|
||||
from pip._internal.models.wheel import Wheel
|
||||
from pip._internal.operations.build.wheel import build_wheel_pep517
|
||||
|
|
@ -20,16 +25,22 @@ 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, is_wheel_installed
|
||||
from pip._internal.utils.misc import ensure_dir
|
||||
from pip._internal.utils.misc import hash_file
|
||||
from pip._internal.utils.misc import is_wheel_installed
|
||||
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
|
||||
from pip._vendor.packaging.utils import canonicalize_name
|
||||
from pip._vendor.packaging.utils import canonicalize_version
|
||||
from pip._vendor.packaging.version import InvalidVersion
|
||||
from pip._vendor.packaging.version import Version
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_egg_info_re = re.compile(r"([a-z0-9_.]+)-([a-z0-9_.!+-]+)", re.IGNORECASE)
|
||||
_egg_info_re = re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.IGNORECASE)
|
||||
|
||||
BinaryAllowedPredicate = Callable[[InstallRequirement], bool]
|
||||
BuildResult = Tuple[List[InstallRequirement], List[InstallRequirement]]
|
||||
|
|
@ -55,7 +66,7 @@ def _should_build(
|
|||
if req.is_wheel:
|
||||
if need_wheel:
|
||||
logger.info(
|
||||
"Skipping %s, due to already being wheel.",
|
||||
'Skipping %s, due to already being wheel.',
|
||||
req.name,
|
||||
)
|
||||
return False
|
||||
|
|
@ -79,7 +90,7 @@ def _should_build(
|
|||
|
||||
if not check_binary_allowed(req):
|
||||
logger.info(
|
||||
"Skipping wheel build for %s, due to binaries being disabled for it.",
|
||||
'Skipping wheel build for %s, due to binaries being disabled for it.',
|
||||
req.name,
|
||||
)
|
||||
return False
|
||||
|
|
@ -107,13 +118,13 @@ def should_build_for_install_command(
|
|||
check_binary_allowed: BinaryAllowedPredicate,
|
||||
) -> bool:
|
||||
return _should_build(
|
||||
req, need_wheel=False, check_binary_allowed=check_binary_allowed
|
||||
req, need_wheel=False, check_binary_allowed=check_binary_allowed,
|
||||
)
|
||||
|
||||
|
||||
def _should_cache(
|
||||
req: InstallRequirement,
|
||||
) -> Optional[bool]:
|
||||
) -> bool | None:
|
||||
"""
|
||||
Return whether a built InstallRequirement can be stored in the persistent
|
||||
wheel cache, assuming the wheel cache is available, and _should_build()
|
||||
|
|
@ -164,32 +175,32 @@ def _always_true(_: Any) -> bool:
|
|||
|
||||
|
||||
def _verify_one(req: InstallRequirement, wheel_path: str) -> None:
|
||||
canonical_name = canonicalize_name(req.name or "")
|
||||
canonical_name = canonicalize_name(req.name or '')
|
||||
w = Wheel(os.path.basename(wheel_path))
|
||||
if canonicalize_name(w.name) != canonical_name:
|
||||
raise InvalidWheelFilename(
|
||||
"Wheel has unexpected file name: expected {!r}, "
|
||||
"got {!r}".format(canonical_name, w.name),
|
||||
'Wheel has unexpected file name: expected {!r}, '
|
||||
'got {!r}'.format(canonical_name, w.name),
|
||||
)
|
||||
dist = get_wheel_distribution(FilesystemWheel(wheel_path), canonical_name)
|
||||
dist_verstr = str(dist.version)
|
||||
if canonicalize_version(dist_verstr) != canonicalize_version(w.version):
|
||||
raise InvalidWheelFilename(
|
||||
"Wheel has unexpected file name: expected {!r}, "
|
||||
"got {!r}".format(dist_verstr, w.version),
|
||||
'Wheel has unexpected file name: expected {!r}, '
|
||||
'got {!r}'.format(dist_verstr, w.version),
|
||||
)
|
||||
metadata_version_value = dist.metadata_version
|
||||
if metadata_version_value is None:
|
||||
raise UnsupportedWheel("Missing Metadata-Version")
|
||||
raise UnsupportedWheel('Missing Metadata-Version')
|
||||
try:
|
||||
metadata_version = Version(metadata_version_value)
|
||||
except InvalidVersion:
|
||||
msg = f"Invalid Metadata-Version: {metadata_version_value}"
|
||||
msg = f'Invalid Metadata-Version: {metadata_version_value}'
|
||||
raise UnsupportedWheel(msg)
|
||||
if metadata_version >= Version("1.2") and not isinstance(dist.version, Version):
|
||||
if metadata_version >= Version('1.2') and not isinstance(dist.version, Version):
|
||||
raise UnsupportedWheel(
|
||||
"Metadata 1.2 mandates PEP 440 version, "
|
||||
"but {!r} is not".format(dist_verstr)
|
||||
'Metadata 1.2 mandates PEP 440 version, '
|
||||
'but {!r} is not'.format(dist_verstr),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -197,20 +208,20 @@ def _build_one(
|
|||
req: InstallRequirement,
|
||||
output_dir: str,
|
||||
verify: bool,
|
||||
build_options: List[str],
|
||||
global_options: List[str],
|
||||
build_options: list[str],
|
||||
global_options: list[str],
|
||||
editable: bool,
|
||||
) -> Optional[str]:
|
||||
) -> str | None:
|
||||
"""Build one wheel.
|
||||
|
||||
:return: The filename of the built wheel, or None if the build failed.
|
||||
"""
|
||||
artifact = "editable" if editable else "wheel"
|
||||
artifact = 'editable' if editable else 'wheel'
|
||||
try:
|
||||
ensure_dir(output_dir)
|
||||
except OSError as e:
|
||||
logger.warning(
|
||||
"Building %s for %s failed: %s",
|
||||
'Building %s for %s failed: %s',
|
||||
artifact,
|
||||
req.name,
|
||||
e,
|
||||
|
|
@ -220,13 +231,13 @@ def _build_one(
|
|||
# Install build deps into temporary directory (PEP 518)
|
||||
with req.build_env:
|
||||
wheel_path = _build_one_inside_env(
|
||||
req, output_dir, build_options, global_options, editable
|
||||
req, output_dir, build_options, global_options, editable,
|
||||
)
|
||||
if wheel_path and verify:
|
||||
try:
|
||||
_verify_one(req, wheel_path)
|
||||
except (InvalidWheelFilename, UnsupportedWheel) as e:
|
||||
logger.warning("Built %s for %s is invalid: %s", artifact, req.name, e)
|
||||
logger.warning('Built %s for %s is invalid: %s', artifact, req.name, e)
|
||||
return None
|
||||
return wheel_path
|
||||
|
||||
|
|
@ -234,22 +245,22 @@ def _build_one(
|
|||
def _build_one_inside_env(
|
||||
req: InstallRequirement,
|
||||
output_dir: str,
|
||||
build_options: List[str],
|
||||
global_options: List[str],
|
||||
build_options: list[str],
|
||||
global_options: list[str],
|
||||
editable: bool,
|
||||
) -> Optional[str]:
|
||||
with TempDirectory(kind="wheel") as temp_dir:
|
||||
) -> str | None:
|
||||
with TempDirectory(kind='wheel') as temp_dir:
|
||||
assert req.name
|
||||
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
|
||||
'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
|
||||
'Ignoring --build-option when building %s using PEP 517', req.name,
|
||||
)
|
||||
if editable:
|
||||
wheel_path = build_wheel_editable(
|
||||
|
|
@ -282,17 +293,17 @@ def _build_one_inside_env(
|
|||
wheel_hash, length = hash_file(wheel_path)
|
||||
shutil.move(wheel_path, dest_path)
|
||||
logger.info(
|
||||
"Created wheel for %s: filename=%s size=%d sha256=%s",
|
||||
'Created wheel for %s: filename=%s size=%d sha256=%s',
|
||||
req.name,
|
||||
wheel_name,
|
||||
length,
|
||||
wheel_hash.hexdigest(),
|
||||
)
|
||||
logger.info("Stored in directory: %s", output_dir)
|
||||
logger.info('Stored in directory: %s', output_dir)
|
||||
return dest_path
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Building wheel for %s failed: %s",
|
||||
'Building wheel for %s failed: %s',
|
||||
req.name,
|
||||
e,
|
||||
)
|
||||
|
|
@ -302,20 +313,20 @@ def _build_one_inside_env(
|
|||
return None
|
||||
|
||||
|
||||
def _clean_one_legacy(req: InstallRequirement, global_options: List[str]) -> bool:
|
||||
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)
|
||||
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
|
||||
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)
|
||||
logger.error('Failed cleaning build dir for %s', req.name)
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -323,8 +334,8 @@ def build(
|
|||
requirements: Iterable[InstallRequirement],
|
||||
wheel_cache: WheelCache,
|
||||
verify: bool,
|
||||
build_options: List[str],
|
||||
global_options: List[str],
|
||||
build_options: list[str],
|
||||
global_options: list[str],
|
||||
) -> BuildResult:
|
||||
"""Build wheels.
|
||||
|
||||
|
|
@ -336,8 +347,8 @@ def build(
|
|||
|
||||
# Build the wheels.
|
||||
logger.info(
|
||||
"Building wheels for collected packages: %s",
|
||||
", ".join(req.name for req in requirements), # type: ignore
|
||||
'Building wheels for collected packages: %s',
|
||||
', '.join(req.name for req in requirements), # type: ignore
|
||||
)
|
||||
|
||||
with indent_log():
|
||||
|
|
@ -365,13 +376,13 @@ def build(
|
|||
# notify success/failure
|
||||
if build_successes:
|
||||
logger.info(
|
||||
"Successfully built %s",
|
||||
" ".join([req.name for req in build_successes]), # type: ignore
|
||||
'Successfully built %s',
|
||||
' '.join([req.name for req in build_successes]), # type: ignore
|
||||
)
|
||||
if build_failures:
|
||||
logger.info(
|
||||
"Failed to build %s",
|
||||
" ".join([req.name for req in build_failures]), # type: ignore
|
||||
'Failed to build %s',
|
||||
' '.join([req.name for req in build_failures]), # type: ignore
|
||||
)
|
||||
# Return a list of requirements that failed to build
|
||||
return build_successes, build_failures
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue