mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-06 00:09:15 -06:00
Implement a simplified xargs in python
This commit is contained in:
@@ -12,18 +12,3 @@ def environment_dir(ENVIRONMENT_DIR, language_version):
|
||||
return None
|
||||
else:
|
||||
return '{0}-{1}'.format(ENVIRONMENT_DIR, language_version)
|
||||
|
||||
|
||||
def file_args_to_stdin(file_args):
|
||||
return '\0'.join(list(file_args) + [''])
|
||||
|
||||
|
||||
def run_hook(cmd_args, file_args):
|
||||
return cmd_output(
|
||||
# Use -s 4000 (slightly less than posix mandated minimum)
|
||||
# This is to prevent "xargs: ... Bad file number" on windows
|
||||
'xargs', '-0', '-s4000', *cmd_args,
|
||||
stdin=file_args_to_stdin(file_args),
|
||||
retcode=None,
|
||||
encoding=None
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import Var
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'node_env'
|
||||
@@ -63,6 +64,4 @@ def install_environment(
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
with in_env(repo_cmd_runner, hook['language_version']):
|
||||
return helpers.run_hook(
|
||||
(hook['entry'],) + tuple(hook['args']), file_args,
|
||||
)
|
||||
return xargs((hook['entry'],) + tuple(hook['args']), file_args)
|
||||
|
||||
@@ -2,8 +2,8 @@ from __future__ import unicode_literals
|
||||
|
||||
from sys import platform
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import shell_escape
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -24,7 +24,7 @@ def run_hook(repo_cmd_runner, hook, file_args):
|
||||
)
|
||||
|
||||
# For PCRE the entry is the regular expression to match
|
||||
return helpers.run_hook(
|
||||
return xargs(
|
||||
(
|
||||
'sh', '-c',
|
||||
# Grep usually returns 0 for matches, and nonzero for non-matches
|
||||
|
||||
@@ -10,6 +10,7 @@ from pre_commit.envcontext import UNSET
|
||||
from pre_commit.envcontext import Var
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'py_env'
|
||||
@@ -80,6 +81,4 @@ def install_environment(
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
with in_env(repo_cmd_runner, hook['language_version']):
|
||||
return helpers.run_hook(
|
||||
(hook['entry'],) + tuple(hook['args']), file_args,
|
||||
)
|
||||
return xargs((hook['entry'],) + tuple(hook['args']), file_args)
|
||||
|
||||
@@ -12,6 +12,7 @@ from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import resource_filename
|
||||
from pre_commit.util import tarfile_open
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'rbenv'
|
||||
@@ -125,6 +126,4 @@ def install_environment(
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
with in_env(repo_cmd_runner, hook['language_version']):
|
||||
return helpers.run_hook(
|
||||
(hook['entry'],) + tuple(hook['args']), file_args,
|
||||
)
|
||||
return xargs((hook['entry'],) + tuple(hook['args']), file_args)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -16,7 +16,7 @@ def install_environment(
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
return helpers.run_hook(
|
||||
return xargs(
|
||||
(repo_cmd_runner.prefix_dir + hook['entry'],) + tuple(hook['args']),
|
||||
file_args,
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import shlex
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -18,6 +18,6 @@ def install_environment(
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
return helpers.run_hook(
|
||||
return xargs(
|
||||
tuple(shlex.split(hook['entry'])) + tuple(hook['args']), file_args,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user