Adding upstream version 3.0.2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
cf86d7d6dd
commit
ca00e08dce
107 changed files with 1775 additions and 2323 deletions
|
@ -1,17 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import shlex
|
||||
from typing import Any
|
||||
from typing import Generator
|
||||
from typing import NoReturn
|
||||
from typing import overload
|
||||
from typing import Sequence
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.hook import Hook
|
||||
from pre_commit.prefix import Prefix
|
||||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.xargs import xargs
|
||||
|
@ -48,17 +49,8 @@ def run_setup_cmd(prefix: Prefix, cmd: tuple[str, ...], **kwargs: Any) -> None:
|
|||
cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
|
||||
|
||||
|
||||
@overload
|
||||
def environment_dir(d: None, language_version: str) -> None: ...
|
||||
@overload
|
||||
def environment_dir(d: str, language_version: str) -> str: ...
|
||||
|
||||
|
||||
def environment_dir(d: str | None, language_version: str) -> str | None:
|
||||
if d is None:
|
||||
return None
|
||||
else:
|
||||
return f'{d}-{language_version}'
|
||||
def environment_dir(prefix: Prefix, d: str, language_version: str) -> str:
|
||||
return prefix.path(f'{d}-{language_version}')
|
||||
|
||||
|
||||
def assert_version_default(binary: str, version: str) -> None:
|
||||
|
@ -94,11 +86,16 @@ def no_install(
|
|||
version: str,
|
||||
additional_dependencies: Sequence[str],
|
||||
) -> NoReturn:
|
||||
raise AssertionError('This type is not installable')
|
||||
raise AssertionError('This language is not installable')
|
||||
|
||||
|
||||
def target_concurrency(hook: Hook) -> int:
|
||||
if hook.require_serial or 'PRE_COMMIT_NO_CONCURRENCY' in os.environ:
|
||||
@contextlib.contextmanager
|
||||
def no_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
|
||||
yield
|
||||
|
||||
|
||||
def target_concurrency() -> int:
|
||||
if 'PRE_COMMIT_NO_CONCURRENCY' in os.environ:
|
||||
return 1
|
||||
else:
|
||||
# Travis appears to have a bunch of CPUs, but we can't use them all.
|
||||
|
@ -122,13 +119,40 @@ def _shuffled(seq: Sequence[str]) -> list[str]:
|
|||
|
||||
|
||||
def run_xargs(
|
||||
hook: Hook,
|
||||
cmd: tuple[str, ...],
|
||||
file_args: Sequence[str],
|
||||
**kwargs: Any,
|
||||
*,
|
||||
require_serial: bool,
|
||||
color: bool,
|
||||
) -> tuple[int, bytes]:
|
||||
# Shuffle the files so that they more evenly fill out the xargs partitions,
|
||||
# but do it deterministically in case a hook cares about ordering.
|
||||
file_args = _shuffled(file_args)
|
||||
kwargs['target_concurrency'] = target_concurrency(hook)
|
||||
return xargs(cmd, file_args, **kwargs)
|
||||
if require_serial:
|
||||
jobs = 1
|
||||
else:
|
||||
# Shuffle the files so that they more evenly fill out the xargs
|
||||
# partitions, but do it deterministically in case a hook cares about
|
||||
# ordering.
|
||||
file_args = _shuffled(file_args)
|
||||
jobs = target_concurrency()
|
||||
return xargs(cmd, file_args, target_concurrency=jobs, color=color)
|
||||
|
||||
|
||||
def hook_cmd(entry: str, args: Sequence[str]) -> tuple[str, ...]:
|
||||
return (*shlex.split(entry), *args)
|
||||
|
||||
|
||||
def basic_run_hook(
|
||||
prefix: Prefix,
|
||||
entry: str,
|
||||
args: Sequence[str],
|
||||
file_args: Sequence[str],
|
||||
*,
|
||||
is_local: bool,
|
||||
require_serial: bool,
|
||||
color: bool,
|
||||
) -> tuple[int, bytes]:
|
||||
return run_xargs(
|
||||
hook_cmd(entry, args),
|
||||
file_args,
|
||||
require_serial=require_serial,
|
||||
color=color,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue