summaryrefslogtreecommitdiffstats
path: root/pre_commit/languages/helpers.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-04 18:42:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-04 18:42:11 +0000
commit361ff4da262b4891323287049e9e6c5fbe1d01dc (patch)
tree969b376a2c170841758d39ef9516dac65c8b94cd /pre_commit/languages/helpers.py
parentAdding upstream version 2.17.0. (diff)
downloadpre-commit-361ff4da262b4891323287049e9e6c5fbe1d01dc.tar.xz
pre-commit-361ff4da262b4891323287049e9e6c5fbe1d01dc.zip
Adding upstream version 2.18.1.upstream/2.18.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/languages/helpers.py')
-rw-r--r--pre_commit/languages/helpers.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/pre_commit/languages/helpers.py b/pre_commit/languages/helpers.py
index 276ce16..8080826 100644
--- a/pre_commit/languages/helpers.py
+++ b/pre_commit/languages/helpers.py
@@ -1,13 +1,12 @@
+from __future__ import annotations
+
import multiprocessing
import os
import random
import re
from typing import Any
-from typing import List
-from typing import Optional
from typing import overload
from typing import Sequence
-from typing import Tuple
from typing import TYPE_CHECKING
import pre_commit.constants as C
@@ -32,7 +31,7 @@ def exe_exists(exe: str) -> bool:
homedir = os.path.expanduser('~')
try:
- common: Optional[str] = os.path.commonpath((found, homedir))
+ common: str | None = os.path.commonpath((found, homedir))
except ValueError: # on windows, different drives raises ValueError
common = None
@@ -48,7 +47,7 @@ def exe_exists(exe: str) -> bool:
)
-def run_setup_cmd(prefix: Prefix, cmd: Tuple[str, ...], **kwargs: Any) -> None:
+def run_setup_cmd(prefix: Prefix, cmd: tuple[str, ...], **kwargs: Any) -> None:
cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
@@ -58,7 +57,7 @@ def environment_dir(d: None, language_version: str) -> None: ...
def environment_dir(d: str, language_version: str) -> str: ...
-def environment_dir(d: Optional[str], language_version: str) -> Optional[str]:
+def environment_dir(d: str | None, language_version: str) -> str | None:
if d is None:
return None
else:
@@ -68,7 +67,8 @@ def environment_dir(d: Optional[str], language_version: str) -> Optional[str]:
def assert_version_default(binary: str, version: str) -> None:
if version != C.DEFAULT:
raise AssertionError(
- f'For now, pre-commit requires system-installed {binary}',
+ f'for now, pre-commit requires system-installed {binary} -- '
+ f'you selected `language_version: {version}`',
)
@@ -78,8 +78,9 @@ def assert_no_additional_deps(
) -> None:
if additional_deps:
raise AssertionError(
- f'For now, pre-commit does not support '
- f'additional_dependencies for {lang}',
+ f'for now, pre-commit does not support '
+ f'additional_dependencies for {lang} -- '
+ f'you selected `additional_dependencies: {additional_deps}`',
)
@@ -95,7 +96,7 @@ def no_install(
prefix: Prefix,
version: str,
additional_dependencies: Sequence[str],
-) -> 'NoReturn':
+) -> NoReturn:
raise AssertionError('This type is not installable')
@@ -113,7 +114,7 @@ def target_concurrency(hook: Hook) -> int:
return 1
-def _shuffled(seq: Sequence[str]) -> List[str]:
+def _shuffled(seq: Sequence[str]) -> list[str]:
"""Deterministically shuffle"""
fixed_random = random.Random()
fixed_random.seed(FIXED_RANDOM_SEED, version=1)
@@ -125,10 +126,10 @@ def _shuffled(seq: Sequence[str]) -> List[str]:
def run_xargs(
hook: Hook,
- cmd: Tuple[str, ...],
+ cmd: tuple[str, ...],
file_args: Sequence[str],
**kwargs: Any,
-) -> Tuple[int, bytes]:
+) -> 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)