mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Factor out bash and activate files
This commit is contained in:
parent
00a3a9a09b
commit
a5b56bd9e3
13 changed files with 149 additions and 189 deletions
|
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from sys import platform
|
||||
|
||||
from pre_commit.languages.helpers import file_args_to_stdin
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import shell_escape
|
||||
|
||||
|
||||
|
|
@ -12,29 +12,28 @@ ENVIRONMENT_DIR = None
|
|||
def install_environment(
|
||||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=None,
|
||||
additional_dependencies=(),
|
||||
):
|
||||
"""Installation for pcre type is a noop."""
|
||||
raise AssertionError('Cannot install pcre repo.')
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
grep_command = 'grep -H -n -P'
|
||||
if platform == 'darwin': # pragma: no cover (osx)
|
||||
grep_command = 'ggrep -H -n -P'
|
||||
grep_command = '{0} -H -n -P'.format(
|
||||
'ggrep' if platform == 'darwin' else 'grep',
|
||||
)
|
||||
|
||||
# For PCRE the entry is the regular expression to match
|
||||
return repo_cmd_runner.run(
|
||||
[
|
||||
'xargs', '-0', 'sh', '-c',
|
||||
return helpers.run_hook(
|
||||
(
|
||||
'sh', '-c',
|
||||
# Grep usually returns 0 for matches, and nonzero for non-matches
|
||||
# so we flip it here.
|
||||
'! {0} {1} {2} $@'.format(
|
||||
grep_command, ' '.join(hook['args']),
|
||||
shell_escape(hook['entry'])),
|
||||
shell_escape(hook['entry']),
|
||||
),
|
||||
'--',
|
||||
],
|
||||
stdin=file_args_to_stdin(file_args),
|
||||
retcode=None,
|
||||
encoding=None,
|
||||
),
|
||||
file_args,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue