pre-commit/pre_commit/languages/coursier_launch.py
Joseph Moniz 0603c3c931 Add a coursier_launch integration
This is a follow up to the repository based coursier integration. The
standard coursier integration is to this integration what the docker
integration is to the docker_image integration.

This is meant to target either maven coordinates or coursier apps
directly without depending on a hook repository containing app
descriptors and hook configs making this integration highly suitable
for local hooks.

An example of hook local targets are bellow
```yaml
- repo: local
  hooks:
    - id: scalafmt
      name: scalafmt
      entry: scalafmt # coursier app target
      language: coursier_launch
      files: (\.scala|\.sbt|\.sc)$
    - id: scalafix
      name: scalafix
      entry: ch.epfl.scala:::scalafix-cli:latest.release # maven coordinates target
      language: coursier_launch
      files: (\.scala|\.sbt|\.sc)$
    - id: echo-java
      name: echo-java
      entry: echo-java
      language: coursier_launch
      args: ["--", "hello from java"] # forward arguments to the app
```
2020-11-06 12:55:21 -05:00

21 lines
627 B
Python

from typing import Sequence
from typing import Tuple
from pre_commit.hook import Hook
from pre_commit.languages import helpers
ENVIRONMENT_DIR = None
get_default_version = helpers.basic_get_default_version
healthy = helpers.basic_healthy
install_environment = helpers.no_install
def run_hook(
hook: Hook,
file_args: Sequence[str],
color: bool,
) -> Tuple[int, bytes]: # pragma: win32 no cover
hook_cmd = hook.cmd
forwarded_cmd = hook_cmd if '--' in hook_cmd else hook_cmd + ('--',)
cmd = ('cs', 'launch') + forwarded_cmd
return helpers.run_xargs(hook, cmd, file_args, color=color)