summaryrefslogtreecommitdiffstats
path: root/pre_commit/lang_base.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-27 10:32:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-27 10:32:18 +0000
commita75e61fbe483eb1f3bbfb2d61d7c15615f56172b (patch)
tree2200a67ca0cbe0c8091c69a447c70c3b0ca0a79c /pre_commit/lang_base.py
parentAdding upstream version 3.0.4. (diff)
downloadpre-commit-upstream/3.1.0.tar.xz
pre-commit-upstream/3.1.0.zip
Adding upstream version 3.1.0.upstream/3.1.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--pre_commit/lang_base.py (renamed from pre_commit/languages/helpers.py)40
1 files changed, 39 insertions, 1 deletions
diff --git a/pre_commit/languages/helpers.py b/pre_commit/lang_base.py
index d1be409..9480c55 100644
--- a/pre_commit/languages/helpers.py
+++ b/pre_commit/lang_base.py
@@ -7,8 +7,10 @@ import random
import re
import shlex
from typing import Any
+from typing import ContextManager
from typing import Generator
from typing import NoReturn
+from typing import Protocol
from typing import Sequence
import pre_commit.constants as C
@@ -22,6 +24,42 @@ FIXED_RANDOM_SEED = 1542676187
SHIMS_RE = re.compile(r'[/\\]shims[/\\]')
+class Language(Protocol):
+ # Use `None` for no installation / environment
+ @property
+ def ENVIRONMENT_DIR(self) -> str | None: ...
+ # return a value to replace `'default` for `language_version`
+ def get_default_version(self) -> str: ...
+ # return whether the environment is healthy (or should be rebuilt)
+ def health_check(self, prefix: Prefix, version: str) -> str | None: ...
+
+ # install a repository for the given language and language_version
+ def install_environment(
+ self,
+ prefix: Prefix,
+ version: str,
+ additional_dependencies: Sequence[str],
+ ) -> None:
+ ...
+
+ # modify the environment for hook execution
+ def in_env(self, prefix: Prefix, version: str) -> ContextManager[None]: ...
+
+ # execute a hook and return the exit code and output
+ def run_hook(
+ self,
+ prefix: Prefix,
+ entry: str,
+ args: Sequence[str],
+ file_args: Sequence[str],
+ *,
+ is_local: bool,
+ require_serial: bool,
+ color: bool,
+ ) -> tuple[int, bytes]:
+ ...
+
+
def exe_exists(exe: str) -> bool:
found = parse_shebang.find_executable(exe)
if found is None: # exe exists
@@ -45,7 +83,7 @@ def exe_exists(exe: str) -> bool:
)
-def run_setup_cmd(prefix: Prefix, cmd: tuple[str, ...], **kwargs: Any) -> None:
+def setup_cmd(prefix: Prefix, cmd: tuple[str, ...], **kwargs: Any) -> None:
cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)