[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,24 +1,25 @@
from __future__ import annotations
import logging
import os
import shlex
import subprocess
from typing import (
TYPE_CHECKING,
Any,
Callable,
Iterable,
List,
Mapping,
Optional,
Union,
)
from typing import Any
from typing import Callable
from typing import Iterable
from typing import List
from typing import Mapping
from typing import Optional
from typing import TYPE_CHECKING
from typing import Union
from pip._vendor.rich.markup import escape
from pip._internal.cli.spinners import SpinnerInterface, open_spinner
from pip._internal.cli.spinners import open_spinner
from pip._internal.cli.spinners import SpinnerInterface
from pip._internal.exceptions import InstallationSubprocessError
from pip._internal.utils.logging import VERBOSE, subprocess_logger
from pip._internal.utils.logging import subprocess_logger
from pip._internal.utils.logging import VERBOSE
from pip._internal.utils.misc import HiddenText
from pip._vendor.rich.markup import escape
if TYPE_CHECKING:
# Literal was introduced in Python 3.8.
@ -29,7 +30,7 @@ if TYPE_CHECKING:
CommandArgs = List[Union[str, HiddenText]]
def make_command(*args: Union[str, HiddenText, CommandArgs]) -> CommandArgs:
def make_command(*args: str | HiddenText | CommandArgs) -> CommandArgs:
"""
Create a CommandArgs object.
"""
@ -46,7 +47,7 @@ def make_command(*args: Union[str, HiddenText, CommandArgs]) -> CommandArgs:
return command_args
def format_command_args(args: Union[List[str], CommandArgs]) -> str:
def format_command_args(args: list[str] | CommandArgs) -> str:
"""
Format command arguments for display.
"""
@ -55,13 +56,13 @@ def format_command_args(args: Union[List[str], CommandArgs]) -> str:
# this can trigger a UnicodeDecodeError in Python 2 if the argument
# has type unicode and includes a non-ascii character. (The type
# checker doesn't ensure the annotations are correct in all cases.)
return " ".join(
return ' '.join(
shlex.quote(str(arg)) if isinstance(arg, HiddenText) else shlex.quote(arg)
for arg in args
)
def reveal_command_args(args: Union[List[str], CommandArgs]) -> List[str]:
def reveal_command_args(args: list[str] | CommandArgs) -> list[str]:
"""
Return the arguments in their raw, unredacted form.
"""
@ -69,16 +70,16 @@ def reveal_command_args(args: Union[List[str], CommandArgs]) -> List[str]:
def call_subprocess(
cmd: Union[List[str], CommandArgs],
cmd: list[str] | CommandArgs,
show_stdout: bool = False,
cwd: Optional[str] = None,
on_returncode: 'Literal["raise", "warn", "ignore"]' = "raise",
extra_ok_returncodes: Optional[Iterable[int]] = None,
extra_environ: Optional[Mapping[str, Any]] = None,
unset_environ: Optional[Iterable[str]] = None,
spinner: Optional[SpinnerInterface] = None,
log_failed_cmd: Optional[bool] = True,
stdout_only: Optional[bool] = False,
cwd: str | None = None,
on_returncode: Literal["raise", "warn", "ignore"] = 'raise',
extra_ok_returncodes: Iterable[int] | None = None,
extra_environ: Mapping[str, Any] | None = None,
unset_environ: Iterable[str] | None = None,
spinner: SpinnerInterface | None = None,
log_failed_cmd: bool | None = True,
stdout_only: bool | None = False,
*,
command_desc: str,
) -> str:
@ -131,7 +132,7 @@ def call_subprocess(
# and we have a spinner.
use_spinner = not showing_subprocess and spinner is not None
log_subprocess("Running command %s", command_desc)
log_subprocess('Running command %s', command_desc)
env = os.environ.copy()
if extra_environ:
env.update(extra_environ)
@ -146,12 +147,12 @@ def call_subprocess(
stderr=subprocess.STDOUT if not stdout_only else subprocess.PIPE,
cwd=cwd,
env=env,
errors="backslashreplace",
errors='backslashreplace',
)
except Exception as exc:
if log_failed_cmd:
subprocess_logger.critical(
"Error %s while executing command %s",
'Error %s while executing command %s',
exc,
command_desc,
)
@ -167,7 +168,7 @@ def call_subprocess(
if not line:
break
line = line.rstrip()
all_output.append(line + "\n")
all_output.append(line + '\n')
# Show the line immediately.
log_subprocess(line)
@ -180,7 +181,7 @@ def call_subprocess(
finally:
if proc.stdout:
proc.stdout.close()
output = "".join(all_output)
output = ''.join(all_output)
else:
# In this mode, stdout and stderr are in different pipes.
# We must use communicate() which is the only safe way to read both.
@ -198,41 +199,41 @@ def call_subprocess(
if use_spinner:
assert spinner
if proc_had_error:
spinner.finish("error")
spinner.finish('error')
else:
spinner.finish("done")
spinner.finish('done')
if proc_had_error:
if on_returncode == "raise":
if on_returncode == 'raise':
error = InstallationSubprocessError(
command_description=command_desc,
exit_code=proc.returncode,
output_lines=all_output if not showing_subprocess else None,
)
if log_failed_cmd:
subprocess_logger.error("[present-diagnostic] %s", error)
subprocess_logger.error('[present-diagnostic] %s', error)
subprocess_logger.verbose(
"[bold magenta]full command[/]: [blue]%s[/]",
'[bold magenta]full command[/]: [blue]%s[/]',
escape(format_command_args(cmd)),
extra={"markup": True},
extra={'markup': True},
)
subprocess_logger.verbose(
"[bold magenta]cwd[/]: %s",
escape(cwd or "[inherit]"),
extra={"markup": True},
'[bold magenta]cwd[/]: %s',
escape(cwd or '[inherit]'),
extra={'markup': True},
)
raise error
elif on_returncode == "warn":
elif on_returncode == 'warn':
subprocess_logger.warning(
'Command "%s" had error code %s in %s',
command_desc,
proc.returncode,
cwd,
)
elif on_returncode == "ignore":
elif on_returncode == 'ignore':
pass
else:
raise ValueError(f"Invalid value: on_returncode={on_returncode!r}")
raise ValueError(f'Invalid value: on_returncode={on_returncode!r}')
return output
@ -244,9 +245,9 @@ def runner_with_spinner_message(message: str) -> Callable[..., None]:
"""
def runner(
cmd: List[str],
cwd: Optional[str] = None,
extra_environ: Optional[Mapping[str, Any]] = None,
cmd: list[str],
cwd: str | None = None,
extra_environ: Mapping[str, Any] | None = None,
) -> None:
with open_spinner(message) as spinner:
call_subprocess(