Added powershell support

This commit is contained in:
Walluce Pinkham 2022-04-13 09:08:12 +01:00
parent 835396c645
commit f2e3803913
5 changed files with 43 additions and 2 deletions

View file

@ -0,0 +1,21 @@
from __future__ import annotations
from typing import Sequence
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
fullpath = (hook.prefix.prefix_dir + '\\' + hook.cmd[0])
cmd = ('pwsh', '-F') + (fullpath,)
return helpers.run_xargs(hook, cmd, file_args, color=color)

View file

@ -5,8 +5,8 @@ import sys
LANGUAGES = [ LANGUAGES = [
'conda', 'coursier', 'dart', 'docker', 'docker_image', 'dotnet', 'fail', 'conda', 'coursier', 'dart', 'docker', 'docker_image', 'dotnet', 'fail',
'golang', 'lua', 'node', 'perl', 'pygrep', 'python', 'r', 'ruby', 'rust', 'golang', 'lua', 'node', 'perl', 'powershell', 'pygrep', 'python', 'r',
'script', 'swift', 'system', 'ruby', 'rust', 'script', 'swift', 'system',
] ]
FIELDS = [ FIELDS = [
'ENVIRONMENT_DIR', 'get_default_version', 'healthy', 'install_environment', 'ENVIRONMENT_DIR', 'get_default_version', 'healthy', 'install_environment',

View file

@ -0,0 +1,6 @@
- id: powershell-example-hook
name: Test Powershell Project
description: Test Powershell Project
entry: test-script.ps1
language: powershell
stages: [commit]

View file

@ -0,0 +1,2 @@
Write-Output "Hello from Powershell"
exit 0

View file

@ -1162,3 +1162,15 @@ def test_local_lua_additional_dependencies(store):
ret, out = _hook_run(hook, (), color=False) ret, out = _hook_run(hook, (), color=False)
assert b'Luacheck' in out assert b'Luacheck' in out
assert ret == 0 assert ret == 0
@pytest.mark.parametrize(
'repo',
(
'powershell_repo',
),
)
def test_dotnet_hook(tempdir_factory, store, repo):
_test_hook_repo(
tempdir_factory, store, repo,
'powershell-example-hook', [], b'Hello from Powershell\n',
)