mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 00:24:47 +04:00
Fixup log_file commit
This commit is contained in:
parent
71e500a177
commit
840a55bbc3
5 changed files with 17 additions and 18 deletions
|
|
@ -53,7 +53,7 @@ MANIFEST_HOOK_DICT = schema.Map(
|
|||
'^$',
|
||||
),
|
||||
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('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):
|
||||
assert type(out) is bytes, type(out)
|
||||
if out.strip():
|
||||
output.write_line(
|
||||
out.strip(),
|
||||
logfile_name=hook.get('log_file'),
|
||||
)
|
||||
output.write_line(out.strip(), logfile_name=hook['log_file'])
|
||||
output.write_line()
|
||||
|
||||
return retcode
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import sys
|
|||
|
||||
from pre_commit import color
|
||||
from pre_commit import five
|
||||
from pre_commit.util import noop_context
|
||||
|
||||
|
||||
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 output_streams():
|
||||
yield stream
|
||||
try:
|
||||
with open(logfile_name, 'ab') as logfile:
|
||||
yield logfile
|
||||
except (TypeError, IOError):
|
||||
pass
|
||||
output_streams = [stream]
|
||||
if logfile_name:
|
||||
ctx = open(logfile_name, 'ab')
|
||||
output_streams.append(ctx)
|
||||
else:
|
||||
ctx = noop_context()
|
||||
|
||||
for output_stream in output_streams():
|
||||
if s is not None:
|
||||
output_stream.write(five.to_bytes(s))
|
||||
output_stream.write(b'\n')
|
||||
output_stream.flush()
|
||||
with ctx:
|
||||
for output_stream in output_streams:
|
||||
if s is not None:
|
||||
output_stream.write(five.to_bytes(s))
|
||||
output_stream.write(b'\n')
|
||||
output_stream.flush()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue