Skip to content

Commit 795506a

Browse files
committed
Fix up some newlines in output
1 parent cfc4910 commit 795506a

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

pre_commit/error_handler.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,39 @@ def _log_and_exit(msg, exc, formatted):
3030
error_msg = b''.join((
3131
five.to_bytes(msg), b': ',
3232
five.to_bytes(type(exc).__name__), b': ',
33-
_to_bytes(exc), b'\n',
33+
_to_bytes(exc),
3434
))
35-
output.write(error_msg)
35+
output.write_line(error_msg)
3636
store = Store()
3737
log_path = os.path.join(store.directory, 'pre-commit.log')
3838
output.write_line('Check the log at {}'.format(log_path))
3939

4040
with open(log_path, 'wb') as log:
41-
output.write_line(
42-
'### version information\n```', stream=log,
43-
)
44-
output.write_line(
45-
'pre-commit.version: {}'.format(C.VERSION), stream=log,
46-
)
47-
output.write_line(
48-
'sys.version:\n{}'.format(
49-
'\n'.join(
50-
[
51-
' {}'.format(line)
52-
for line in sys.version.splitlines()
53-
],
54-
),
55-
),
56-
stream=log,
57-
)
58-
output.write_line(
59-
'sys.executable: {}'.format(sys.executable), stream=log,
60-
)
61-
output.write_line('os.name: {}'.format(os.name), stream=log)
62-
output.write_line(
63-
'sys.platform: {}\n```'.format(sys.platform), stream=log,
64-
)
65-
output.write_line('### error information\n```', stream=log)
66-
output.write(error_msg, stream=log)
67-
output.write_line(formatted, stream=log)
68-
output.write('\n```\n', stream=log)
41+
def _log_line(*s): # type: (*str) -> None
42+
output.write_line(*s, stream=log)
43+
44+
_log_line('### version information')
45+
_log_line()
46+
_log_line('```')
47+
_log_line('pre-commit version: {}'.format(C.VERSION))
48+
_log_line('sys.version:')
49+
for line in sys.version.splitlines():
50+
_log_line(' {}'.format(line))
51+
_log_line('sys.executable: {}'.format(sys.executable))
52+
_log_line('os.name: {}'.format(os.name))
53+
_log_line('sys.platform: {}'.format(sys.platform))
54+
_log_line('```')
55+
_log_line()
56+
57+
_log_line('### error information')
58+
_log_line()
59+
_log_line('```')
60+
_log_line(error_msg)
61+
_log_line('```')
62+
_log_line()
63+
_log_line('```')
64+
_log_line(formatted)
65+
_log_line('```')
6966
raise SystemExit(1)
7067

7168

pre_commit/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def to_bytes(self):
103103
),
104104
),
105105
b'Output: ', output[0], b'\n',
106-
b'Errors: ', output[1], b'\n',
106+
b'Errors: ', output[1],
107107
))
108108

109109
def to_text(self):

tests/error_handler_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,25 @@ def test_log_and_exit(cap_out, mock_store_dir):
113113
logged = f.read()
114114
expected = (
115115
r'^### version information\n'
116+
r'\n'
116117
r'```\n'
117-
r'pre-commit.version: \d+\.\d+\.\d+\n'
118-
r'sys.version:\n( .*\n)*'
118+
r'pre-commit version: \d+\.\d+\.\d+\n'
119+
r'sys.version:\n'
120+
r'( .*\n)*'
119121
r'sys.executable: .*\n'
120122
r'os.name: .*\n'
121123
r'sys.platform: .*\n'
122124
r'```\n'
125+
r'\n'
123126
r'### error information\n'
127+
r'\n'
124128
r'```\n'
125129
r'msg: FatalError: hai\n'
126-
r"I'm a stacktrace\n"
130+
r'```\n'
127131
r'\n'
128132
r'```\n'
133+
r"I'm a stacktrace\n"
134+
r'```\n'
129135
)
130136
assert re.match(expected, logged)
131137

tests/util_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_CalledProcessError_str():
2424
'Output: \n'
2525
' stdout\n'
2626
'Errors: \n'
27-
' stderr\n'
27+
' stderr'
2828
)
2929

3030

@@ -37,7 +37,7 @@ def test_CalledProcessError_str_nooutput():
3737
'Return code: 1\n'
3838
'Expected return code: 0\n'
3939
'Output: (none)\n'
40-
'Errors: (none)\n'
40+
'Errors: (none)'
4141
)
4242

4343

0 commit comments

Comments
 (0)