Remove pre_commit.five

This commit is contained in:
Anthony Sottile
2020-01-12 11:44:41 -08:00
parent f33716cc17
commit 67c2dcd90d
10 changed files with 33 additions and 60 deletions

View File

@@ -3,10 +3,9 @@ import os.path
import sys
import traceback
from typing import Generator
from typing import Union
from typing import Optional
import pre_commit.constants as C
from pre_commit import five
from pre_commit import output
from pre_commit.store import Store
@@ -15,25 +14,24 @@ class FatalError(RuntimeError):
pass
def _to_bytes(exc: BaseException) -> bytes:
return str(exc).encode()
def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:
error_msg = b''.join((
five.to_bytes(msg), b': ',
five.to_bytes(type(exc).__name__), b': ',
_to_bytes(exc),
msg.encode(), b': ',
type(exc).__name__.encode(), b': ',
str(exc).encode(),
))
output.write_line(error_msg)
output.write_line_b(error_msg)
store = Store()
log_path = os.path.join(store.directory, 'pre-commit.log')
output.write_line(f'Check the log at {log_path}')
with open(log_path, 'wb') as log:
def _log_line(s: Union[None, str, bytes] = None) -> None:
def _log_line(s: Optional[str] = None) -> None:
output.write_line(s, stream=log)
def _log_line_b(s: Optional[bytes] = None) -> None:
output.write_line_b(s, stream=log)
_log_line('### version information')
_log_line()
_log_line('```')
@@ -50,7 +48,7 @@ def _log_and_exit(msg: str, exc: BaseException, formatted: str) -> None:
_log_line('### error information')
_log_line()
_log_line('```')
_log_line(error_msg)
_log_line_b(error_msg)
_log_line('```')
_log_line()
_log_line('```')