Skip to content

Commit

Permalink
Merge pull request #535 from pre-commit/fixup
Browse files Browse the repository at this point in the history
Fixup log_file commit
  • Loading branch information
asottile committed May 9, 2017
2 parents 71e500a + 840a55b commit e3b14c3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Expand Up @@ -4,7 +4,6 @@ source = .
omit =
.tox/*
/usr/*
*/tmp*
setup.py
# Don't complain if non-runnable code isn't run
*/__main__.py
Expand Down
2 changes: 1 addition & 1 deletion pre_commit/clientlib.py
Expand Up @@ -53,7 +53,7 @@ def _make_argparser(filenames_help):
'^$',
),
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), []),
)
Expand Down
5 changes: 1 addition & 4 deletions pre_commit/commands/run.py
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions pre_commit/output.py
Expand Up @@ -4,6 +4,7 @@

from pre_commit import color
from pre_commit import five
from pre_commit.util import noop_context


def get_hook_message(
Expand Down Expand Up @@ -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

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()
output_streams = [stream]
if logfile_name:
ctx = open(logfile_name, 'ab')
output_streams.append(ctx)
else:
ctx = noop_context()

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()
2 changes: 2 additions & 0 deletions tests/manifest_test.py
Expand Up @@ -29,6 +29,7 @@ def test_manifest_contents(manifest):
'id': 'bash_hook',
'language': 'script',
'language_version': 'default',
'log_file': '',
'minimum_pre_commit_version': '0',
'name': 'Bash hook',
'stages': [],
Expand All @@ -47,6 +48,7 @@ def test_hooks(manifest):
'id': 'bash_hook',
'language': 'script',
'language_version': 'default',
'log_file': '',
'minimum_pre_commit_version': '0',
'name': 'Bash hook',
'stages': [],
Expand Down

0 comments on commit e3b14c3

Please sign in to comment.