[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,15 +1,17 @@
from __future__ import annotations
import os
from collections import namedtuple
from typing import Any, List, Optional
from typing import Any
from typing import List
from typing import Optional
from pip._internal.exceptions import InstallationError
from pip._internal.exceptions import InvalidPyProjectBuildRequires
from pip._internal.exceptions import MissingPyProjectBuildRequires
from pip._vendor import tomli
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
from pip._internal.exceptions import (
InstallationError,
InvalidPyProjectBuildRequires,
MissingPyProjectBuildRequires,
)
from pip._vendor.packaging.requirements import InvalidRequirement
from pip._vendor.packaging.requirements import Requirement
def _is_list_of_str(obj: Any) -> bool:
@ -17,17 +19,17 @@ def _is_list_of_str(obj: Any) -> bool:
def make_pyproject_path(unpacked_source_directory: str) -> str:
return os.path.join(unpacked_source_directory, "pyproject.toml")
return os.path.join(unpacked_source_directory, 'pyproject.toml')
BuildSystemDetails = namedtuple(
"BuildSystemDetails", ["requires", "backend", "check", "backend_path"]
'BuildSystemDetails', ['requires', 'backend', 'check', 'backend_path'],
)
def load_pyproject_toml(
use_pep517: Optional[bool], pyproject_toml: str, setup_py: str, req_name: str
) -> Optional[BuildSystemDetails]:
use_pep517: bool | None, pyproject_toml: str, setup_py: str, req_name: str,
) -> BuildSystemDetails | None:
"""Load the pyproject.toml file.
Parameters:
@ -54,14 +56,14 @@ def load_pyproject_toml(
if not has_pyproject and not has_setup:
raise InstallationError(
f"{req_name} does not appear to be a Python project: "
f"neither 'setup.py' nor 'pyproject.toml' found."
f'{req_name} does not appear to be a Python project: '
f"neither 'setup.py' nor 'pyproject.toml' found.",
)
if has_pyproject:
with open(pyproject_toml, encoding="utf-8") as f:
with open(pyproject_toml, encoding='utf-8') as f:
pp_toml = tomli.loads(f.read())
build_system = pp_toml.get("build-system")
build_system = pp_toml.get('build-system')
else:
build_system = None
@ -74,16 +76,16 @@ def load_pyproject_toml(
if has_pyproject and not has_setup:
if use_pep517 is not None and not use_pep517:
raise InstallationError(
"Disabling PEP 517 processing is invalid: "
"project does not have a setup.py"
'Disabling PEP 517 processing is invalid: '
'project does not have a setup.py',
)
use_pep517 = True
elif build_system and "build-backend" in build_system:
elif build_system and 'build-backend' in build_system:
if use_pep517 is not None and not use_pep517:
raise InstallationError(
"Disabling PEP 517 processing is invalid: "
"project specifies a build backend of {} "
"in pyproject.toml".format(build_system["build-backend"])
'Disabling PEP 517 processing is invalid: '
'project specifies a build backend of {} '
'in pyproject.toml'.format(build_system['build-backend']),
)
use_pep517 = True
@ -111,8 +113,8 @@ def load_pyproject_toml(
# a version of setuptools that supports that backend.
build_system = {
"requires": ["setuptools>=40.8.0", "wheel"],
"build-backend": "setuptools.build_meta:__legacy__",
'requires': ['setuptools>=40.8.0', 'wheel'],
'build-backend': 'setuptools.build_meta:__legacy__',
}
# If we're using PEP 517, we have build system information (either
@ -125,15 +127,15 @@ def load_pyproject_toml(
# to PEP 518.
# Specifying the build-system table but not the requires key is invalid
if "requires" not in build_system:
if 'requires' not in build_system:
raise MissingPyProjectBuildRequires(package=req_name)
# Error out if requires is not a list of strings
requires = build_system["requires"]
requires = build_system['requires']
if not _is_list_of_str(requires):
raise InvalidPyProjectBuildRequires(
package=req_name,
reason="It is not a list of strings.",
reason='It is not a list of strings.',
)
# Each requirement must be valid as per PEP 508
@ -143,12 +145,12 @@ def load_pyproject_toml(
except InvalidRequirement as error:
raise InvalidPyProjectBuildRequires(
package=req_name,
reason=f"It contains an invalid requirement: {requirement!r}",
reason=f'It contains an invalid requirement: {requirement!r}',
) from error
backend = build_system.get("build-backend")
backend_path = build_system.get("backend-path", [])
check: List[str] = []
backend = build_system.get('build-backend')
backend_path = build_system.get('backend-path', [])
check: list[str] = []
if backend is None:
# If the user didn't specify a backend, we assume they want to use
# the setuptools backend. But we can't be sure they have included
@ -162,7 +164,7 @@ def load_pyproject_toml(
# execute setup.py, but never considered needing to mention the build
# tools themselves. The original PEP 518 code had a similar check (but
# implemented in a different way).
backend = "setuptools.build_meta:__legacy__"
check = ["setuptools>=40.8.0", "wheel"]
backend = 'setuptools.build_meta:__legacy__'
check = ['setuptools>=40.8.0', 'wheel']
return BuildSystemDetails(requires, backend, check, backend_path)