mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Python 3 compatibility.
This commit is contained in:
parent
ddebb83a40
commit
bb365a6e68
10 changed files with 30 additions and 27 deletions
|
|
@ -21,7 +21,7 @@ def extend_validator_cls(validator_cls, modify):
|
|||
|
||||
|
||||
def default_values(properties, instance):
|
||||
for property, subschema in properties.iteritems():
|
||||
for property, subschema in properties.items():
|
||||
if 'default' in subschema:
|
||||
instance.setdefault(
|
||||
property, copy.deepcopy(subschema['default']),
|
||||
|
|
@ -29,7 +29,7 @@ def default_values(properties, instance):
|
|||
|
||||
|
||||
def remove_default_values(properties, instance):
|
||||
for property, subschema in properties.iteritems():
|
||||
for property, subschema in properties.items():
|
||||
if (
|
||||
'default' in subschema and
|
||||
instance.get(property) == subschema['default']
|
||||
|
|
|
|||
|
|
@ -14,12 +14,13 @@ LOG_LEVEL_COLORS = {
|
|||
|
||||
|
||||
class LoggingHandler(logging.Handler):
|
||||
def __init__(self, use_color):
|
||||
def __init__(self, use_color, print_fn=print):
|
||||
logging.Handler.__init__(self)
|
||||
self.use_color = use_color
|
||||
self.__print_fn = print_fn
|
||||
|
||||
def emit(self, record):
|
||||
print(
|
||||
self.__print_fn(
|
||||
u'{0}{1}'.format(
|
||||
color.format_color(
|
||||
'[{0}]'.format(record.levelname),
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ class PrefixedCommandRunner(object):
|
|||
'stdout': subprocess.PIPE,
|
||||
'stderr': subprocess.PIPE,
|
||||
}
|
||||
if stdin is not None:
|
||||
stdin = stdin.encode('utf-8')
|
||||
|
||||
popen_kwargs.update(kwargs)
|
||||
self._create_path_if_not_exists()
|
||||
replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir)
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class Repository(object):
|
|||
logger.info('Installing environment for {0}.'.format(self.repo_url))
|
||||
logger.info('Once installed this environment will be reused.')
|
||||
logger.info('This may take a few minutes...')
|
||||
with clean_path_on_failure(unicode(local.path(self.sha))):
|
||||
with clean_path_on_failure(str(local.path(self.sha))):
|
||||
local['git']['clone', '--no-checkout', self.repo_url, self.sha]()
|
||||
with self.in_checkout():
|
||||
local['git']['checkout', self.sha]()
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ def _run_single_hook(runner, repository, hook_id, args):
|
|||
get_filenames(hook['files'], hook['exclude']),
|
||||
)
|
||||
|
||||
output = '\n'.join([stdout, stderr]).strip()
|
||||
if retcode != repository.hooks[hook_id]['expected_return_value']:
|
||||
retcode = 1
|
||||
print_color = color.RED
|
||||
|
|
@ -57,8 +56,12 @@ def _run_single_hook(runner, repository, hook_id, args):
|
|||
|
||||
print(color.format_color(pass_fail, print_color, args.color))
|
||||
|
||||
if output and (retcode or args.verbose):
|
||||
print('\n' + output)
|
||||
if (stdout or stderr) and (retcode or args.verbose):
|
||||
print()
|
||||
for output in (stdout, stderr):
|
||||
if output.strip():
|
||||
print(output.strip())
|
||||
print()
|
||||
|
||||
return retcode
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue