summaryrefslogtreecommitdiffstats
path: root/pre_commit/xargs.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/xargs.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/xargs.py')
-rw-r--r--pre_commit/xargs.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/pre_commit/xargs.py b/pre_commit/xargs.py
index 6b0fa20..f2b3421 100644
--- a/pre_commit/xargs.py
+++ b/pre_commit/xargs.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import concurrent.futures
import contextlib
import math
@@ -8,11 +10,8 @@ from typing import Any
from typing import Callable
from typing import Generator
from typing import Iterable
-from typing import List
from typing import MutableMapping
-from typing import Optional
from typing import Sequence
-from typing import Tuple
from typing import TypeVar
from pre_commit import parse_shebang
@@ -23,7 +22,7 @@ TArg = TypeVar('TArg')
TRet = TypeVar('TRet')
-def _environ_size(_env: Optional[MutableMapping[str, str]] = None) -> int:
+def _environ_size(_env: MutableMapping[str, str] | None = None) -> int:
environ = _env if _env is not None else getattr(os, 'environb', os.environ)
size = 8 * len(environ) # number of pointers in `envp`
for k, v in environ.items():
@@ -62,8 +61,8 @@ def partition(
cmd: Sequence[str],
varargs: Sequence[str],
target_concurrency: int,
- _max_length: Optional[int] = None,
-) -> Tuple[Tuple[str, ...], ...]:
+ _max_length: int | None = None,
+) -> tuple[tuple[str, ...], ...]:
_max_length = _max_length or _get_platform_max_length()
# Generally, we try to partition evenly into at least `target_concurrency`
@@ -73,7 +72,7 @@ def partition(
cmd = tuple(cmd)
ret = []
- ret_cmd: List[str] = []
+ ret_cmd: list[str] = []
# Reversed so arguments are in order
varargs = list(reversed(varargs))
@@ -115,14 +114,14 @@ def _thread_mapper(maxsize: int) -> Generator[
def xargs(
- cmd: Tuple[str, ...],
+ cmd: tuple[str, ...],
varargs: Sequence[str],
*,
color: bool = False,
target_concurrency: int = 1,
_max_length: int = _get_platform_max_length(),
**kwargs: Any,
-) -> Tuple[int, bytes]:
+) -> tuple[int, bytes]:
"""A simplified implementation of xargs.
color: Make a pty if on a platform that supports it
@@ -152,8 +151,8 @@ def xargs(
partitions = partition(cmd, varargs, target_concurrency, _max_length)
def run_cmd_partition(
- run_cmd: Tuple[str, ...],
- ) -> Tuple[int, bytes, Optional[bytes]]:
+ run_cmd: tuple[str, ...],
+ ) -> tuple[int, bytes, bytes | None]:
return cmd_fn(
*run_cmd, retcode=None, stderr=subprocess.STDOUT, **kwargs,
)