# Path: pre_commit/output.py
# def write(s: str, stream: IO[bytes] = sys.stdout.buffer) -> None:
# def write_line_b(
#         s: bytes | None = None,
#         stream: IO[bytes] = sys.stdout.buffer,
#         logfile_name: str | None = None,
# ) -> None:
# def write_line(s: str | None = None, **kwargs: Any) -> None:
# 
# Path: pre_commit/hook.py
# class Hook(NamedTuple):
#     src: str
#     prefix: Prefix
#     id: str
#     name: str
#     entry: str
#     language: str
#     alias: str
#     files: str
#     exclude: str
#     types: Sequence[str]
#     types_or: Sequence[str]
#     exclude_types: Sequence[str]
#     additional_dependencies: Sequence[str]
#     args: Sequence[str]
#     always_run: bool
#     fail_fast: bool
#     pass_filenames: bool
#     description: str
#     language_version: str
#     log_file: str
#     minimum_pre_commit_version: str
#     require_serial: bool
#     stages: Sequence[str]
#     verbose: bool
# 
#     @property
#     def cmd(self) -> tuple[str, ...]:
#         return (*shlex.split(self.entry), *self.args)
# 
#     @property
#     def install_key(self) -> tuple[Prefix, str, str, tuple[str, ...]]:
#         return (
#             self.prefix,
#             self.language,
#             self.language_version,
#             tuple(self.additional_dependencies),
#         )
# 
#     @classmethod
#     def create(cls, src: str, prefix: Prefix, dct: dict[str, Any]) -> Hook:
#         # TODO: have cfgv do this (?)
#         extra_keys = set(dct) - _KEYS
#         if extra_keys:
#             logger.warning(
#                 f'Unexpected key(s) present on {src} => {dct["id"]}: '
#                 f'{", ".join(sorted(extra_keys))}',
#             )
#         return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
# 
# Path: pre_commit/languages/helpers.py
# FIXED_RANDOM_SEED = 1542676187
# SHIMS_RE = re.compile(r'[/\\]shims[/\\]')
# def exe_exists(exe: str) -> bool:
# def run_setup_cmd(prefix: Prefix, cmd: tuple[str, ...], **kwargs: Any) -> None:
# def environment_dir(d: None, language_version: str) -> None: ...
# def environment_dir(d: str, language_version: str) -> str: ...
# def environment_dir(d: str | None, language_version: str) -> str | None:
# def assert_version_default(binary: str, version: str) -> None:
# def assert_no_additional_deps(
#         lang: str,
#         additional_deps: Sequence[str],
# ) -> None:
# def basic_get_default_version() -> str:
# def basic_healthy(prefix: Prefix, language_version: str) -> bool:
# def no_install(
#         prefix: Prefix,
#         version: str,
#         additional_dependencies: Sequence[str],
# ) -> NoReturn:
# def target_concurrency(hook: Hook) -> int:
# def _shuffled(seq: Sequence[str]) -> list[str]:
# def run_xargs(
#         hook: Hook,
#         cmd: tuple[str, ...],
#         file_args: Sequence[str],
#         **kwargs: Any,
# ) -> tuple[int, bytes]:
# 
# Path: pre_commit/xargs.py
# 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
#     retcode = 0
#     stdout = b''
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         return e.to_output()[:2]
# 
#     # on windows, batch files have a separate length limit than windows itself
#     if (
#             sys.platform == 'win32' and
#             cmd[0].lower().endswith(('.bat', '.cmd'))
#     ):  # pragma: win32 cover
#         # this is implementation details but the command gets translated into
#         # full/path/to/cmd.exe /c *cmd
#         cmd_exe = parse_shebang.find_executable('cmd.exe')
#         # 1024 is additionally subtracted to give headroom for further
#         # expansion inside the batch file
#         _max_length = 8192 - len(cmd_exe) - len(' /c ') - 1024
# 
#     partitions = partition(cmd, varargs, target_concurrency, _max_length)
# 
#     def run_cmd_partition(
#             run_cmd: tuple[str, ...],
#     ) -> tuple[int, bytes, bytes | None]:
#         return cmd_fn(
#             *run_cmd, retcode=None, stderr=subprocess.STDOUT, **kwargs,
#         )
# 
#     threads = min(len(partitions), target_concurrency)
#     with _thread_mapper(threads) as thread_map:
#         results = thread_map(run_cmd_partition, partitions)
# 
#         for proc_retcode, proc_out, _ in results:
#             retcode = max(retcode, proc_retcode)
#             stdout += proc_out
# 
#     return retcode, stdout


import argparse
import re
import sys
from typing import NamedTuple
from typing import Pattern
from typing import Sequence
from pre_commit import output
from pre_commit.hook import Hook
from pre_commit.languages import helpers
from pre_commit.xargs import xargs
from __future__ import annotations



ENVIRONMENT_DIR = None
get_default_version = helpers.basic_get_default_version
healthy = helpers.basic_healthy
install_environment = helpers.no_install


def _process_filename_by_line(pattern: Pattern[bytes], filename: str) -> int:
    retv = 0
    with open(filename, 'rb') as f:
        for line_no, line in enumerate(f, start=1):
            if pattern.search(line):
                retv = 1

# Path: pre_commit/output.py
# def write(s: str, stream: IO[bytes] = sys.stdout.buffer) -> None:
# def write_line_b(
#         s: bytes | None = None,
#         stream: IO[bytes] = sys.stdout.buffer,
#         logfile_name: str | None = None,
# ) -> None:
# def write_line(s: str | None = None, **kwargs: Any) -> None:
# 
# Path: pre_commit/hook.py
# class Hook(NamedTuple):
#     src: str
#     prefix: Prefix
#     id: str
#     name: str
#     entry: str
#     language: str
#     alias: str
#     files: str
#     exclude: str
#     types: Sequence[str]
#     types_or: Sequence[str]
#     exclude_types: Sequence[str]
#     additional_dependencies: Sequence[str]
#     args: Sequence[str]
#     always_run: bool
#     fail_fast: bool
#     pass_filenames: bool
#     description: str
#     language_version: str
#     log_file: str
#     minimum_pre_commit_version: str
#     require_serial: bool
#     stages: Sequence[str]
#     verbose: bool
# 
#     @property
#     def cmd(self) -> tuple[str, ...]:
#         return (*shlex.split(self.entry), *self.args)
# 
#     @property
#     def install_key(self) -> tuple[Prefix, str, str, tuple[str, ...]]:
#         return (
#             self.prefix,
#             self.language,
#             self.language_version,
#             tuple(self.additional_dependencies),
#         )
# 
#     @classmethod
#     def create(cls, src: str, prefix: Prefix, dct: dict[str, Any]) -> Hook:
#         # TODO: have cfgv do this (?)
#         extra_keys = set(dct) - _KEYS
#         if extra_keys:
#             logger.warning(
#                 f'Unexpected key(s) present on {src} => {dct["id"]}: '
#                 f'{", ".join(sorted(extra_keys))}',
#             )
#         return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
# 
# Path: pre_commit/languages/helpers.py
# FIXED_RANDOM_SEED = 1542676187
# SHIMS_RE = re.compile(r'[/\\]shims[/\\]')
# def exe_exists(exe: str) -> bool:
# def run_setup_cmd(prefix: Prefix, cmd: tuple[str, ...], **kwargs: Any) -> None:
# def environment_dir(d: None, language_version: str) -> None: ...
# def environment_dir(d: str, language_version: str) -> str: ...
# def environment_dir(d: str | None, language_version: str) -> str | None:
# def assert_version_default(binary: str, version: str) -> None:
# def assert_no_additional_deps(
#         lang: str,
#         additional_deps: Sequence[str],
# ) -> None:
# def basic_get_default_version() -> str:
# def basic_healthy(prefix: Prefix, language_version: str) -> bool:
# def no_install(
#         prefix: Prefix,
#         version: str,
#         additional_dependencies: Sequence[str],
# ) -> NoReturn:
# def target_concurrency(hook: Hook) -> int:
# def _shuffled(seq: Sequence[str]) -> list[str]:
# def run_xargs(
#         hook: Hook,
#         cmd: tuple[str, ...],
#         file_args: Sequence[str],
#         **kwargs: Any,
# ) -> tuple[int, bytes]:
# 
# Path: pre_commit/xargs.py
# 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
#     retcode = 0
#     stdout = b''
# 
#     try:
#         cmd = parse_shebang.normalize_cmd(cmd)
#     except parse_shebang.ExecutableNotFoundError as e:
#         return e.to_output()[:2]
# 
#     # on windows, batch files have a separate length limit than windows itself
#     if (
#             sys.platform == 'win32' and
#             cmd[0].lower().endswith(('.bat', '.cmd'))
#     ):  # pragma: win32 cover
#         # this is implementation details but the command gets translated into
#         # full/path/to/cmd.exe /c *cmd
#         cmd_exe = parse_shebang.find_executable('cmd.exe')
#         # 1024 is additionally subtracted to give headroom for further
#         # expansion inside the batch file
#         _max_length = 8192 - len(cmd_exe) - len(' /c ') - 1024
# 
#     partitions = partition(cmd, varargs, target_concurrency, _max_length)
# 
#     def run_cmd_partition(
#             run_cmd: tuple[str, ...],
#     ) -> tuple[int, bytes, bytes | None]:
#         return cmd_fn(
#             *run_cmd, retcode=None, stderr=subprocess.STDOUT, **kwargs,
#         )
# 
#     threads = min(len(partitions), target_concurrency)
#     with _thread_mapper(threads) as thread_map:
#         results = thread_map(run_cmd_partition, partitions)
# 
#         for proc_retcode, proc_out, _ in results:
#             retcode = max(retcode, proc_retcode)
#             stdout += proc_out
# 
#     return retcode, stdout


# Path: pre_commit/languages/pygrep.py
import argparse
import re
import sys
from typing import NamedTuple
from typing import Pattern
from typing import Sequence
from pre_commit import output
from pre_commit.hook import Hook
from pre_commit.languages import helpers
from pre_commit.xargs import xargs

from __future__ import annotations



ENVIRONMENT_DIR = None
get_default_version = helpers.basic_get_default_version
healthy = helpers.basic_healthy
install_environment = helpers.no_install


def _process_filename_by_line(pattern: Pattern[bytes], filename: str) -> int:
    retv = 0
    with open(filename, 'rb') as f:
        for line_no, line in enumerate(f, start=1):
            if pattern.search(line):
                retv = 1

                output.write(f'{filename}:{line_no}:')