Skip to content

Commit cb164ef

Browse files
committed
replaced str concat with .write_line(); replaced \t with spaces; removed trailing space in logs
1 parent e0155fb commit cb164ef

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

pre_commit/error_handler.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,32 @@ def _log_and_exit(msg, exc, formatted):
3737
log_path = os.path.join(store.directory, 'pre-commit.log')
3838
output.write_line('Check the log at {}'.format(log_path))
3939

40-
meta_info_msg = '### version information\n```\n'
41-
meta_info_msg += 'pre-commit.version: {}\n'.format(C.VERSION)
42-
meta_info_msg += 'sys.version: \n{}\n'.format(
43-
'\n'.join(
44-
[
45-
'\t{}'.format(line)
46-
for line in sys.version.splitlines()
47-
],
48-
),
49-
)
50-
meta_info_msg += 'sys.executable: {}\n'.format(sys.executable)
51-
meta_info_msg += 'os.name: {}\n'.format(os.name)
52-
meta_info_msg += 'sys.platform: {}\n```\n'.format(sys.platform)
53-
meta_info_msg += '### error information\n```\n'
5440
with open(log_path, 'wb') as log:
55-
output.write(meta_info_msg, stream=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)
5666
output.write(error_msg, stream=log)
5767
output.write_line(formatted, stream=log)
5868
output.write('\n```\n', stream=log)

tests/error_handler_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
115115
r'^### version information\n'
116116
r'```\n'
117117
r'pre-commit.version: \d+\.\d+\.\d+\n'
118-
r'sys.version: (.*\n)*'
118+
r'sys.version:\n( .*\n)*'
119119
r'sys.executable: .*\n'
120120
r'os.name: .*\n'
121121
r'sys.platform: .*\n'

0 commit comments

Comments
 (0)