mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Add initial implementation for running SBT commands.
This commit is contained in:
parent
81db32e148
commit
163e418754
10 changed files with 185 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ from pre_commit.languages import python
|
|||
from pre_commit.languages import r
|
||||
from pre_commit.languages import ruby
|
||||
from pre_commit.languages import rust
|
||||
from pre_commit.languages import sbt
|
||||
from pre_commit.languages import script
|
||||
from pre_commit.languages import swift
|
||||
from pre_commit.languages import system
|
||||
|
|
@ -60,6 +61,7 @@ languages = {
|
|||
'r': Language(name='r', ENVIRONMENT_DIR=r.ENVIRONMENT_DIR, get_default_version=r.get_default_version, health_check=r.health_check, install_environment=r.install_environment, run_hook=r.run_hook), # noqa: E501
|
||||
'ruby': Language(name='ruby', ENVIRONMENT_DIR=ruby.ENVIRONMENT_DIR, get_default_version=ruby.get_default_version, health_check=ruby.health_check, install_environment=ruby.install_environment, run_hook=ruby.run_hook), # noqa: E501
|
||||
'rust': Language(name='rust', ENVIRONMENT_DIR=rust.ENVIRONMENT_DIR, get_default_version=rust.get_default_version, health_check=rust.health_check, install_environment=rust.install_environment, run_hook=rust.run_hook), # noqa: E501
|
||||
'sbt': Language(name='sbt', ENVIRONMENT_DIR=sbt.ENVIRONMENT_DIR, get_default_version=sbt.get_default_version, health_check=sbt.health_check, install_environment=sbt.install_environment, run_hook=sbt.run_hook), # noqa: E501
|
||||
'script': Language(name='script', ENVIRONMENT_DIR=script.ENVIRONMENT_DIR, get_default_version=script.get_default_version, health_check=script.health_check, install_environment=script.install_environment, run_hook=script.run_hook), # noqa: E501
|
||||
'swift': Language(name='swift', ENVIRONMENT_DIR=swift.ENVIRONMENT_DIR, get_default_version=swift.get_default_version, health_check=swift.health_check, install_environment=swift.install_environment, run_hook=swift.run_hook), # noqa: E501
|
||||
'system': Language(name='system', ENVIRONMENT_DIR=system.ENVIRONMENT_DIR, get_default_version=system.get_default_version, health_check=system.health_check, install_environment=system.install_environment, run_hook=system.run_hook), # noqa: E501
|
||||
|
|
|
|||
44
pre_commit/languages/sbt.py
Normal file
44
pre_commit/languages/sbt.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Sequence
|
||||
|
||||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages import helpers
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
install_environment = helpers.no_install
|
||||
health_check = helpers.basic_health_check
|
||||
get_default_version = helpers.basic_get_default_version
|
||||
|
||||
|
||||
def run_hook(
|
||||
hook: Hook,
|
||||
file_args: Sequence[str],
|
||||
color: bool,
|
||||
) -> tuple[int, bytes]:
|
||||
# TODO: Improve impl to connect to run commands via SBT server
|
||||
return run_sbt_hook_via_commandline(hook, file_args, color)
|
||||
|
||||
|
||||
def run_sbt_hook_via_commandline(
|
||||
hook: Hook,
|
||||
file_args: Sequence[str],
|
||||
color: bool,
|
||||
) -> tuple[int, bytes]:
|
||||
"""
|
||||
Run an SBT hook, via the commandline. The command to be run is:
|
||||
sbt ${entry} ${args} ${files}
|
||||
The entry and args will not be quoted (so should be wrapped in quotes as
|
||||
appropriate by the hook author),however files will be quoted, so any
|
||||
filenames with spaces will be interpreted as a single argument by SBT
|
||||
"""
|
||||
entry_part = hook.entry
|
||||
args_part = ' '.join(hook.args)
|
||||
files_part = ' '.join(_quote(file) for file in file_args)
|
||||
sbt_command = f'{entry_part} {args_part} {files_part}'
|
||||
shell_cmd = ('sbt', sbt_command)
|
||||
return helpers.run_xargs(hook, shell_cmd, [], color=color)
|
||||
|
||||
|
||||
def _quote(s: str) -> str:
|
||||
return f"\"{s}\""
|
||||
Loading…
Add table
Add a link
Reference in a new issue