Adding upstream version 3.4.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
dc2cdb17e0
commit
0db83eaf7b
13 changed files with 183 additions and 19 deletions
|
@ -9,6 +9,7 @@ from pre_commit.languages import docker_image
|
|||
from pre_commit.languages import dotnet
|
||||
from pre_commit.languages import fail
|
||||
from pre_commit.languages import golang
|
||||
from pre_commit.languages import haskell
|
||||
from pre_commit.languages import lua
|
||||
from pre_commit.languages import node
|
||||
from pre_commit.languages import perl
|
||||
|
@ -31,6 +32,7 @@ languages: dict[str, Language] = {
|
|||
'dotnet': dotnet,
|
||||
'fail': fail,
|
||||
'golang': golang,
|
||||
'haskell': haskell,
|
||||
'lua': lua,
|
||||
'node': node,
|
||||
'perl': perl,
|
||||
|
|
|
@ -103,8 +103,7 @@ def _install_hook_script(
|
|||
|
||||
hook_file.write(before + TEMPLATE_START)
|
||||
hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\n')
|
||||
# TODO: python3.8+: shlex.join
|
||||
args_s = ' '.join(shlex.quote(part) for part in args)
|
||||
args_s = shlex.join(args)
|
||||
hook_file.write(f'ARGS=({args_s})\n')
|
||||
hook_file.write(TEMPLATE_END + after)
|
||||
make_executable(hook_path)
|
||||
|
|
56
pre_commit/languages/haskell.py
Normal file
56
pre_commit/languages/haskell.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import os.path
|
||||
from typing import Generator
|
||||
from typing import Sequence
|
||||
|
||||
from pre_commit import lang_base
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import PatchesT
|
||||
from pre_commit.envcontext import Var
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.prefix import Prefix
|
||||
|
||||
ENVIRONMENT_DIR = 'hs_env'
|
||||
get_default_version = lang_base.basic_get_default_version
|
||||
health_check = lang_base.basic_health_check
|
||||
run_hook = lang_base.basic_run_hook
|
||||
|
||||
|
||||
def get_env_patch(target_dir: str) -> PatchesT:
|
||||
bin_path = os.path.join(target_dir, 'bin')
|
||||
return (('PATH', (bin_path, os.pathsep, Var('PATH'))),)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
|
||||
envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
||||
with envcontext(get_env_patch(envdir)):
|
||||
yield
|
||||
|
||||
|
||||
def install_environment(
|
||||
prefix: Prefix,
|
||||
version: str,
|
||||
additional_dependencies: Sequence[str],
|
||||
) -> None:
|
||||
lang_base.assert_version_default('haskell', version)
|
||||
envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
||||
|
||||
pkgs = [*prefix.star('.cabal'), *additional_dependencies]
|
||||
if not pkgs:
|
||||
raise FatalError('Expected .cabal files or additional_dependencies')
|
||||
|
||||
bindir = os.path.join(envdir, 'bin')
|
||||
os.makedirs(bindir, exist_ok=True)
|
||||
lang_base.setup_cmd(prefix, ('cabal', 'update'))
|
||||
lang_base.setup_cmd(
|
||||
prefix,
|
||||
(
|
||||
'cabal', 'install',
|
||||
'--install-method', 'copy',
|
||||
'--installdir', bindir,
|
||||
*pkgs,
|
||||
),
|
||||
)
|
|
@ -24,6 +24,14 @@ TRet = TypeVar('TRet')
|
|||
|
||||
|
||||
def cpu_count() -> int:
|
||||
try:
|
||||
# On systems that support it, this will return a more accurate count of
|
||||
# usable CPUs for the current process, which will take into account
|
||||
# cgroup limits
|
||||
return len(os.sched_getaffinity(0))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return multiprocessing.cpu_count()
|
||||
except NotImplementedError:
|
||||
|
@ -170,7 +178,8 @@ def xargs(
|
|||
results = thread_map(run_cmd_partition, partitions)
|
||||
|
||||
for proc_retcode, proc_out, _ in results:
|
||||
retcode = max(retcode, proc_retcode)
|
||||
if abs(proc_retcode) > abs(retcode):
|
||||
retcode = proc_retcode
|
||||
stdout += proc_out
|
||||
|
||||
return retcode, stdout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue