From 02d5100afa71d1343de4066b812cd4cdc774d812 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 30 Jan 2023 17:53:19 +0100 Subject: Adding upstream version 3.0.2. Signed-off-by: Daniel Baumann --- testing/language_helpers.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 testing/language_helpers.py (limited to 'testing/language_helpers.py') diff --git a/testing/language_helpers.py b/testing/language_helpers.py new file mode 100644 index 0000000..f9ae0b1 --- /dev/null +++ b/testing/language_helpers.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +import os +from typing import Sequence + +import pre_commit.constants as C +from pre_commit.languages.all import Language +from pre_commit.prefix import Prefix + + +def run_language( + path: os.PathLike[str], + language: Language, + exe: str, + args: Sequence[str] = (), + file_args: Sequence[str] = (), + version: str = C.DEFAULT, + deps: Sequence[str] = (), + is_local: bool = False, +) -> tuple[int, bytes]: + prefix = Prefix(str(path)) + + language.install_environment(prefix, version, deps) + with language.in_env(prefix, version): + ret, out = language.run_hook( + prefix, + exe, + args, + file_args, + is_local=is_local, + require_serial=True, + color=False, + ) + out = out.replace(b'\r\n', b'\n') + return ret, out -- cgit v1.2.3