mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
commit
e3b14c35f7
5 changed files with 17 additions and 18 deletions
|
|
@ -4,7 +4,6 @@ source = .
|
||||||
omit =
|
omit =
|
||||||
.tox/*
|
.tox/*
|
||||||
/usr/*
|
/usr/*
|
||||||
*/tmp*
|
|
||||||
setup.py
|
setup.py
|
||||||
# Don't complain if non-runnable code isn't run
|
# Don't complain if non-runnable code isn't run
|
||||||
*/__main__.py
|
*/__main__.py
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ MANIFEST_HOOK_DICT = schema.Map(
|
||||||
'^$',
|
'^$',
|
||||||
),
|
),
|
||||||
schema.Optional('language_version', schema.check_string, 'default'),
|
schema.Optional('language_version', schema.check_string, 'default'),
|
||||||
schema.OptionalNoDefault('log_file', schema.check_string),
|
schema.Optional('log_file', schema.check_string, ''),
|
||||||
schema.Optional('minimum_pre_commit_version', schema.check_string, '0'),
|
schema.Optional('minimum_pre_commit_version', schema.check_string, '0'),
|
||||||
schema.Optional('stages', schema.check_array(schema.check_string), []),
|
schema.Optional('stages', schema.check_array(schema.check_string), []),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -121,10 +121,7 @@ def _run_single_hook(hook, repo, args, skips, cols):
|
||||||
for out in (stdout, stderr):
|
for out in (stdout, stderr):
|
||||||
assert type(out) is bytes, type(out)
|
assert type(out) is bytes, type(out)
|
||||||
if out.strip():
|
if out.strip():
|
||||||
output.write_line(
|
output.write_line(out.strip(), logfile_name=hook['log_file'])
|
||||||
out.strip(),
|
|
||||||
logfile_name=hook.get('log_file'),
|
|
||||||
)
|
|
||||||
output.write_line()
|
output.write_line()
|
||||||
|
|
||||||
return retcode
|
return retcode
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import sys
|
||||||
|
|
||||||
from pre_commit import color
|
from pre_commit import color
|
||||||
from pre_commit import five
|
from pre_commit import five
|
||||||
|
from pre_commit.util import noop_context
|
||||||
|
|
||||||
|
|
||||||
def get_hook_message(
|
def get_hook_message(
|
||||||
|
|
@ -72,16 +73,16 @@ def write(s, stream=stdout_byte_stream):
|
||||||
|
|
||||||
|
|
||||||
def write_line(s=None, stream=stdout_byte_stream, logfile_name=None):
|
def write_line(s=None, stream=stdout_byte_stream, logfile_name=None):
|
||||||
def output_streams():
|
output_streams = [stream]
|
||||||
yield stream
|
if logfile_name:
|
||||||
try:
|
ctx = open(logfile_name, 'ab')
|
||||||
with open(logfile_name, 'ab') as logfile:
|
output_streams.append(ctx)
|
||||||
yield logfile
|
else:
|
||||||
except (TypeError, IOError):
|
ctx = noop_context()
|
||||||
pass
|
|
||||||
|
|
||||||
for output_stream in output_streams():
|
with ctx:
|
||||||
if s is not None:
|
for output_stream in output_streams:
|
||||||
output_stream.write(five.to_bytes(s))
|
if s is not None:
|
||||||
output_stream.write(b'\n')
|
output_stream.write(five.to_bytes(s))
|
||||||
output_stream.flush()
|
output_stream.write(b'\n')
|
||||||
|
output_stream.flush()
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ def test_manifest_contents(manifest):
|
||||||
'id': 'bash_hook',
|
'id': 'bash_hook',
|
||||||
'language': 'script',
|
'language': 'script',
|
||||||
'language_version': 'default',
|
'language_version': 'default',
|
||||||
|
'log_file': '',
|
||||||
'minimum_pre_commit_version': '0',
|
'minimum_pre_commit_version': '0',
|
||||||
'name': 'Bash hook',
|
'name': 'Bash hook',
|
||||||
'stages': [],
|
'stages': [],
|
||||||
|
|
@ -47,6 +48,7 @@ def test_hooks(manifest):
|
||||||
'id': 'bash_hook',
|
'id': 'bash_hook',
|
||||||
'language': 'script',
|
'language': 'script',
|
||||||
'language_version': 'default',
|
'language_version': 'default',
|
||||||
|
'log_file': '',
|
||||||
'minimum_pre_commit_version': '0',
|
'minimum_pre_commit_version': '0',
|
||||||
'name': 'Bash hook',
|
'name': 'Bash hook',
|
||||||
'stages': [],
|
'stages': [],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue