# Buggy code
def py_interface(
    _dir: str,
    _make_venv: Callable[[str, str], None],
) -> Tuple[
    Callable[[Prefix, str], ContextManager[None]],
    Callable[[Prefix, str], bool],
    Callable[[Hook, Sequence[str], bool], Tuple[int, bytes]],
    Callable[[Prefix, str, Sequence[str]], None],
]:
    @contextlib.contextmanager
    def in_env(
        prefix: Prefix,
        language_version: str,
    ) -> Generator[None, None, None]:
        envdir = prefix.path(helpers.environment_dir(_dir, language_version))
        with envcontext(get_env_patch(envdir)):
            yield

    def healthy(prefix: Prefix, language_version: str) -> bool:
        envdir = helpers.environment_dir(_dir, language_version)
        exe_name = "python.exe" if sys.platform == "win32" else "python"
        py_exe = prefix.path(bin_dir(envdir), exe_name)
        with in_env(prefix, language_version):
            retcode, _, _ = cmd_output_b(
                py_exe,
                "-c",
                "import ctypes, datetime, io, os, ssl, weakref",
                cwd="/",
                retcode=None,
            )
        return retcode == 0

    def run_hook(
        hook: Hook,
        file_args: Sequence[str],
        color: bool,
    ) -> Tuple[int, bytes]:
        with in_env(hook.prefix, hook.language_version):
            return helpers.run_xargs(hook, hook.cmd, file_args, color=color)

    def install_environment(
        prefix: Prefix,
        version: str,
        additional_dependencies: Sequence[str],
    ) -> None:
        additional_dependencies = tuple(additional_dependencies)
        directory = helpers.environment_dir(_dir, version)

        env_dir = prefix.path(directory)
        with clean_path_on_failure(env_dir):
            if version != C.DEFAULT:
                python = norm_version(version)
            else:
                python = os.path.realpath(sys.executable)
            _make_venv(env_dir, python)
            with in_env(prefix, version):
                helpers.run_setup_cmd(
                    prefix,
                    ("pip", "install", ".") + additional_dependencies,
                )

    return in_env, healthy, run_hook, install_environment


# Traceback (pre_commit.util.CalledProcessError)
Traceback (most recent call last):
File "c:\program files\python37\lib\site-packages\pre_commit\error_handler.py", line 56, in error_handler
yield
File "c:\program files\python37\lib\site-packages\pre_commit\main.py", line 372, in main
args=args.rest[1:],
File "c:\program files\python37\lib\site-packages\pre_commit\commands\hook_impl.py", line 187, in hook_impl
return retv | run(config, store, ns)
File "c:\program files\python37\lib\site-packages\pre_commit\commands\run.py", line 355, in run
install_hook_envs(hooks, store)
File "c:\program files\python37\lib\site-packages\pre_commit\repository.py", line 200, in install_hook_envs
_hook_install(hook)
File "c:\program files\python37\lib\site-packages\pre_commit\repository.py", line 83, in _hook_install
hook.prefix, hook.language_version, hook.additional_dependencies,
File "c:\program files\python37\lib\site-packages\pre_commit\languages\python.py", line 197, in install_environment
prefix, ('pip', 'install', '.') + additional_dependencies,
File "c:\program files\python37\lib\site-packages\pre_commit\languages\helpers.py", line 25, in run_setup_cmd
cmd_output_b(*cmd, cwd=prefix.prefix_dir)
File "c:\program files\python37\lib\site-packages\pre_commit\util.py", line 156, in cmd_output_b
raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: <unprintable CalledProcessError object>

# Fixed code
def py_interface(
    _dir: str,
    _make_venv: Callable[[str, str], None],
) -> Tuple[
    Callable[[Prefix, str], ContextManager[None]],
    Callable[[Prefix, str], bool],
    Callable[[Hook, Sequence[str], bool], Tuple[int, bytes]],
    Callable[[Prefix, str, Sequence[str]], None],
]:
    @contextlib.contextmanager
    def in_env(
        prefix: Prefix,
        language_version: str,
    ) -> Generator[None, None, None]:
        envdir = prefix.path(helpers.environment_dir(_dir, language_version))
        with envcontext(get_env_patch(envdir)):
            yield

    def healthy(prefix: Prefix, language_version: str) -> bool:
        envdir = helpers.environment_dir(_dir, language_version)
        exe_name = "python.exe" if sys.platform == "win32" else "python"
        py_exe = prefix.path(bin_dir(envdir), exe_name)
        with in_env(prefix, language_version):
            retcode, _, _ = cmd_output_b(
                py_exe,
                "-c",
                "import ctypes, datetime, io, os, ssl, weakref",
                cwd="/",
                retcode=None,
            )
        return retcode == 0

    def run_hook(
        hook: Hook,
        file_args: Sequence[str],
        color: bool,
    ) -> Tuple[int, bytes]:
        with in_env(hook.prefix, hook.language_version):
            return helpers.run_xargs(hook, hook.cmd, file_args, color=color)

    def install_environment(
        prefix: Prefix,
        version: str,
        additional_dependencies: Sequence[str],
    ) -> None:
        directory = helpers.environment_dir(_dir, version)
        install = ("python", "-mpip", "install", ".", *additional_dependencies)

        env_dir = prefix.path(directory)
        with clean_path_on_failure(env_dir):
            if version != C.DEFAULT:
                python = norm_version(version)
            else:
                python = os.path.realpath(sys.executable)
            _make_venv(env_dir, python)
            with in_env(prefix, version):
                helpers.run_setup_cmd(prefix, install)

    return in_env, healthy, run_hook, install_environment