# Path: pre_commit/parse_shebang.py
# class ExecutableNotFoundError(OSError):
#     def to_output(self) -> tuple[int, bytes, None]:
# def parse_filename(filename: str) -> tuple[str, ...]:
# def find_executable(
#         exe: str, _environ: Mapping[str, str] | None = None,
# ) -> str | None:
# def normexe(orig: str) -> str:
#     def _error(msg: str) -> NoReturn:
# def normalize_cmd(cmd: tuple[str, ...]) -> tuple[str, ...]:
# 
# Path: pre_commit/util.py
# def cmd_output_b(
#         *cmd: str,
#         retcode: int | None = 0,
#         **kwargs: Any,
# ) -> tuple[int, bytes, bytes | None]:
#     _setdefault_kwargs(kwargs)
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         returncode, stdout_b, stderr_b = e.to_output()
#     else:
#         try:
#             proc = subprocess.Popen(cmd, **kwargs)
#         except OSError as e:
#             returncode, stdout_b, stderr_b = _oserror_to_output(e)
#         else:
#             stdout_b, stderr_b = proc.communicate()
#             returncode = proc.returncode
# 
#     if retcode is not None and retcode != returncode:
#         raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
# 
#     return returncode, stdout_b, stderr_b
# 
# Path: pre_commit/util.py
# def cmd_output_p(
#         *cmd: str,
#         retcode: int | None = 0,
#         **kwargs: Any,
# ) -> tuple[int, bytes, bytes | None]:
#     assert retcode is None
#     assert kwargs['stderr'] == subprocess.STDOUT, kwargs['stderr']
#     _setdefault_kwargs(kwargs)
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         return e.to_output()
# 
#     with open(os.devnull) as devnull, Pty() as pty:
#         assert pty.r is not None
#         kwargs.update({'stdin': devnull, 'stdout': pty.w, 'stderr': pty.w})
#         try:
#             proc = subprocess.Popen(cmd, **kwargs)
#         except OSError as e:
#             return _oserror_to_output(e)
# 
#         pty.close_w()
# 
#         buf = b''
#         while True:
#             try:
#                 bts = os.read(pty.r, 4096)
#             except OSError as e:
#                 if e.errno == errno.EIO:
#                     bts = b''
#                 else:
#                     raise
#             else:
#                 buf += bts
#             if not bts:
#                 break
# 
#     return proc.wait(), buf, None


import concurrent.futures
import contextlib
import math
import os
import subprocess
import sys
from typing import Any
from typing import Callable
from typing import Generator
from typing import Iterable
from typing import MutableMapping
from typing import Sequence
from typing import TypeVar
from pre_commit import parse_shebang
from pre_commit.util import cmd_output_b
from pre_commit.util import cmd_output_p

    return tuple(ret)


@contextlib.contextmanager
def _thread_mapper(maxsize: int) -> Generator[
    Callable[[Callable[[TArg], TRet], Iterable[TArg]], Iterable[TRet]],
    None, None,
]:
    if maxsize == 1:
        yield map
    else:
        with concurrent.futures.ThreadPoolExecutor(maxsize) as ex:
            yield ex.map


def xargs(
        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]:
    """A simplified implementation of xargs.

    color: Make a pty if on a platform that supports it
    target_concurrency: Target number of partitions to run concurrently
    """

# Path: pre_commit/parse_shebang.py
# class ExecutableNotFoundError(OSError):
#     def to_output(self) -> tuple[int, bytes, None]:
# def parse_filename(filename: str) -> tuple[str, ...]:
# def find_executable(
#         exe: str, _environ: Mapping[str, str] | None = None,
# ) -> str | None:
# def normexe(orig: str) -> str:
#     def _error(msg: str) -> NoReturn:
# def normalize_cmd(cmd: tuple[str, ...]) -> tuple[str, ...]:
# 
# Path: pre_commit/util.py
# def cmd_output_b(
#         *cmd: str,
#         retcode: int | None = 0,
#         **kwargs: Any,
# ) -> tuple[int, bytes, bytes | None]:
#     _setdefault_kwargs(kwargs)
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         returncode, stdout_b, stderr_b = e.to_output()
#     else:
#         try:
#             proc = subprocess.Popen(cmd, **kwargs)
#         except OSError as e:
#             returncode, stdout_b, stderr_b = _oserror_to_output(e)
#         else:
#             stdout_b, stderr_b = proc.communicate()
#             returncode = proc.returncode
# 
#     if retcode is not None and retcode != returncode:
#         raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
# 
#     return returncode, stdout_b, stderr_b
# 
# Path: pre_commit/util.py
# def cmd_output_p(
#         *cmd: str,
#         retcode: int | None = 0,
#         **kwargs: Any,
# ) -> tuple[int, bytes, bytes | None]:
#     assert retcode is None
#     assert kwargs['stderr'] == subprocess.STDOUT, kwargs['stderr']
#     _setdefault_kwargs(kwargs)
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         return e.to_output()
# 
#     with open(os.devnull) as devnull, Pty() as pty:
#         assert pty.r is not None
#         kwargs.update({'stdin': devnull, 'stdout': pty.w, 'stderr': pty.w})
#         try:
#             proc = subprocess.Popen(cmd, **kwargs)
#         except OSError as e:
#             return _oserror_to_output(e)
# 
#         pty.close_w()
# 
#         buf = b''
#         while True:
#             try:
#                 bts = os.read(pty.r, 4096)
#             except OSError as e:
#                 if e.errno == errno.EIO:
#                     bts = b''
#                 else:
#                     raise
#             else:
#                 buf += bts
#             if not bts:
#                 break
# 
#     return proc.wait(), buf, None


# Path: pre_commit/xargs.py
import concurrent.futures
import contextlib
import math
import os
import subprocess
import sys
from typing import Any
from typing import Callable
from typing import Generator
from typing import Iterable
from typing import MutableMapping
from typing import Sequence
from typing import TypeVar
from pre_commit import parse_shebang
from pre_commit.util import cmd_output_b
from pre_commit.util import cmd_output_p


    return tuple(ret)


@contextlib.contextmanager
def _thread_mapper(maxsize: int) -> Generator[
    Callable[[Callable[[TArg], TRet], Iterable[TArg]], Iterable[TRet]],
    None, None,
]:
    if maxsize == 1:
        yield map
    else:
        with concurrent.futures.ThreadPoolExecutor(maxsize) as ex:
            yield ex.map


def xargs(
        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]:
    """A simplified implementation of xargs.

    color: Make a pty if on a platform that supports it
    target_concurrency: Target number of partitions to run concurrently
    """

    cmd_fn = cmd_output_p if color else cmd_output_b