Skip to content

Commit 18c9e06

Browse files
committed
Small cleanups
1 parent e717df0 commit 18c9e06

17 files changed

+40
-58
lines changed

pre_commit/clientlib.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import pre_commit.constants as C
1212
from pre_commit import schema
13-
from pre_commit.errors import FatalError
13+
from pre_commit.error_handler import FatalError
1414
from pre_commit.languages.all import all_languages
1515

1616

@@ -51,8 +51,7 @@ def _make_argparser(filenames_help):
5151
'',
5252
),
5353
schema.Optional(
54-
'exclude',
55-
schema.check_and(schema.check_string, schema.check_regex),
54+
'exclude', schema.check_and(schema.check_string, schema.check_regex),
5655
'^$',
5756
),
5857
schema.Optional('types', schema.check_array(check_type_tag), ['file']),

pre_commit/color.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,4 @@ def use_color(setting):
4747
if setting not in COLOR_CHOICES:
4848
raise InvalidColorSetting(setting)
4949

50-
return (
51-
setting == 'always' or
52-
(setting == 'auto' and sys.stdout.isatty())
53-
)
50+
return setting == 'always' or (setting == 'auto' and sys.stdout.isatty())

pre_commit/color_windows.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import absolute_import
12
from __future__ import unicode_literals
23

34
from ctypes import POINTER
@@ -19,8 +20,7 @@ def bool_errcheck(result, func, args):
1920

2021

2122
GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(
22-
("GetStdHandle", windll.kernel32),
23-
((1, "nStdHandle"), ),
23+
("GetStdHandle", windll.kernel32), ((1, "nStdHandle"),),
2424
)
2525

2626
GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
@@ -42,7 +42,6 @@ def enable_virtual_terminal_processing():
4242
4343
More info on the escape sequences supported:
4444
https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx
45-
4645
"""
4746
stdout = GetStdHandle(STD_OUTPUT_HANDLE)
4847
flags = GetConsoleMode(stdout)

pre_commit/commands/run.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def _get_skips(environ):
3232

3333
def _hook_msg_start(hook, verbose):
3434
return '{}{}'.format(
35-
'[{}] '.format(hook['id']) if verbose else '',
36-
hook['name'],
35+
'[{}] '.format(hook['id']) if verbose else '', hook['name'],
3736
)
3837

3938

@@ -99,8 +98,7 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols):
9998
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
10099
)
101100
retcode, stdout, stderr = repo.run_hook(
102-
hook,
103-
tuple(filenames) if hook['pass_filenames'] else (),
101+
hook, tuple(filenames) if hook['pass_filenames'] else (),
104102
)
105103
diff_after = cmd_output(
106104
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,

pre_commit/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import absolute_import
12
from __future__ import unicode_literals
23

34
import pkg_resources

pre_commit/envcontext.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111

1212
Var = collections.namedtuple('Var', ('name', 'default'))
13-
setattr(Var.__new__, '__defaults__', ('',))
13+
Var.__new__.__defaults__ = ('',)
1414

1515

1616
def format_env(parts, env):
1717
return ''.join(
18-
env.get(part.name, part.default)
19-
if isinstance(part, Var)
20-
else part
18+
env.get(part.name, part.default) if isinstance(part, Var) else part
2119
for part in parts
2220
)
2321

pre_commit/error_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
from pre_commit import five
1212
from pre_commit import output
13-
from pre_commit.errors import FatalError
1413
from pre_commit.store import Store
1514

1615

16+
class FatalError(RuntimeError):
17+
pass
18+
19+
1720
def _to_bytes(exc):
1821
try:
1922
return bytes(exc)
@@ -46,7 +49,5 @@ def error_handler():
4649
_log_and_exit('An error has occurred', e, traceback.format_exc())
4750
except Exception as e:
4851
_log_and_exit(
49-
'An unexpected error has occurred',
50-
e,
51-
traceback.format_exc(),
52+
'An unexpected error has occurred', e, traceback.format_exc(),
5253
)

pre_commit/errors.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

pre_commit/file_lock.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import absolute_import
2+
from __future__ import unicode_literals
3+
14
import contextlib
25
import errno
36

pre_commit/five.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import absolute_import
12
from __future__ import unicode_literals
23

34
import six

0 commit comments

Comments
 (0)