mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-14 04:09:16 -06:00
Small cleanups
This commit is contained in:
@@ -10,7 +10,7 @@ from identify.identify import ALL_TAGS
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import schema
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.error_handler import FatalError
|
||||
from pre_commit.languages.all import all_languages
|
||||
|
||||
|
||||
@@ -51,8 +51,7 @@ MANIFEST_HOOK_DICT = schema.Map(
|
||||
'',
|
||||
),
|
||||
schema.Optional(
|
||||
'exclude',
|
||||
schema.check_and(schema.check_string, schema.check_regex),
|
||||
'exclude', schema.check_and(schema.check_string, schema.check_regex),
|
||||
'^$',
|
||||
),
|
||||
schema.Optional('types', schema.check_array(check_type_tag), ['file']),
|
||||
|
||||
@@ -47,7 +47,4 @@ def use_color(setting):
|
||||
if setting not in COLOR_CHOICES:
|
||||
raise InvalidColorSetting(setting)
|
||||
|
||||
return (
|
||||
setting == 'always' or
|
||||
(setting == 'auto' and sys.stdout.isatty())
|
||||
)
|
||||
return setting == 'always' or (setting == 'auto' and sys.stdout.isatty())
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ctypes import POINTER
|
||||
@@ -19,8 +20,7 @@ def bool_errcheck(result, func, args):
|
||||
|
||||
|
||||
GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(
|
||||
("GetStdHandle", windll.kernel32),
|
||||
((1, "nStdHandle"), ),
|
||||
("GetStdHandle", windll.kernel32), ((1, "nStdHandle"),),
|
||||
)
|
||||
|
||||
GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
|
||||
@@ -42,7 +42,6 @@ def enable_virtual_terminal_processing():
|
||||
|
||||
More info on the escape sequences supported:
|
||||
https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx
|
||||
|
||||
"""
|
||||
stdout = GetStdHandle(STD_OUTPUT_HANDLE)
|
||||
flags = GetConsoleMode(stdout)
|
||||
|
||||
@@ -32,8 +32,7 @@ def _get_skips(environ):
|
||||
|
||||
def _hook_msg_start(hook, verbose):
|
||||
return '{}{}'.format(
|
||||
'[{}] '.format(hook['id']) if verbose else '',
|
||||
hook['name'],
|
||||
'[{}] '.format(hook['id']) if verbose else '', hook['name'],
|
||||
)
|
||||
|
||||
|
||||
@@ -99,8 +98,7 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols):
|
||||
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
|
||||
)
|
||||
retcode, stdout, stderr = repo.run_hook(
|
||||
hook,
|
||||
tuple(filenames) if hook['pass_filenames'] else (),
|
||||
hook, tuple(filenames) if hook['pass_filenames'] else (),
|
||||
)
|
||||
diff_after = cmd_output(
|
||||
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pkg_resources
|
||||
|
||||
@@ -10,14 +10,12 @@ UNSET = collections.namedtuple('UNSET', ())()
|
||||
|
||||
|
||||
Var = collections.namedtuple('Var', ('name', 'default'))
|
||||
setattr(Var.__new__, '__defaults__', ('',))
|
||||
Var.__new__.__defaults__ = ('',)
|
||||
|
||||
|
||||
def format_env(parts, env):
|
||||
return ''.join(
|
||||
env.get(part.name, part.default)
|
||||
if isinstance(part, Var)
|
||||
else part
|
||||
env.get(part.name, part.default) if isinstance(part, Var) else part
|
||||
for part in parts
|
||||
)
|
||||
|
||||
|
||||
@@ -10,10 +10,13 @@ import six
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit import output
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.store import Store
|
||||
|
||||
|
||||
class FatalError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _to_bytes(exc):
|
||||
try:
|
||||
return bytes(exc)
|
||||
@@ -46,7 +49,5 @@ def error_handler():
|
||||
_log_and_exit('An error has occurred', e, traceback.format_exc())
|
||||
except Exception as e:
|
||||
_log_and_exit(
|
||||
'An unexpected error has occurred',
|
||||
e,
|
||||
traceback.format_exc(),
|
||||
'An unexpected error has occurred', e, traceback.format_exc(),
|
||||
)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
class FatalError(RuntimeError):
|
||||
pass
|
||||
@@ -1,3 +1,6 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
|
||||
@@ -4,7 +4,7 @@ import logging
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.error_handler import FatalError
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
|
||||
@@ -114,7 +114,6 @@ def check_for_cygwin_mismatch():
|
||||
'These can be installed through the cygwin installer.\n'
|
||||
' - python {}\n'
|
||||
' - git {}\n'.format(
|
||||
exe_type[is_cygwin_python],
|
||||
exe_type[is_cygwin_git],
|
||||
exe_type[is_cygwin_python], exe_type[is_cygwin_git],
|
||||
),
|
||||
)
|
||||
|
||||
@@ -23,12 +23,12 @@ class LoggingHandler(logging.Handler):
|
||||
|
||||
def emit(self, record):
|
||||
output.write_line(
|
||||
'{}{}'.format(
|
||||
'{} {}'.format(
|
||||
color.format_color(
|
||||
'[{}]'.format(record.levelname),
|
||||
LOG_LEVEL_COLORS[record.levelname],
|
||||
self.use_color,
|
||||
) + ' ',
|
||||
),
|
||||
record.getMessage(),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -2,12 +2,14 @@ from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import os.path
|
||||
import tarfile
|
||||
|
||||
from pre_commit import output
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import resource_filename
|
||||
from pre_commit.util import rmtree
|
||||
from pre_commit.util import tmpdir
|
||||
|
||||
@@ -27,11 +29,6 @@ REPOS = (
|
||||
)
|
||||
|
||||
|
||||
RESOURCES_DIR = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), 'resources'),
|
||||
)
|
||||
|
||||
|
||||
def make_archive(name, repo, ref, destdir):
|
||||
"""Makes an archive of a repository in the given destdir.
|
||||
|
||||
@@ -59,12 +56,15 @@ def make_archive(name, repo, ref, destdir):
|
||||
return output_path
|
||||
|
||||
|
||||
def main():
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--dest', default=resource_filename())
|
||||
args = parser.parse_args(argv)
|
||||
for archive_name, repo, ref in REPOS:
|
||||
output.write_line('Making {}.tar.gz for {}@{}'.format(
|
||||
archive_name, repo, ref,
|
||||
))
|
||||
make_archive(archive_name, repo, ref, RESOURCES_DIR)
|
||||
make_archive(archive_name, repo, ref, args.dest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -93,18 +93,16 @@ def tmpdir():
|
||||
rmtree(tempdir)
|
||||
|
||||
|
||||
def resource_filename(filename):
|
||||
def resource_filename(*segments):
|
||||
return pkg_resources.resource_filename(
|
||||
'pre_commit',
|
||||
os.path.join('resources', filename),
|
||||
'pre_commit', os.path.join('resources', *segments),
|
||||
)
|
||||
|
||||
|
||||
def make_executable(filename):
|
||||
original_mode = os.stat(filename).st_mode
|
||||
os.chmod(
|
||||
filename,
|
||||
original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH,
|
||||
filename, original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user