mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 20:40:08 -06:00
@@ -38,7 +38,7 @@ def get_validator(
|
||||
"""
|
||||
def validate(filename, load_strategy=yaml.load):
|
||||
if not os.path.exists(filename):
|
||||
raise exception_type('File {0} does not exist'.format(filename))
|
||||
raise exception_type('File {} does not exist'.format(filename))
|
||||
|
||||
file_contents = open(filename, 'r').read()
|
||||
|
||||
@@ -46,14 +46,14 @@ def get_validator(
|
||||
obj = load_strategy(file_contents)
|
||||
except Exception as e:
|
||||
raise exception_type(
|
||||
'Invalid yaml: {0}\n{1}'.format(os.path.relpath(filename), e),
|
||||
'Invalid yaml: {}\n{}'.format(os.path.relpath(filename), e),
|
||||
)
|
||||
|
||||
try:
|
||||
jsonschema.validate(obj, json_schema)
|
||||
except jsonschema.exceptions.ValidationError as e:
|
||||
raise exception_type(
|
||||
'Invalid content: {0}\n{1}'.format(
|
||||
'Invalid content: {}\n{}'.format(
|
||||
os.path.relpath(filename), e
|
||||
),
|
||||
)
|
||||
@@ -75,7 +75,7 @@ def get_run_function(filenames_help, validate_strategy, exception_cls):
|
||||
parser.add_argument(
|
||||
'-V', '--version',
|
||||
action='version',
|
||||
version='%(prog)s {0}'.format(
|
||||
version='%(prog)s {}'.format(
|
||||
pkg_resources.get_distribution('pre-commit').version
|
||||
)
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ CONFIG_JSON_SCHEMA = {
|
||||
def try_regex(repo, hook, value, field_name):
|
||||
if not is_regex_valid(value):
|
||||
raise InvalidConfigError(
|
||||
'Invalid {0} regex at {1}, {2}: {3}'.format(
|
||||
'Invalid {} regex at {}, {}: {}'.format(
|
||||
field_name, repo, hook, value,
|
||||
)
|
||||
)
|
||||
@@ -72,7 +72,7 @@ def validate_config_extra(config):
|
||||
)
|
||||
elif 'sha' not in repo:
|
||||
raise InvalidConfigError(
|
||||
'Missing "sha" field for repository {0}'.format(repo['repo'])
|
||||
'Missing "sha" field for repository {}'.format(repo['repo'])
|
||||
)
|
||||
for hook in repo['hooks']:
|
||||
try_regex(repo, hook['id'], hook.get('files', ''), 'files')
|
||||
|
||||
@@ -55,7 +55,7 @@ MANIFEST_JSON_SCHEMA = {
|
||||
def validate_languages(hook_config):
|
||||
if hook_config['language'] not in all_languages:
|
||||
raise InvalidManifestError(
|
||||
'Expected language {0} for {1} to be one of {2!r}'.format(
|
||||
'Expected language {} for {} to be one of {!r}'.format(
|
||||
hook_config['id'],
|
||||
hook_config['language'],
|
||||
all_languages,
|
||||
@@ -66,14 +66,14 @@ def validate_languages(hook_config):
|
||||
def validate_files(hook_config):
|
||||
if not is_regex_valid(hook_config['files']):
|
||||
raise InvalidManifestError(
|
||||
'Invalid files regex at {0}: {1}'.format(
|
||||
'Invalid files regex at {}: {}'.format(
|
||||
hook_config['id'], hook_config['files'],
|
||||
)
|
||||
)
|
||||
|
||||
if not is_regex_valid(hook_config.get('exclude', '')):
|
||||
raise InvalidManifestError(
|
||||
'Invalid exclude regex at {0}: {1}'.format(
|
||||
'Invalid exclude regex at {}: {}'.format(
|
||||
hook_config['id'], hook_config['exclude'],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ def format_color(text, color, use_color_setting):
|
||||
if not use_color_setting:
|
||||
return text
|
||||
else:
|
||||
return u'{0}{1}{2}'.format(color, text, NORMAL)
|
||||
return '{}{}{}'.format(color, text, NORMAL)
|
||||
|
||||
|
||||
COLOR_CHOICES = ('auto', 'always', 'never')
|
||||
|
||||
@@ -61,7 +61,7 @@ def _update_repository(repo_config, runner):
|
||||
if hooks_missing:
|
||||
raise RepositoryCannotBeUpdatedError(
|
||||
'Cannot update because the tip of master is missing these hooks:\n'
|
||||
'{0}'.format(', '.join(sorted(hooks_missing)))
|
||||
'{}'.format(', '.join(sorted(hooks_missing)))
|
||||
)
|
||||
|
||||
return new_config
|
||||
@@ -86,7 +86,7 @@ def autoupdate(runner):
|
||||
if is_local_hooks(repo_config):
|
||||
output_configs.append(repo_config)
|
||||
continue
|
||||
sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
|
||||
sys.stdout.write('Updating {}...'.format(repo_config['repo']))
|
||||
sys.stdout.flush()
|
||||
try:
|
||||
new_repo_config = _update_repository(repo_config, runner)
|
||||
@@ -99,7 +99,7 @@ def autoupdate(runner):
|
||||
if new_repo_config['sha'] != repo_config['sha']:
|
||||
changed = True
|
||||
print(
|
||||
'updating {0} -> {1}.'.format(
|
||||
'updating {} -> {}.'.format(
|
||||
repo_config['sha'], new_repo_config['sha'],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -9,5 +9,5 @@ from pre_commit.util import rmtree
|
||||
def clean(runner):
|
||||
if os.path.exists(runner.store.directory):
|
||||
rmtree(runner.store.directory)
|
||||
print('Cleaned {0}.'.format(runner.store.directory))
|
||||
print('Cleaned {}.'.format(runner.store.directory))
|
||||
return 0
|
||||
|
||||
@@ -62,7 +62,7 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
|
||||
os.remove(legacy_path)
|
||||
elif os.path.exists(legacy_path):
|
||||
print(
|
||||
'Running in migration mode with existing hooks at {0}\n'
|
||||
'Running in migration mode with existing hooks at {}\n'
|
||||
'Use -f to use only pre-commit.'.format(
|
||||
legacy_path,
|
||||
)
|
||||
@@ -83,7 +83,7 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
|
||||
pre_commit_file_obj.write(contents)
|
||||
make_executable(hook_path)
|
||||
|
||||
print('pre-commit installed at {0}'.format(hook_path))
|
||||
print('pre-commit installed at {}'.format(hook_path))
|
||||
|
||||
# If they requested we install all of the hooks, do so.
|
||||
if hooks:
|
||||
@@ -110,10 +110,10 @@ def uninstall(runner, hook_type='pre-commit'):
|
||||
return 0
|
||||
|
||||
os.remove(hook_path)
|
||||
print('{0} uninstalled'.format(hook_type))
|
||||
print('{} uninstalled'.format(hook_type))
|
||||
|
||||
if os.path.exists(legacy_path):
|
||||
os.rename(legacy_path, hook_path)
|
||||
print('Restored previous hooks to {0}'.format(hook_path))
|
||||
print('Restored previous hooks to {}'.format(hook_path))
|
||||
|
||||
return 0
|
||||
|
||||
@@ -24,8 +24,8 @@ def _get_skips(environ):
|
||||
|
||||
|
||||
def _hook_msg_start(hook, verbose):
|
||||
return '{0}{1}'.format(
|
||||
'[{0}] '.format(hook['id']) if verbose else '',
|
||||
return '{}{}'.format(
|
||||
'[{}] '.format(hook['id']) if verbose else '',
|
||||
hook['name'],
|
||||
)
|
||||
|
||||
@@ -51,7 +51,7 @@ def _print_user_skipped(hook, write, args):
|
||||
|
||||
def get_changed_files(new, old):
|
||||
return cmd_output(
|
||||
'git', 'diff', '--name-only', '{0}...{1}'.format(old, new),
|
||||
'git', 'diff', '--name-only', '{}...{}'.format(old, new),
|
||||
)[1].splitlines()
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ def _run_single_hook(hook, repo, args, write, skips=frozenset()):
|
||||
write(color.format_color(pass_fail, print_color, args.color) + '\n')
|
||||
|
||||
if (stdout or stderr or file_modifications) and (retcode or args.verbose):
|
||||
write('hookid: {0}\n'.format(hook['id']))
|
||||
write('hookid: {}\n'.format(hook['id']))
|
||||
write('\n')
|
||||
|
||||
# Print a message if failing due to file modifications
|
||||
@@ -200,7 +200,7 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
||||
if hook['id'] == args.hook
|
||||
]
|
||||
if not repo_hooks:
|
||||
write('No hook with id `{0}`\n'.format(args.hook))
|
||||
write('No hook with id `{}`\n'.format(args.hook))
|
||||
return 1
|
||||
|
||||
# Filter hooks for stages
|
||||
|
||||
@@ -11,4 +11,4 @@ def environment_dir(ENVIRONMENT_DIR, language_version):
|
||||
if ENVIRONMENT_DIR is None:
|
||||
return None
|
||||
else:
|
||||
return '{0}-{1}'.format(ENVIRONMENT_DIR, language_version)
|
||||
return '{}-{}'.format(ENVIRONMENT_DIR, language_version)
|
||||
|
||||
@@ -47,7 +47,7 @@ def install_environment(
|
||||
with clean_path_on_failure(env_dir):
|
||||
cmd = [
|
||||
sys.executable, '-m', 'nodeenv', '--prebuilt',
|
||||
'{{prefix}}{0}'.format(directory),
|
||||
'{{prefix}}{}'.format(directory),
|
||||
]
|
||||
|
||||
if version != 'default':
|
||||
|
||||
@@ -49,7 +49,7 @@ def norm_version(version):
|
||||
# If it is in the form pythonx.x search in the default
|
||||
# place on windows
|
||||
if version.startswith('python'):
|
||||
return r'C:\{0}\python.exe'.format(version.replace('.', ''))
|
||||
return r'C:\{}\python.exe'.format(version.replace('.', ''))
|
||||
|
||||
# Otherwise assume it is a path
|
||||
return os.path.expanduser(version)
|
||||
@@ -67,7 +67,7 @@ def install_environment(
|
||||
with clean_path_on_failure(repo_cmd_runner.path(directory)):
|
||||
venv_cmd = [
|
||||
sys.executable, '-m', 'virtualenv',
|
||||
'{{prefix}}{0}'.format(directory)
|
||||
'{{prefix}}{}'.format(directory)
|
||||
]
|
||||
if version != 'default':
|
||||
venv_cmd.extend(['-p', norm_version(version)])
|
||||
|
||||
@@ -70,20 +70,20 @@ def _install_rbenv(repo_cmd_runner, version='default'):
|
||||
# We also modify the PS1 variable for manual debugging sake.
|
||||
activate_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
"export RBENV_ROOT='{0}'\n"
|
||||
"export RBENV_ROOT='{directory}'\n"
|
||||
'export PATH="$RBENV_ROOT/bin:$PATH"\n'
|
||||
'eval "$(rbenv init -)"\n'
|
||||
'export PS1="(rbenv)$PS1"\n'
|
||||
# This lets us install gems in an isolated and repeatable
|
||||
# directory
|
||||
"export GEM_HOME='{0}/gems'\n"
|
||||
"export GEM_HOME='{directory}/gems'\n"
|
||||
'export PATH="$GEM_HOME/bin:$PATH"\n'
|
||||
'\n'.format(repo_cmd_runner.path(directory))
|
||||
'\n'.format(directory=repo_cmd_runner.path(directory))
|
||||
)
|
||||
|
||||
# If we aren't using the system ruby, add a version here
|
||||
if version != 'default':
|
||||
activate_file.write('export RBENV_VERSION="{0}"\n'.format(version))
|
||||
activate_file.write('export RBENV_VERSION="{}"\n'.format(version))
|
||||
|
||||
|
||||
def _install_ruby(runner, version):
|
||||
|
||||
@@ -22,9 +22,9 @@ class LoggingHandler(logging.Handler):
|
||||
|
||||
def emit(self, record):
|
||||
self.__write(
|
||||
u'{0}{1}\n'.format(
|
||||
'{}{}\n'.format(
|
||||
color.format_color(
|
||||
'[{0}]'.format(record.levelname),
|
||||
'[{}]'.format(record.levelname),
|
||||
LOG_LEVEL_COLORS[record.levelname],
|
||||
self.use_color,
|
||||
) + ' ',
|
||||
|
||||
@@ -34,7 +34,7 @@ def main(argv=None):
|
||||
parser.add_argument(
|
||||
'-V', '--version',
|
||||
action='version',
|
||||
version='%(prog)s {0}'.format(
|
||||
version='%(prog)s {}'.format(
|
||||
pkg_resources.get_distribution('pre-commit').version
|
||||
)
|
||||
)
|
||||
@@ -157,11 +157,11 @@ def main(argv=None):
|
||||
return run(runner, args)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
'Command {0} not implemented.'.format(args.command)
|
||||
'Command {} not implemented.'.format(args.command)
|
||||
)
|
||||
|
||||
raise AssertionError(
|
||||
'Command {0} failed to exit with a returncode'.format(args.command)
|
||||
'Command {} failed to exit with a returncode'.format(args.command)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ def make_archive(name, repo, ref, destdir):
|
||||
|
||||
def main():
|
||||
for archive_name, repo, ref in REPOS:
|
||||
print('Making {0}.tar.gz for {1}@{2}'.format(archive_name, repo, ref))
|
||||
print('Making {}.tar.gz for {}@{}'.format(archive_name, repo, ref))
|
||||
make_archive(archive_name, repo, ref, RESOURCES_DIR)
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ def get_hook_message(
|
||||
if end_len:
|
||||
return start + '.' * (cols - len(start) - end_len - 1)
|
||||
else:
|
||||
return '{0}{1}{2}{3}\n'.format(
|
||||
return '{}{}{}{}\n'.format(
|
||||
start,
|
||||
'.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),
|
||||
postfix,
|
||||
|
||||
@@ -75,7 +75,7 @@ def normexe(orig_exe):
|
||||
exe = find_executable(orig_exe)
|
||||
if exe is None:
|
||||
raise ExecutableNotFoundError(
|
||||
'Executable `{0}` not found'.format(orig_exe),
|
||||
'Executable `{}` not found'.format(orig_exe),
|
||||
)
|
||||
return exe
|
||||
else:
|
||||
|
||||
@@ -76,7 +76,7 @@ class Repository(object):
|
||||
for hook in self.repo_config['hooks']:
|
||||
if hook['id'] not in self.manifest.hooks:
|
||||
logger.error(
|
||||
'`{0}` is not present in repository {1}. '
|
||||
'`{}` is not present in repository {}. '
|
||||
'Typo? Perhaps it is introduced in a newer version? '
|
||||
'Often you can fix this by removing the hook, running '
|
||||
'`pre-commit autoupdate`, '
|
||||
@@ -90,8 +90,8 @@ class Repository(object):
|
||||
)
|
||||
if hook_version > _pre_commit_version:
|
||||
logger.error(
|
||||
'The hook `{0}` requires pre-commit version {1} but '
|
||||
'version {2} is installed. '
|
||||
'The hook `{}` requires pre-commit version {} but '
|
||||
'version {} is installed. '
|
||||
'Perhaps run `pip install --upgrade pre-commit`.'.format(
|
||||
hook['id'], hook_version, _pre_commit_version,
|
||||
)
|
||||
@@ -165,7 +165,7 @@ class Repository(object):
|
||||
for language_name, language_version in self.languages
|
||||
):
|
||||
logger.info(
|
||||
'Installing environment for {0}.'.format(self.repo_url)
|
||||
'Installing environment for {}.'.format(self.repo_url)
|
||||
)
|
||||
logger.info('Once installed this environment will be reused.')
|
||||
logger.info('This may take a few minutes...')
|
||||
|
||||
@@ -29,10 +29,10 @@ def staged_files_only(cmd_runner):
|
||||
encoding=None,
|
||||
)
|
||||
if retcode and diff_stdout_binary.strip():
|
||||
patch_filename = cmd_runner.path('patch{0}'.format(int(time.time())))
|
||||
patch_filename = cmd_runner.path('patch{}'.format(int(time.time())))
|
||||
logger.warning('Unstaged files detected.')
|
||||
logger.info(
|
||||
'Stashing unstaged files to {0}.'.format(patch_filename),
|
||||
'Stashing unstaged files to {}.'.format(patch_filename),
|
||||
)
|
||||
# Save the current unstaged changes as a patch
|
||||
with io.open(patch_filename, 'wb') as patch_file:
|
||||
@@ -56,7 +56,7 @@ def staged_files_only(cmd_runner):
|
||||
# Roll back the changes made by hooks.
|
||||
cmd_runner.run(['git', 'checkout', '--', '.'])
|
||||
cmd_runner.run(('git', 'apply', patch_filename), encoding=None)
|
||||
logger.info('Restored changes from {0}.'.format(patch_filename))
|
||||
logger.info('Restored changes from {}.'.format(patch_filename))
|
||||
else:
|
||||
# There weren't any staged files so we don't need to do anything
|
||||
# special
|
||||
|
||||
@@ -111,7 +111,7 @@ class Store(object):
|
||||
if result:
|
||||
return result[0]
|
||||
|
||||
logger.info('Initializing environment for {0}.'.format(url))
|
||||
logger.info('Initializing environment for {}.'.format(url))
|
||||
|
||||
dir = tempfile.mkdtemp(prefix='repo', dir=self.directory)
|
||||
with clean_path_on_failure(dir):
|
||||
|
||||
@@ -131,9 +131,9 @@ class CalledProcessError(RuntimeError):
|
||||
|
||||
return b''.join((
|
||||
five.to_bytes(
|
||||
'Command: {0!r}\n'
|
||||
'Return code: {1}\n'
|
||||
'Expected return code: {2}\n'.format(
|
||||
'Command: {!r}\n'
|
||||
'Return code: {}\n'
|
||||
'Expected return code: {}\n'.format(
|
||||
self.cmd, self.returncode, self.expected_returncode
|
||||
)
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@ import sys
|
||||
|
||||
|
||||
def func():
|
||||
print('{0}.{1}'.format(*sys.version_info[:2]))
|
||||
print('{}.{}'.format(*sys.version_info[:2]))
|
||||
print(repr(sys.argv[1:]))
|
||||
print('Hello World')
|
||||
return 0
|
||||
|
||||
@@ -186,7 +186,7 @@ def test_does_not_contain_defaults():
|
||||
if isinstance(schema, dict):
|
||||
if 'default' in schema:
|
||||
raise AssertionError(
|
||||
'Unexpected default in schema at {0}'.format(
|
||||
'Unexpected default in schema at {}'.format(
|
||||
' => '.join(route),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ from pre_commit.color import use_color
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('in_text', 'in_color', 'in_use_color', 'expected'), (
|
||||
('foo', GREEN, True, '{0}foo\033[0m'.format(GREEN)),
|
||||
('foo', GREEN, True, '{}foo\033[0m'.format(GREEN)),
|
||||
('foo', GREEN, False, 'foo'),
|
||||
))
|
||||
def test_format_color(in_text, in_color, in_use_color, expected):
|
||||
|
||||
@@ -417,7 +417,7 @@ def test_lots_of_files(mock_out_store_directory, tempdir_factory):
|
||||
|
||||
# Write a crap ton of files
|
||||
for i in range(400):
|
||||
filename = '{0}{1}'.format('a' * 100, i)
|
||||
filename = '{}{}'.format('a' * 100, i)
|
||||
open(filename, 'w').close()
|
||||
|
||||
cmd_output('bash', '-c', 'git add .')
|
||||
|
||||
@@ -10,7 +10,7 @@ def test_norm_version_expanduser():
|
||||
home = os.path.expanduser('~')
|
||||
if os.name == 'nt': # pragma: no cover (nt)
|
||||
path = r'~\python343'
|
||||
expected_path = r'{0}\python343'.format(home)
|
||||
expected_path = r'{}\python343'.format(home)
|
||||
else: # pragma: no cover (non-nt)
|
||||
path = '~/.pyenv/versions/3.4.3/bin/python'
|
||||
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
|
||||
|
||||
@@ -69,7 +69,7 @@ def write_executable(shebang, filename='run'):
|
||||
os.mkdir('bin')
|
||||
path = os.path.join('bin', filename)
|
||||
with io.open(path, 'w') as f:
|
||||
f.write('#!{0}'.format(shebang))
|
||||
f.write('#!{}'.format(shebang))
|
||||
make_executable(path)
|
||||
return path
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ def _norm_pwd(path):
|
||||
# Under windows bash's temp and windows temp is different.
|
||||
# This normalizes to the bash /tmp
|
||||
return cmd_output(
|
||||
'bash', '-c', "cd '{0}' && pwd".format(path),
|
||||
'bash', '-c', "cd '{}' && pwd".format(path),
|
||||
encoding=None,
|
||||
)[1].strip()
|
||||
|
||||
@@ -554,7 +554,7 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
||||
with pytest.raises(SystemExit):
|
||||
repo.install()
|
||||
assert fake_log_handler.handle.call_args[0][0].msg == (
|
||||
'`i-dont-exist` is not present in repository {0}. '
|
||||
'`i-dont-exist` is not present in repository {}. '
|
||||
'Typo? Perhaps it is introduced in a newer version? '
|
||||
'Often you can fix this by removing the hook, '
|
||||
'running `pre-commit autoupdate`, '
|
||||
|
||||
Reference in New Issue
Block a user