summaryrefslogtreecommitdiffstats
path: root/pre_commit/languages/coursier.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit/languages/coursier.py')
-rw-r--r--pre_commit/languages/coursier.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/pre_commit/languages/coursier.py b/pre_commit/languages/coursier.py
index 2841467..bb3e0b8 100644
--- a/pre_commit/languages/coursier.py
+++ b/pre_commit/languages/coursier.py
@@ -1,14 +1,16 @@
+from __future__ import annotations
+
import contextlib
import os
from typing import Generator
from typing import Sequence
-from typing import Tuple
from pre_commit.envcontext import envcontext
from pre_commit.envcontext import PatchesT
from pre_commit.envcontext import Var
from pre_commit.hook import Hook
from pre_commit.languages import helpers
+from pre_commit.parse_shebang import find_executable
from pre_commit.prefix import Prefix
from pre_commit.util import clean_path_on_failure
@@ -26,6 +28,14 @@ def install_environment(
helpers.assert_version_default('coursier', version)
helpers.assert_no_additional_deps('coursier', additional_dependencies)
+ # Support both possible executable names (either "cs" or "coursier")
+ executable = find_executable('cs') or find_executable('coursier')
+ if executable is None:
+ raise AssertionError(
+ 'pre-commit requires system-installed "cs" or "coursier" '
+ 'executables in the application search path',
+ )
+
envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version))
channel = prefix.path('.pre-commit-channel')
with clean_path_on_failure(envdir):
@@ -35,7 +45,7 @@ def install_environment(
helpers.run_setup_cmd(
prefix,
(
- 'cs',
+ executable,
'install',
'--default-channels=false',
f'--channel={channel}',
@@ -66,6 +76,6 @@ def run_hook(
hook: Hook,
file_args: Sequence[str],
color: bool,
-) -> Tuple[int, bytes]: # pragma: win32 no cover
+) -> tuple[int, bytes]: # pragma: win32 no cover
with in_env(hook.prefix):
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)