mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
upgrade hooks, pyupgrade pre-commit
This commit is contained in:
parent
764c765d29
commit
30c1e8289f
91 changed files with 176 additions and 437 deletions
|
|
@ -1,6 +1,6 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.1.0
|
||||
rev: v2.4.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
|
|
@ -12,30 +12,36 @@ repos:
|
|||
- id: requirements-txt-fixer
|
||||
- id: double-quote-string-fixer
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.7.7
|
||||
rev: 3.7.9
|
||||
hooks:
|
||||
- id: flake8
|
||||
- repo: https://github.com/pre-commit/mirrors-autopep8
|
||||
rev: v1.4.3
|
||||
rev: v1.4.4
|
||||
hooks:
|
||||
- id: autopep8
|
||||
- repo: https://github.com/pre-commit/pre-commit
|
||||
rev: v1.14.4
|
||||
rev: v1.21.0
|
||||
hooks:
|
||||
- id: validate_manifest
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v1.12.0
|
||||
rev: v1.25.3
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py36-plus]
|
||||
- repo: https://github.com/asottile/reorder_python_imports
|
||||
rev: v1.4.0
|
||||
rev: v1.9.0
|
||||
hooks:
|
||||
- id: reorder-python-imports
|
||||
language_version: python3
|
||||
args: [--py3-plus]
|
||||
- repo: https://github.com/asottile/add-trailing-comma
|
||||
rev: v1.0.0
|
||||
rev: v1.5.0
|
||||
hooks:
|
||||
- id: add-trailing-comma
|
||||
args: [--py36-plus]
|
||||
- repo: https://github.com/asottile/setup-cfg-fmt
|
||||
rev: v1.6.0
|
||||
hooks:
|
||||
- id: setup-cfg-fmt
|
||||
- repo: meta
|
||||
hooks:
|
||||
- id: check-hooks-apply
|
||||
|
|
|
|||
|
|
@ -10,18 +10,17 @@ resources:
|
|||
type: github
|
||||
endpoint: github
|
||||
name: asottile/azure-pipeline-templates
|
||||
ref: refs/tags/v0.0.15
|
||||
ref: refs/tags/v1.0.0
|
||||
|
||||
jobs:
|
||||
- template: job--pre-commit.yml@asottile
|
||||
- template: job--python-tox.yml@asottile
|
||||
parameters:
|
||||
toxenvs: [py27, py37]
|
||||
toxenvs: [py37]
|
||||
os: windows
|
||||
additional_variables:
|
||||
COVERAGE_IGNORE_WINDOWS: '# pragma: windows no cover'
|
||||
TOX_TESTENV_PASSENV: COVERAGE_IGNORE_WINDOWS
|
||||
TEMP: C:\Temp # remove when dropping python2
|
||||
pre_test:
|
||||
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
|
||||
displayName: Add conda to PATH
|
||||
|
|
@ -39,7 +38,7 @@ jobs:
|
|||
displayName: install swift
|
||||
- template: job--python-tox.yml@asottile
|
||||
parameters:
|
||||
toxenvs: [pypy, pypy3, py27, py36, py37, py38]
|
||||
toxenvs: [pypy3, py36, py37, py38]
|
||||
os: linux
|
||||
pre_test:
|
||||
- task: UseRubyVersion@0
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from pre_commit.main import main
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import functools
|
||||
import logging
|
||||
|
|
@ -106,7 +103,7 @@ LOCAL = 'local'
|
|||
META = 'meta'
|
||||
|
||||
|
||||
class MigrateShaToRev(object):
|
||||
class MigrateShaToRev:
|
||||
key = 'rev'
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -202,7 +199,7 @@ META_HOOK_DICT = cfgv.Map(
|
|||
if item.key in {'name', 'language', 'entry'} else
|
||||
item
|
||||
for item in MANIFEST_HOOK_DICT.items
|
||||
])
|
||||
]),
|
||||
)
|
||||
CONFIG_HOOK_DICT = cfgv.Map(
|
||||
'Hook', 'id',
|
||||
|
|
@ -217,7 +214,7 @@ CONFIG_HOOK_DICT = cfgv.Map(
|
|||
cfgv.OptionalNoDefault(item.key, item.check_fn)
|
||||
for item in MANIFEST_HOOK_DICT.items
|
||||
if item.key != 'id'
|
||||
]
|
||||
],
|
||||
)
|
||||
CONFIG_REPO_DICT = cfgv.Map(
|
||||
'Repository', 'repo',
|
||||
|
|
@ -243,7 +240,7 @@ CONFIG_REPO_DICT = cfgv.Map(
|
|||
DEFAULT_LANGUAGE_VERSION = cfgv.Map(
|
||||
'DefaultLanguageVersion', None,
|
||||
cfgv.NoAdditionalKeys(all_languages),
|
||||
*[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages]
|
||||
*[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages],
|
||||
)
|
||||
CONFIG_SCHEMA = cfgv.Map(
|
||||
'Config', None,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
|
@ -8,7 +6,7 @@ if os.name == 'nt': # pragma: no cover (windows)
|
|||
from pre_commit.color_windows import enable_virtual_terminal_processing
|
||||
try:
|
||||
enable_virtual_terminal_processing()
|
||||
except WindowsError:
|
||||
except OSError:
|
||||
terminal_supports_color = False
|
||||
|
||||
RED = '\033[41m'
|
||||
|
|
@ -34,7 +32,7 @@ def format_color(text, color, use_color_setting):
|
|||
if not use_color_setting:
|
||||
return text
|
||||
else:
|
||||
return '{}{}{}'.format(color, text, NORMAL)
|
||||
return f'{color}{text}{NORMAL}'
|
||||
|
||||
|
||||
COLOR_CHOICES = ('auto', 'always', 'never')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ctypes import POINTER
|
||||
from ctypes import windll
|
||||
from ctypes import WinError
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import os.path
|
||||
import re
|
||||
|
||||
import six
|
||||
from aspy.yaml import ordered_dump
|
||||
from aspy.yaml import ordered_load
|
||||
|
||||
|
|
@ -64,7 +60,7 @@ def _check_hooks_still_exist_at_rev(repo_config, info, store):
|
|||
path = store.clone(repo_config['repo'], info.rev)
|
||||
manifest = load_manifest(os.path.join(path, C.MANIFEST_FILE))
|
||||
except InvalidManifestError as e:
|
||||
raise RepositoryCannotBeUpdatedError(six.text_type(e))
|
||||
raise RepositoryCannotBeUpdatedError(str(e))
|
||||
|
||||
# See if any of our hooks were deleted with the new commits
|
||||
hooks = {hook['id'] for hook in repo_config['hooks']}
|
||||
|
|
@ -108,7 +104,7 @@ def _write_new_config(path, rev_infos):
|
|||
new_rev_s = ordered_dump({'rev': rev_info.rev}, **C.YAML_DUMP_KWARGS)
|
||||
new_rev = new_rev_s.split(':', 1)[1].strip()
|
||||
if rev_info.frozen is not None:
|
||||
comment = ' # frozen: {}'.format(rev_info.frozen)
|
||||
comment = f' # frozen: {rev_info.frozen}'
|
||||
elif match.group(4).strip().startswith('# frozen:'):
|
||||
comment = ''
|
||||
else:
|
||||
|
|
@ -138,7 +134,7 @@ def autoupdate(config_file, store, tags_only, freeze, repos=()):
|
|||
rev_infos.append(None)
|
||||
continue
|
||||
|
||||
output.write('Updating {} ... '.format(info.repo))
|
||||
output.write(f'Updating {info.repo} ... ')
|
||||
new_info = info.update(tags_only=tags_only, freeze=freeze)
|
||||
try:
|
||||
_check_hooks_still_exist_at_rev(repo_config, new_info, store)
|
||||
|
|
@ -151,10 +147,10 @@ def autoupdate(config_file, store, tags_only, freeze, repos=()):
|
|||
if new_info.rev != info.rev:
|
||||
changed = True
|
||||
if new_info.frozen:
|
||||
updated_to = '{} (frozen)'.format(new_info.frozen)
|
||||
updated_to = f'{new_info.frozen} (frozen)'
|
||||
else:
|
||||
updated_to = new_info.rev
|
||||
msg = 'updating {} -> {}.'.format(info.rev, updated_to)
|
||||
msg = f'updating {info.rev} -> {updated_to}.'
|
||||
output.write_line(msg)
|
||||
rev_infos.append(new_info)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
from pre_commit import output
|
||||
|
|
@ -12,5 +9,5 @@ def clean(store):
|
|||
for directory in (store.directory, legacy_path):
|
||||
if os.path.exists(directory):
|
||||
rmtree(directory)
|
||||
output.write_line('Cleaned {}.'.format(directory))
|
||||
output.write_line(f'Cleaned {directory}.')
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import pre_commit.constants as C
|
||||
|
|
@ -79,5 +76,5 @@ def _gc_repos(store):
|
|||
def gc(store):
|
||||
with store.exclusive_lock():
|
||||
repos_removed = _gc_repos(store)
|
||||
output.write_line('{} repo(s) removed.'.format(repos_removed))
|
||||
output.write_line(f'{repos_removed} repo(s) removed.')
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ def init_templatedir(config_file, store, directory, hook_types):
|
|||
if configured_path != dest:
|
||||
logger.warning('`init.templateDir` not set to the target directory')
|
||||
logger.warning(
|
||||
'maybe `git config --global init.templateDir {}`?'.format(dest),
|
||||
f'maybe `git config --global init.templateDir {dest}`?',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import itertools
|
||||
import logging
|
||||
import os.path
|
||||
|
|
@ -36,13 +32,13 @@ TEMPLATE_END = '# end templated\n'
|
|||
def _hook_paths(hook_type, git_dir=None):
|
||||
git_dir = git_dir if git_dir is not None else git.get_git_dir()
|
||||
pth = os.path.join(git_dir, 'hooks', hook_type)
|
||||
return pth, '{}.legacy'.format(pth)
|
||||
return pth, f'{pth}.legacy'
|
||||
|
||||
|
||||
def is_our_script(filename):
|
||||
if not os.path.exists(filename): # pragma: windows no cover (symlink)
|
||||
return False
|
||||
with io.open(filename) as f:
|
||||
with open(filename) as f:
|
||||
contents = f.read()
|
||||
return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
|
||||
|
||||
|
|
@ -63,7 +59,7 @@ def shebang():
|
|||
break
|
||||
else:
|
||||
py = 'python'
|
||||
return '#!/usr/bin/env {}'.format(py)
|
||||
return f'#!/usr/bin/env {py}'
|
||||
|
||||
|
||||
def _install_hook_script(
|
||||
|
|
@ -94,7 +90,7 @@ def _install_hook_script(
|
|||
'SKIP_ON_MISSING_CONFIG': skip_on_missing_config,
|
||||
}
|
||||
|
||||
with io.open(hook_path, 'w') as hook_file:
|
||||
with open(hook_path, 'w') as hook_file:
|
||||
contents = resource_text('hook-tmpl')
|
||||
before, rest = contents.split(TEMPLATE_START)
|
||||
to_template, after = rest.split(TEMPLATE_END)
|
||||
|
|
@ -108,7 +104,7 @@ def _install_hook_script(
|
|||
hook_file.write(TEMPLATE_END + after)
|
||||
make_executable(hook_path)
|
||||
|
||||
output.write_line('pre-commit installed at {}'.format(hook_path))
|
||||
output.write_line(f'pre-commit installed at {hook_path}')
|
||||
|
||||
|
||||
def install(
|
||||
|
|
@ -149,11 +145,11 @@ def _uninstall_hook_script(hook_type): # type: (str) -> None
|
|||
return
|
||||
|
||||
os.remove(hook_path)
|
||||
output.write_line('{} uninstalled'.format(hook_type))
|
||||
output.write_line(f'{hook_type} uninstalled')
|
||||
|
||||
if os.path.exists(legacy_path):
|
||||
os.rename(legacy_path, hook_path)
|
||||
output.write_line('Restored previous hooks to {}'.format(hook_path))
|
||||
output.write_line(f'Restored previous hooks to {hook_path}')
|
||||
|
||||
|
||||
def uninstall(hook_types):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import re
|
||||
|
||||
import yaml
|
||||
|
|
@ -47,14 +43,14 @@ def _migrate_sha_to_rev(contents):
|
|||
|
||||
|
||||
def migrate_config(config_file, quiet=False):
|
||||
with io.open(config_file) as f:
|
||||
with open(config_file) as f:
|
||||
orig_contents = contents = f.read()
|
||||
|
||||
contents = _migrate_map(contents)
|
||||
contents = _migrate_sha_to_rev(contents)
|
||||
|
||||
if contents != orig_contents:
|
||||
with io.open(config_file, 'w') as f:
|
||||
with open(config_file, 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
print('Configuration has been migrated.')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
|
@ -32,7 +30,7 @@ def filter_by_include_exclude(names, include, exclude):
|
|||
]
|
||||
|
||||
|
||||
class Classifier(object):
|
||||
class Classifier:
|
||||
def __init__(self, filenames):
|
||||
# on windows we normalize all filenames to use forward slashes
|
||||
# this makes it easier to filter using the `files:` regex
|
||||
|
|
@ -136,13 +134,13 @@ def _run_single_hook(classifier, hook, skips, cols, verbose, use_color):
|
|||
output.write_line(color.format_color(status, print_color, use_color))
|
||||
|
||||
if verbose or hook.verbose or retcode or files_modified:
|
||||
_subtle_line('- hook id: {}'.format(hook.id), use_color)
|
||||
_subtle_line(f'- hook id: {hook.id}', use_color)
|
||||
|
||||
if (verbose or hook.verbose) and duration is not None:
|
||||
_subtle_line('- duration: {}s'.format(duration), use_color)
|
||||
_subtle_line(f'- duration: {duration}s', use_color)
|
||||
|
||||
if retcode:
|
||||
_subtle_line('- exit code: {}'.format(retcode), use_color)
|
||||
_subtle_line(f'- exit code: {retcode}', use_color)
|
||||
|
||||
# Print a message if failing due to file modifications
|
||||
if files_modified:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
# TODO: maybe `git ls-remote git://github.com/pre-commit/pre-commit-hooks` to
|
||||
# determine the latest revision? This adds ~200ms from my tests (and is
|
||||
# significantly faster than https:// or http://). For now, periodically
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import logging
|
||||
import os.path
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 8): # pragma: no cover (<PY38)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import contextlib
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,14 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os.path
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import six
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import five
|
||||
from pre_commit import output
|
||||
|
|
@ -23,7 +17,7 @@ def _to_bytes(exc):
|
|||
try:
|
||||
return bytes(exc)
|
||||
except Exception:
|
||||
return six.text_type(exc).encode('UTF-8')
|
||||
return str(exc).encode('UTF-8')
|
||||
|
||||
|
||||
def _log_and_exit(msg, exc, formatted):
|
||||
|
|
@ -35,7 +29,7 @@ def _log_and_exit(msg, exc, formatted):
|
|||
output.write_line(error_msg)
|
||||
store = Store()
|
||||
log_path = os.path.join(store.directory, 'pre-commit.log')
|
||||
output.write_line('Check the log at {}'.format(log_path))
|
||||
output.write_line(f'Check the log at {log_path}')
|
||||
|
||||
with open(log_path, 'wb') as log:
|
||||
def _log_line(*s): # type: (*str) -> None
|
||||
|
|
@ -44,13 +38,13 @@ def _log_and_exit(msg, exc, formatted):
|
|||
_log_line('### version information')
|
||||
_log_line()
|
||||
_log_line('```')
|
||||
_log_line('pre-commit version: {}'.format(C.VERSION))
|
||||
_log_line(f'pre-commit version: {C.VERSION}')
|
||||
_log_line('sys.version:')
|
||||
for line in sys.version.splitlines():
|
||||
_log_line(' {}'.format(line))
|
||||
_log_line('sys.executable: {}'.format(sys.executable))
|
||||
_log_line('os.name: {}'.format(os.name))
|
||||
_log_line('sys.platform: {}'.format(sys.platform))
|
||||
_log_line(f' {line}')
|
||||
_log_line(f'sys.executable: {sys.executable}')
|
||||
_log_line(f'os.name: {os.name}')
|
||||
_log_line(f'sys.platform: {sys.platform}')
|
||||
_log_line('```')
|
||||
_log_line()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
|
||||
|
|
@ -18,12 +15,12 @@ try: # pragma: no cover (windows)
|
|||
def _locked(fileno, blocked_cb):
|
||||
try:
|
||||
msvcrt.locking(fileno, msvcrt.LK_NBLCK, _region)
|
||||
except IOError:
|
||||
except OSError:
|
||||
blocked_cb()
|
||||
while True:
|
||||
try:
|
||||
msvcrt.locking(fileno, msvcrt.LK_LOCK, _region)
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
# Locking violation. Returned when the _LK_LOCK or _LK_RLCK
|
||||
# flag is specified and the file cannot be locked after 10
|
||||
# attempts.
|
||||
|
|
@ -48,7 +45,7 @@ except ImportError: # pragma: windows no cover
|
|||
def _locked(fileno, blocked_cb):
|
||||
try:
|
||||
fcntl.flock(fileno, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except IOError: # pragma: no cover (tests are single-threaded)
|
||||
except OSError: # pragma: no cover (tests are single-threaded)
|
||||
blocked_cb()
|
||||
fcntl.flock(fileno, fcntl.LOCK_EX)
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
|
||||
|
||||
def to_text(s):
|
||||
return s if isinstance(s, six.text_type) else s.decode('UTF-8')
|
||||
return s if isinstance(s, str) else s.decode('UTF-8')
|
||||
|
||||
|
||||
def to_bytes(s):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
import sys
|
||||
|
|
@ -127,7 +125,7 @@ def get_changed_files(new, old):
|
|||
return zsplit(
|
||||
cmd_output(
|
||||
'git', 'diff', '--name-only', '--no-ext-diff', '-z',
|
||||
'{}...{}'.format(old, new),
|
||||
f'{old}...{new}',
|
||||
)[1],
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import conda
|
||||
from pre_commit.languages import docker
|
||||
from pre_commit.languages import docker_image
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def install_environment(prefix, version, additional_dependencies):
|
|||
if additional_dependencies:
|
||||
cmd_output_b(
|
||||
'conda', 'install', '-p', env_dir, *additional_dependencies,
|
||||
cwd=prefix.prefix_dir
|
||||
cwd=prefix.prefix_dir,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
|
|
@ -24,7 +21,7 @@ def md5(s): # pragma: windows no cover
|
|||
|
||||
def docker_tag(prefix): # pragma: windows no cover
|
||||
md5sum = md5(os.path.basename(prefix.prefix_dir)).lower()
|
||||
return 'pre-commit-{}'.format(md5sum)
|
||||
return f'pre-commit-{md5sum}'
|
||||
|
||||
|
||||
def docker_is_running(): # pragma: windows no cover
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages.docker import assert_docker_available
|
||||
from pre_commit.languages.docker import docker_cmd
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os.path
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
|
||||
import six
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.xargs import xargs
|
||||
|
|
@ -21,13 +17,13 @@ def environment_dir(ENVIRONMENT_DIR, language_version):
|
|||
if ENVIRONMENT_DIR is None:
|
||||
return None
|
||||
else:
|
||||
return '{}-{}'.format(ENVIRONMENT_DIR, language_version)
|
||||
return f'{ENVIRONMENT_DIR}-{language_version}'
|
||||
|
||||
|
||||
def assert_version_default(binary, version):
|
||||
if version != C.DEFAULT:
|
||||
raise AssertionError(
|
||||
'For now, pre-commit requires system-installed {}'.format(binary),
|
||||
f'For now, pre-commit requires system-installed {binary}',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -68,9 +64,6 @@ def target_concurrency(hook):
|
|||
def _shuffled(seq):
|
||||
"""Deterministically shuffle identically under both py2 + py3."""
|
||||
fixed_random = random.Random()
|
||||
if six.PY2: # pragma: no cover (py2)
|
||||
fixed_random.seed(FIXED_RANDOM_SEED)
|
||||
else: # pragma: no cover (py3)
|
||||
fixed_random.seed(FIXED_RANDOM_SEED, version=1)
|
||||
|
||||
seq = list(seq)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -22,7 +19,7 @@ def _process_filename_by_line(pattern, filename):
|
|||
for line_no, line in enumerate(f, start=1):
|
||||
if pattern.search(line):
|
||||
retv = 1
|
||||
output.write('{}:{}:'.format(filename, line_no))
|
||||
output.write(f'{filename}:{line_no}:')
|
||||
output.write_line(line.rstrip(b'\r\n'))
|
||||
return retv
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.util import CalledProcessError
|
||||
|
|
@ -13,9 +10,6 @@ ENVIRONMENT_DIR = 'py_venv'
|
|||
|
||||
|
||||
def get_default_version(): # pragma: no cover (version specific)
|
||||
if sys.version_info < (3,):
|
||||
return 'python3'
|
||||
else:
|
||||
return python.get_default_version()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import os.path
|
||||
import shutil
|
||||
import tarfile
|
||||
|
|
@ -66,7 +63,7 @@ def _install_rbenv(prefix, version=C.DEFAULT): # pragma: windows no cover
|
|||
_extract_resource('ruby-build.tar.gz', plugins_dir)
|
||||
|
||||
activate_path = prefix.path(directory, 'bin', 'activate')
|
||||
with io.open(activate_path, 'w') as activate_file:
|
||||
with open(activate_path, 'w') as activate_file:
|
||||
# This is similar to how you would install rbenv to your home directory
|
||||
# However we do a couple things to make the executables exposed and
|
||||
# configure it to work in our directory.
|
||||
|
|
@ -86,7 +83,7 @@ def _install_rbenv(prefix, version=C.DEFAULT): # pragma: windows no cover
|
|||
|
||||
# If we aren't using the system ruby, add a version here
|
||||
if version != C.DEFAULT:
|
||||
activate_file.write('export RBENV_VERSION="{}"\n'.format(version))
|
||||
activate_file.write(f'export RBENV_VERSION="{version}"\n')
|
||||
|
||||
|
||||
def _install_ruby(prefix, version): # pragma: windows no cover
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os.path
|
||||
|
||||
|
|
@ -85,7 +83,7 @@ def install_environment(prefix, version, additional_dependencies):
|
|||
for package in packages_to_install:
|
||||
cmd_output_b(
|
||||
'cargo', 'install', '--bins', '--root', directory, *package,
|
||||
cwd=prefix.prefix_dir
|
||||
cwd=prefix.prefix_dir,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
|
||||
|
|
@ -19,14 +17,14 @@ LOG_LEVEL_COLORS = {
|
|||
|
||||
class LoggingHandler(logging.Handler):
|
||||
def __init__(self, use_color):
|
||||
super(LoggingHandler, self).__init__()
|
||||
super().__init__()
|
||||
self.use_color = use_color
|
||||
|
||||
def emit(self, record):
|
||||
output.write_line(
|
||||
'{} {}'.format(
|
||||
color.format_color(
|
||||
'[{}]'.format(record.levelname),
|
||||
f'[{record.levelname}]',
|
||||
LOG_LEVEL_COLORS[record.levelname],
|
||||
self.use_color,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
|
@ -57,7 +55,7 @@ def _add_config_option(parser):
|
|||
|
||||
class AppendReplaceDefault(argparse.Action):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AppendReplaceDefault, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.appended = False
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
|
|
@ -154,7 +152,7 @@ def main(argv=None):
|
|||
parser.add_argument(
|
||||
'-V', '--version',
|
||||
action='version',
|
||||
version='%(prog)s {}'.format(C.VERSION),
|
||||
version=f'%(prog)s {C.VERSION}',
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(dest='command')
|
||||
|
|
@ -254,7 +252,7 @@ def main(argv=None):
|
|||
_add_run_options(run_parser)
|
||||
|
||||
sample_config_parser = subparsers.add_parser(
|
||||
'sample-config', help='Produce a sample {} file'.format(C.CONFIG_FILE),
|
||||
'sample-config', help=f'Produce a sample {C.CONFIG_FILE} file',
|
||||
)
|
||||
_add_color_option(sample_config_parser)
|
||||
_add_config_option(sample_config_parser)
|
||||
|
|
@ -345,11 +343,11 @@ def main(argv=None):
|
|||
return uninstall(hook_types=args.hook_types)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
'Command {} not implemented.'.format(args.command),
|
||||
f'Command {args.command} not implemented.',
|
||||
)
|
||||
|
||||
raise AssertionError(
|
||||
'Command {} failed to exit with a returncode'.format(args.command),
|
||||
f'Command {args.command} failed to exit with a returncode',
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import os.path
|
||||
import tarfile
|
||||
|
|
@ -59,7 +55,7 @@ def main(argv=None):
|
|||
args = parser.parse_args(argv)
|
||||
for archive_name, repo, ref in REPOS:
|
||||
output.write_line(
|
||||
'Making {}.tar.gz for {}@{}'.format(archive_name, repo, ref),
|
||||
f'Making {archive_name}.tar.gz for {repo}@{ref}',
|
||||
)
|
||||
make_archive(archive_name, repo, ref, args.dest)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ def check_all_hooks_match_files(config_file):
|
|||
if hook.always_run or hook.language == 'fail':
|
||||
continue
|
||||
elif not classifier.filenames_for_hook(hook):
|
||||
print('{} does not apply to this repository'.format(hook.id))
|
||||
print(f'{hook.id} does not apply to this repository')
|
||||
retv = 1
|
||||
|
||||
return retv
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import re
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from pre_commit import color
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
from identify.identify import parse_shebang_from_file
|
||||
|
|
@ -44,7 +41,7 @@ def find_executable(exe, _environ=None):
|
|||
|
||||
def normexe(orig):
|
||||
def _error(msg):
|
||||
raise ExecutableNotFoundError('Executable `{}` {}'.format(orig, msg))
|
||||
raise ExecutableNotFoundError(f'Executable `{orig}` {msg}')
|
||||
|
||||
if os.sep not in orig and (not os.altsep or os.altsep not in orig):
|
||||
exe = find_executable(orig)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import os.path
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
|
@ -36,14 +33,14 @@ def _read_state(prefix, venv):
|
|||
if not os.path.exists(filename):
|
||||
return None
|
||||
else:
|
||||
with io.open(filename) as f:
|
||||
with open(filename) as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def _write_state(prefix, venv, state):
|
||||
state_filename = _state_filename(prefix, venv)
|
||||
staging = state_filename + 'staging'
|
||||
with io.open(staging, 'w') as state_file:
|
||||
with open(staging, 'w') as state_file:
|
||||
state_file.write(five.to_text(json.dumps(state)))
|
||||
# Move the file into place atomically to indicate we've installed
|
||||
os.rename(staging, state_filename)
|
||||
|
|
@ -82,7 +79,7 @@ class Hook(collections.namedtuple('Hook', ('src', 'prefix') + _KEYS)):
|
|||
)
|
||||
|
||||
def install(self):
|
||||
logger.info('Installing environment for {}.'.format(self.src))
|
||||
logger.info(f'Installing environment for {self.src}.')
|
||||
logger.info('Once installed this environment will be reused.')
|
||||
logger.info('This may take a few minutes...')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
"""File generated by pre-commit: https://pre-commit.com"""
|
||||
from __future__ import print_function
|
||||
|
||||
import distutils.spawn
|
||||
import os
|
||||
import subprocess
|
||||
|
|
@ -64,7 +62,7 @@ def _run_legacy():
|
|||
else:
|
||||
stdin = None
|
||||
|
||||
legacy_hook = os.path.join(HERE, '{}.legacy'.format(HOOK_TYPE))
|
||||
legacy_hook = os.path.join(HERE, f'{HOOK_TYPE}.legacy')
|
||||
if os.access(legacy_hook, os.X_OK):
|
||||
cmd = _norm_exe(legacy_hook) + (legacy_hook,) + tuple(sys.argv[1:])
|
||||
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE if stdin else None)
|
||||
|
|
@ -136,7 +134,7 @@ def _pre_push(stdin):
|
|||
# ancestors not found in remote
|
||||
ancestors = subprocess.check_output((
|
||||
'git', 'rev-list', local_sha, '--topo-order', '--reverse',
|
||||
'--not', '--remotes={}'.format(remote),
|
||||
'--not', f'--remotes={remote}',
|
||||
)).decode().strip()
|
||||
if not ancestors:
|
||||
continue
|
||||
|
|
@ -148,7 +146,7 @@ def _pre_push(stdin):
|
|||
# pushing the whole tree including root commit
|
||||
opts = ('--all-files',)
|
||||
else:
|
||||
cmd = ('git', 'rev-parse', '{}^'.format(first_ancestor))
|
||||
cmd = ('git', 'rev-parse', f'{first_ancestor}^')
|
||||
source = subprocess.check_output(cmd).decode().strip()
|
||||
opts = ('--origin', local_sha, '--source', source)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import logging
|
||||
import os.path
|
||||
import time
|
||||
|
|
@ -54,11 +51,11 @@ def _unstaged_changes_cleared(patch_dir):
|
|||
patch_filename = os.path.join(patch_dir, patch_filename)
|
||||
logger.warning('Unstaged files detected.')
|
||||
logger.info(
|
||||
'Stashing unstaged files to {}.'.format(patch_filename),
|
||||
f'Stashing unstaged files to {patch_filename}.',
|
||||
)
|
||||
# Save the current unstaged changes as a patch
|
||||
mkdirp(patch_dir)
|
||||
with io.open(patch_filename, 'wb') as patch_file:
|
||||
with open(patch_filename, 'wb') as patch_file:
|
||||
patch_file.write(diff_stdout_binary)
|
||||
|
||||
# Clear the working directory of unstaged changes
|
||||
|
|
@ -79,7 +76,7 @@ def _unstaged_changes_cleared(patch_dir):
|
|||
# Roll back the changes made by hooks.
|
||||
cmd_output_b('git', 'checkout', '--', '.')
|
||||
_git_apply(patch_filename)
|
||||
logger.info('Restored changes from {}.'.format(patch_filename))
|
||||
logger.info(f'Restored changes from {patch_filename}.')
|
||||
else:
|
||||
# There weren't any staged files so we don't need to do anything
|
||||
# special
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import logging
|
||||
import os.path
|
||||
import sqlite3
|
||||
|
|
@ -34,7 +31,7 @@ def _get_default_directory():
|
|||
)
|
||||
|
||||
|
||||
class Store(object):
|
||||
class Store:
|
||||
get_default_directory = staticmethod(_get_default_directory)
|
||||
|
||||
def __init__(self, directory=None):
|
||||
|
|
@ -43,7 +40,7 @@ class Store(object):
|
|||
|
||||
if not os.path.exists(self.directory):
|
||||
mkdirp(self.directory)
|
||||
with io.open(os.path.join(self.directory, 'README'), 'w') as f:
|
||||
with open(os.path.join(self.directory, 'README'), 'w') as f:
|
||||
f.write(
|
||||
'This directory is maintained by the pre-commit project.\n'
|
||||
'Learn more: https://github.com/pre-commit/pre-commit\n',
|
||||
|
|
@ -122,7 +119,7 @@ class Store(object):
|
|||
if result: # pragma: no cover (race)
|
||||
return result
|
||||
|
||||
logger.info('Initializing environment for {}.'.format(repo))
|
||||
logger.info(f'Initializing environment for {repo}.')
|
||||
|
||||
directory = tempfile.mkdtemp(prefix='repo', dir=self.directory)
|
||||
with clean_path_on_failure(directory):
|
||||
|
|
@ -179,8 +176,8 @@ class Store(object):
|
|||
def make_local(self, deps):
|
||||
def make_local_strategy(directory):
|
||||
for resource in self.LOCAL_RESOURCES:
|
||||
contents = resource_text('empty_template_{}'.format(resource))
|
||||
with io.open(os.path.join(directory, resource), 'w') as f:
|
||||
contents = resource_text(f'empty_template_{resource}')
|
||||
with open(os.path.join(directory, resource), 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
env = git.no_git_env()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import os.path
|
||||
|
|
@ -9,8 +7,6 @@ import subprocess
|
|||
import sys
|
||||
import tempfile
|
||||
|
||||
import six
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit import parse_shebang
|
||||
|
||||
|
|
@ -75,7 +71,7 @@ def make_executable(filename):
|
|||
|
||||
class CalledProcessError(RuntimeError):
|
||||
def __init__(self, returncode, cmd, expected_returncode, stdout, stderr):
|
||||
super(CalledProcessError, self).__init__(
|
||||
super().__init__(
|
||||
returncode, cmd, expected_returncode, stdout, stderr,
|
||||
)
|
||||
self.returncode = returncode
|
||||
|
|
@ -104,10 +100,6 @@ class CalledProcessError(RuntimeError):
|
|||
def to_text(self):
|
||||
return self.to_bytes().decode('UTF-8')
|
||||
|
||||
if six.PY2: # pragma: no cover (py2)
|
||||
__str__ = to_bytes
|
||||
__unicode__ = to_text
|
||||
else: # pragma: no cover (py3)
|
||||
__bytes__ = to_bytes
|
||||
__str__ = to_text
|
||||
|
||||
|
|
@ -154,7 +146,7 @@ if os.name != 'nt': # pragma: windows no cover
|
|||
from os import openpty
|
||||
import termios
|
||||
|
||||
class Pty(object):
|
||||
class Pty:
|
||||
def __init__(self):
|
||||
self.r = self.w = None
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import concurrent.futures
|
||||
import contextlib
|
||||
import math
|
||||
|
|
@ -9,8 +5,6 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.util import cmd_output_p
|
||||
|
|
@ -26,7 +20,7 @@ def _environ_size(_env=None):
|
|||
|
||||
def _get_platform_max_length(): # pragma: no cover (platform specific)
|
||||
if os.name == 'posix':
|
||||
maximum = os.sysconf(str('SC_ARG_MAX')) - 2048 - _environ_size()
|
||||
maximum = os.sysconf('SC_ARG_MAX') - 2048 - _environ_size()
|
||||
maximum = max(min(maximum, 2 ** 17), 2 ** 12)
|
||||
return maximum
|
||||
elif os.name == 'nt':
|
||||
|
|
@ -43,9 +37,6 @@ def _command_length(*cmd):
|
|||
# https://github.com/pre-commit/pre-commit/pull/839
|
||||
if sys.platform == 'win32':
|
||||
# the python2.x apis require bytes, we encode as UTF-8
|
||||
if six.PY2:
|
||||
return len(full_cmd.encode('utf-8'))
|
||||
else:
|
||||
return len(full_cmd.encode('utf-16le')) // 2
|
||||
else:
|
||||
return len(full_cmd.encode(sys.getfilesystemencoding()))
|
||||
|
|
@ -125,7 +116,7 @@ def xargs(cmd, varargs, **kwargs):
|
|||
|
||||
def run_cmd_partition(run_cmd):
|
||||
return cmd_fn(
|
||||
*run_cmd, retcode=None, stderr=subprocess.STDOUT, **kwargs
|
||||
*run_cmd, retcode=None, stderr=subprocess.STDOUT, **kwargs,
|
||||
)
|
||||
|
||||
threads = min(len(partitions), target_concurrency)
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ license = MIT
|
|||
license_file = LICENSE
|
||||
classifiers =
|
||||
License :: OSI Approved :: MIT License
|
||||
Programming Language :: Python :: 2
|
||||
Programming Language :: Python :: 2.7
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.5
|
||||
Programming Language :: Python :: 3 :: Only
|
||||
Programming Language :: Python :: 3.6
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
|
|
@ -32,10 +30,9 @@ install_requires =
|
|||
six
|
||||
toml
|
||||
virtualenv>=15.2
|
||||
futures;python_version<"3.2"
|
||||
importlib-metadata;python_version<"3.8"
|
||||
importlib-resources;python_version<"3.7"
|
||||
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
|
||||
python_requires = >=3.6
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import os.path
|
||||
import shutil
|
||||
|
||||
|
|
@ -58,10 +54,10 @@ def modify_manifest(path, commit=True):
|
|||
.pre-commit-hooks.yaml.
|
||||
"""
|
||||
manifest_path = os.path.join(path, C.MANIFEST_FILE)
|
||||
with io.open(manifest_path) as f:
|
||||
with open(manifest_path) as f:
|
||||
manifest = ordered_load(f.read())
|
||||
yield manifest
|
||||
with io.open(manifest_path, 'w') as manifest_file:
|
||||
with open(manifest_path, 'w') as manifest_file:
|
||||
manifest_file.write(ordered_dump(manifest, **C.YAML_DUMP_KWARGS))
|
||||
if commit:
|
||||
git_commit(msg=modify_manifest.__name__, cwd=path)
|
||||
|
|
@ -73,10 +69,10 @@ def modify_config(path='.', commit=True):
|
|||
.pre-commit-config.yaml
|
||||
"""
|
||||
config_path = os.path.join(path, C.CONFIG_FILE)
|
||||
with io.open(config_path) as f:
|
||||
with open(config_path) as f:
|
||||
config = ordered_load(f.read())
|
||||
yield config
|
||||
with io.open(config_path, 'w', encoding='UTF-8') as config_file:
|
||||
with open(config_path, 'w', encoding='UTF-8') as config_file:
|
||||
config_file.write(ordered_dump(config, **C.YAML_DUMP_KWARGS))
|
||||
if commit:
|
||||
git_commit(msg=modify_config.__name__, cwd=path)
|
||||
|
|
@ -101,7 +97,7 @@ def sample_meta_config():
|
|||
def make_config_from_repo(repo_path, rev=None, hooks=None, check=True):
|
||||
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||
config = {
|
||||
'repo': 'file://{}'.format(repo_path),
|
||||
'repo': f'file://{repo_path}',
|
||||
'rev': rev or git.head_rev(repo_path),
|
||||
'hooks': hooks or [{'id': hook['id']} for hook in manifest],
|
||||
}
|
||||
|
|
@ -117,7 +113,7 @@ def make_config_from_repo(repo_path, rev=None, hooks=None, check=True):
|
|||
|
||||
def read_config(directory, config_file=C.CONFIG_FILE):
|
||||
config_path = os.path.join(directory, config_file)
|
||||
with io.open(config_path) as f:
|
||||
with open(config_path) as f:
|
||||
config = ordered_load(f.read())
|
||||
return config
|
||||
|
||||
|
|
@ -126,7 +122,7 @@ def write_config(directory, config, config_file=C.CONFIG_FILE):
|
|||
if type(config) is not list and 'repos' not in config:
|
||||
assert isinstance(config, dict), config
|
||||
config = {'repos': [config]}
|
||||
with io.open(os.path.join(directory, config_file), 'w') as outfile:
|
||||
with open(os.path.join(directory, config_file), 'w') as outfile:
|
||||
outfile.write(ordered_dump(config, **C.YAML_DUMP_KWARGS))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import sys
|
|||
def main():
|
||||
for i in range(6):
|
||||
f = sys.stdout if i % 2 == 0 else sys.stderr
|
||||
f.write('{}\n'.format(i))
|
||||
f.write(f'{i}\n')
|
||||
f.flush()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import os.path
|
||||
import subprocess
|
||||
|
|
@ -50,7 +48,7 @@ def broken_deep_listdir(): # pragma: no cover (platform specific)
|
|||
if sys.platform != 'win32':
|
||||
return False
|
||||
try:
|
||||
os.listdir(str('\\\\?\\') + os.path.abspath(str('.')))
|
||||
os.listdir('\\\\?\\' + os.path.abspath('.'))
|
||||
except OSError:
|
||||
return True
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
import cfgv
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
import mock
|
||||
|
|
@ -14,7 +12,7 @@ from pre_commit.color import use_color
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
('in_text', 'in_color', 'in_use_color', 'expected'), (
|
||||
('foo', GREEN, True, '{}foo\033[0m'.format(GREEN)),
|
||||
('foo', GREEN, True, f'{GREEN}foo\033[0m'),
|
||||
('foo', GREEN, False, 'foo'),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pipes
|
||||
|
||||
import pytest
|
||||
|
|
@ -213,7 +211,7 @@ def test_autoupdate_out_of_date_repo_with_correct_repo_name(
|
|||
|
||||
with open(C.CONFIG_FILE) as f:
|
||||
before = f.read()
|
||||
repo_name = 'file://{}'.format(out_of_date.path)
|
||||
repo_name = f'file://{out_of_date.path}'
|
||||
ret = autoupdate(
|
||||
C.CONFIG_FILE, store, freeze=False, tags_only=False,
|
||||
repos=(repo_name,),
|
||||
|
|
@ -312,7 +310,7 @@ def test_autoupdate_freeze(tagged, in_tmpdir, store):
|
|||
|
||||
assert autoupdate(C.CONFIG_FILE, store, freeze=True, tags_only=False) == 0
|
||||
with open(C.CONFIG_FILE) as f:
|
||||
expected = 'rev: {} # frozen: v1.2.3'.format(tagged.head_rev)
|
||||
expected = f'rev: {tagged.head_rev} # frozen: v1.2.3'
|
||||
assert expected in f.read()
|
||||
|
||||
# if we un-freeze it should remove the frozen comment
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import mock
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -123,7 +118,7 @@ def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
|
|||
fn=cmd_output_mocked_pre_commit_home,
|
||||
retcode=None,
|
||||
tempdir_factory=tempdir_factory,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -203,7 +198,7 @@ def test_commit_am(tempdir_factory, store):
|
|||
open('unstaged', 'w').close()
|
||||
cmd_output('git', 'add', '.')
|
||||
git_commit(cwd=path)
|
||||
with io.open('unstaged', 'w') as foo_file:
|
||||
with open('unstaged', 'w') as foo_file:
|
||||
foo_file.write('Oh hai')
|
||||
|
||||
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) == 0
|
||||
|
|
@ -314,7 +309,7 @@ EXISTING_COMMIT_RUN = re.compile(
|
|||
|
||||
def _write_legacy_hook(path):
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
f.write('#!/usr/bin/env bash\necho "legacy hook"\n')
|
||||
make_executable(f.name)
|
||||
|
||||
|
|
@ -377,7 +372,7 @@ def test_failing_existing_hook_returns_1(tempdir_factory, store):
|
|||
with cwd(path):
|
||||
# Write out a failing "old" hook
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
f.write('#!/usr/bin/env bash\necho "fail!"\nexit 1\n')
|
||||
make_executable(f.name)
|
||||
|
||||
|
|
@ -439,7 +434,7 @@ def test_replace_old_commit_script(tempdir_factory, store):
|
|||
)
|
||||
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
f.write(new_contents)
|
||||
make_executable(f.name)
|
||||
|
||||
|
|
@ -525,7 +520,7 @@ def _get_push_output(tempdir_factory, opts=()):
|
|||
return cmd_output_mocked_pre_commit_home(
|
||||
'git', 'push', 'origin', 'HEAD:new_branch', *opts,
|
||||
tempdir_factory=tempdir_factory,
|
||||
retcode=None
|
||||
retcode=None,
|
||||
)[:2]
|
||||
|
||||
|
||||
|
|
@ -616,7 +611,7 @@ def test_pre_push_legacy(tempdir_factory, store):
|
|||
cmd_output('git', 'clone', upstream, path)
|
||||
with cwd(path):
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-push'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-push'), 'w') as f:
|
||||
f.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -665,7 +660,7 @@ def test_commit_msg_integration_passing(
|
|||
def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
||||
hook_path = os.path.join(commit_msg_repo, '.git/hooks/commit-msg')
|
||||
mkdirp(os.path.dirname(hook_path))
|
||||
with io.open(hook_path, 'w') as hook_file:
|
||||
with open(hook_path, 'w') as hook_file:
|
||||
hook_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -709,7 +704,7 @@ def test_prepare_commit_msg_integration_passing(
|
|||
commit_msg_path = os.path.join(
|
||||
prepare_commit_msg_repo, '.git/COMMIT_EDITMSG',
|
||||
)
|
||||
with io.open(commit_msg_path) as f:
|
||||
with open(commit_msg_path) as f:
|
||||
assert 'Signed off by: ' in f.read()
|
||||
|
||||
|
||||
|
|
@ -720,7 +715,7 @@ def test_prepare_commit_msg_legacy(
|
|||
prepare_commit_msg_repo, '.git/hooks/prepare-commit-msg',
|
||||
)
|
||||
mkdirp(os.path.dirname(hook_path))
|
||||
with io.open(hook_path, 'w') as hook_file:
|
||||
with open(hook_path, 'w') as hook_file:
|
||||
hook_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -739,7 +734,7 @@ def test_prepare_commit_msg_legacy(
|
|||
commit_msg_path = os.path.join(
|
||||
prepare_commit_msg_repo, '.git/COMMIT_EDITMSG',
|
||||
)
|
||||
with io.open(commit_msg_path) as f:
|
||||
with open(commit_msg_path) as f:
|
||||
assert 'Signed off by: ' in f.read()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import pipes
|
||||
import sys
|
||||
|
|
@ -154,7 +150,7 @@ def test_types_hook_repository(cap_out, store, tempdir_factory):
|
|||
def test_exclude_types_hook_repository(cap_out, store, tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'exclude_types_repo')
|
||||
with cwd(git_path):
|
||||
with io.open('exe', 'w') as exe:
|
||||
with open('exe', 'w') as exe:
|
||||
exe.write('#!/usr/bin/env python3\n')
|
||||
make_executable('exe')
|
||||
cmd_output('git', 'add', 'exe')
|
||||
|
|
@ -601,8 +597,8 @@ def test_stages(cap_out, store, repo_with_passing_hook):
|
|||
'repo': 'local',
|
||||
'hooks': [
|
||||
{
|
||||
'id': 'do-not-commit-{}'.format(i),
|
||||
'name': 'hook {}'.format(i),
|
||||
'id': f'do-not-commit-{i}',
|
||||
'name': f'hook {i}',
|
||||
'entry': 'DO NOT COMMIT',
|
||||
'language': 'pygrep',
|
||||
'stages': [stage],
|
||||
|
|
@ -636,7 +632,7 @@ def test_stages(cap_out, store, repo_with_passing_hook):
|
|||
|
||||
def test_commit_msg_hook(cap_out, store, commit_msg_repo):
|
||||
filename = '.git/COMMIT_EDITMSG'
|
||||
with io.open(filename, 'w') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write('This is the commit message')
|
||||
|
||||
_test_run(
|
||||
|
|
@ -652,7 +648,7 @@ def test_commit_msg_hook(cap_out, store, commit_msg_repo):
|
|||
|
||||
def test_prepare_commit_msg_hook(cap_out, store, prepare_commit_msg_repo):
|
||||
filename = '.git/COMMIT_EDITMSG'
|
||||
with io.open(filename, 'w') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write('This is the commit message')
|
||||
|
||||
_test_run(
|
||||
|
|
@ -665,7 +661,7 @@ def test_prepare_commit_msg_hook(cap_out, store, prepare_commit_msg_repo):
|
|||
stage=False,
|
||||
)
|
||||
|
||||
with io.open(filename) as f:
|
||||
with open(filename) as f:
|
||||
assert 'Signed off by: ' in f.read()
|
||||
|
||||
|
||||
|
|
@ -692,7 +688,7 @@ def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
|
|||
}
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
with io.open('dummy.py', 'w') as staged_file:
|
||||
with open('dummy.py', 'w') as staged_file:
|
||||
staged_file.write('"""TODO: something"""\n')
|
||||
cmd_output('git', 'add', 'dummy.py')
|
||||
|
||||
|
|
@ -719,7 +715,7 @@ def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
|
|||
}
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
with io.open('dummy.py', 'w') as staged_file:
|
||||
with open('dummy.py', 'w') as staged_file:
|
||||
staged_file.write('"""TODO: something"""\n')
|
||||
cmd_output('git', 'add', 'dummy.py')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.commands.sample_config import sample_config
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import io
|
||||
import logging
|
||||
|
|
@ -8,7 +5,6 @@ import os.path
|
|||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit import output
|
||||
from pre_commit.envcontext import envcontext
|
||||
|
|
@ -36,19 +32,19 @@ def no_warnings(recwarn):
|
|||
' missing __init__' in message
|
||||
):
|
||||
warnings.append(
|
||||
'{}:{} {}'.format(warning.filename, warning.lineno, message),
|
||||
f'{warning.filename}:{warning.lineno} {message}',
|
||||
)
|
||||
assert not warnings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tempdir_factory(tmpdir):
|
||||
class TmpdirFactory(object):
|
||||
class TmpdirFactory:
|
||||
def __init__(self):
|
||||
self.tmpdir_count = 0
|
||||
|
||||
def get(self):
|
||||
path = tmpdir.join(six.text_type(self.tmpdir_count)).strpath
|
||||
path = tmpdir.join(str(self.tmpdir_count)).strpath
|
||||
self.tmpdir_count += 1
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
|
@ -73,18 +69,18 @@ def in_git_dir(tmpdir):
|
|||
|
||||
def _make_conflict():
|
||||
cmd_output('git', 'checkout', 'origin/master', '-b', 'foo')
|
||||
with io.open('conflict_file', 'w') as conflict_file:
|
||||
with open('conflict_file', 'w') as conflict_file:
|
||||
conflict_file.write('herp\nderp\n')
|
||||
cmd_output('git', 'add', 'conflict_file')
|
||||
with io.open('foo_only_file', 'w') as foo_only_file:
|
||||
with open('foo_only_file', 'w') as foo_only_file:
|
||||
foo_only_file.write('foo')
|
||||
cmd_output('git', 'add', 'foo_only_file')
|
||||
git_commit(msg=_make_conflict.__name__)
|
||||
cmd_output('git', 'checkout', 'origin/master', '-b', 'bar')
|
||||
with io.open('conflict_file', 'w') as conflict_file:
|
||||
with open('conflict_file', 'w') as conflict_file:
|
||||
conflict_file.write('harp\nddrp\n')
|
||||
cmd_output('git', 'add', 'conflict_file')
|
||||
with io.open('bar_only_file', 'w') as bar_only_file:
|
||||
with open('bar_only_file', 'w') as bar_only_file:
|
||||
bar_only_file.write('bar')
|
||||
cmd_output('git', 'add', 'bar_only_file')
|
||||
git_commit(msg=_make_conflict.__name__)
|
||||
|
|
@ -145,14 +141,14 @@ def prepare_commit_msg_repo(tempdir_factory):
|
|||
'hooks': [{
|
||||
'id': 'add-signoff',
|
||||
'name': 'Add "Signed off by:"',
|
||||
'entry': './{}'.format(script_name),
|
||||
'entry': f'./{script_name}',
|
||||
'language': 'script',
|
||||
'stages': ['prepare-commit-msg'],
|
||||
}],
|
||||
}
|
||||
write_config(path, config)
|
||||
with cwd(path):
|
||||
with io.open(script_name, 'w') as script_file:
|
||||
with open(script_name, 'w') as script_file:
|
||||
script_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -229,7 +225,7 @@ def log_info_mock():
|
|||
yield mck
|
||||
|
||||
|
||||
class FakeStream(object):
|
||||
class FakeStream:
|
||||
def __init__(self):
|
||||
self.data = io.BytesIO()
|
||||
|
||||
|
|
@ -240,7 +236,7 @@ class FakeStream(object):
|
|||
pass
|
||||
|
||||
|
||||
class Fixture(object):
|
||||
class Fixture:
|
||||
def __init__(self, stream):
|
||||
self._stream = stream
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import mock
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -109,7 +104,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
|
|||
)
|
||||
|
||||
assert os.path.exists(log_file)
|
||||
with io.open(log_file) as f:
|
||||
with open(log_file) as f:
|
||||
logged = f.read()
|
||||
expected = (
|
||||
r'^### version information\n'
|
||||
|
|
@ -158,4 +153,4 @@ def test_error_handler_no_tty(tempdir_factory):
|
|||
log_file = os.path.join(pre_commit_home, 'pre-commit.log')
|
||||
out_lines = out.splitlines()
|
||||
assert out_lines[-2] == 'An unexpected error has occurred: ValueError: ☃'
|
||||
assert out_lines[-1] == 'Check the log at {}'.format(log_file)
|
||||
assert out_lines[-1] == f'Check the log at {log_file}'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,26 +1,17 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit.languages.all import all_languages
|
||||
from pre_commit.languages.all import languages
|
||||
|
||||
|
||||
if six.PY2: # pragma: no cover
|
||||
ArgSpec = functools.partial(
|
||||
inspect.ArgSpec, varargs=None, keywords=None, defaults=None,
|
||||
)
|
||||
getargspec = inspect.getargspec
|
||||
else: # pragma: no cover
|
||||
ArgSpec = functools.partial(
|
||||
ArgSpec = functools.partial(
|
||||
inspect.FullArgSpec, varargs=None, varkw=None, defaults=None,
|
||||
kwonlyargs=[], kwonlydefaults=None, annotations={},
|
||||
)
|
||||
getargspec = inspect.getfullargspec
|
||||
)
|
||||
getargspec = inspect.getfullargspec
|
||||
|
||||
|
||||
@pytest.mark.parametrize('language', all_languages)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
|
||||
from pre_commit.languages import docker
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages.golang import guess_go_dir
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages import pygrep
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
|
|
@ -16,7 +13,7 @@ def test_norm_version_expanduser():
|
|||
home = os.path.expanduser('~')
|
||||
if os.name == 'nt': # pragma: no cover (nt)
|
||||
path = r'~\python343'
|
||||
expected_path = r'{}\python343'.format(home)
|
||||
expected_path = fr'{home}\python343'
|
||||
else: # pragma: windows no cover
|
||||
path = '~/.pyenv/versions/3.4.3/bin/python'
|
||||
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import pipes
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit import color
|
||||
from pre_commit.logging_handler import LoggingHandler
|
||||
|
||||
|
||||
class FakeLogRecord(object):
|
||||
class FakeLogRecord:
|
||||
def __init__(self, message, levelname, levelno):
|
||||
self.message = message
|
||||
self.levelname = levelname
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import os.path
|
||||
|
||||
|
|
@ -27,7 +24,7 @@ def test_append_replace_default(argv, expected):
|
|||
assert parser.parse_args(argv).f == expected
|
||||
|
||||
|
||||
class Args(object):
|
||||
class Args:
|
||||
def __init__(self, **kwargs):
|
||||
kwargs.setdefault('command', 'help')
|
||||
kwargs.setdefault('config', C.CONFIG_FILE)
|
||||
|
|
@ -189,4 +186,4 @@ def test_expected_fatal_error_no_git_repo(in_tmpdir, cap_out, mock_store_dir):
|
|||
'An error has occurred: FatalError: git failed. '
|
||||
'Is it installed, and are you in a Git repository directory?'
|
||||
)
|
||||
assert cap_out_lines[-1] == 'Check the log at {}'.format(log_file)
|
||||
assert cap_out_lines[-1] == f'Check the log at {log_file}'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import tarfile
|
||||
|
||||
from pre_commit import git
|
||||
|
|
@ -46,4 +43,4 @@ def test_main(tmpdir):
|
|||
make_archives.main(('--dest', tmpdir.strpath))
|
||||
|
||||
for archive, _, _ in make_archives.REPOS:
|
||||
assert tmpdir.join('{}.tar.gz'.format(archive)).exists()
|
||||
assert tmpdir.join(f'{archive}.tar.gz').exists()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import distutils.spawn
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
|
@ -42,8 +38,8 @@ def test_find_executable_not_found_none():
|
|||
def write_executable(shebang, filename='run'):
|
||||
os.mkdir('bin')
|
||||
path = os.path.join('bin', filename)
|
||||
with io.open(path, 'w') as f:
|
||||
f.write('#!{}'.format(shebang))
|
||||
with open(path, 'w') as f:
|
||||
f.write(f'#!{shebang}')
|
||||
make_executable(path)
|
||||
return path
|
||||
|
||||
|
|
@ -106,7 +102,7 @@ def test_normexe_is_a_directory(tmpdir):
|
|||
with pytest.raises(OSError) as excinfo:
|
||||
parse_shebang.normexe(exe)
|
||||
msg, = excinfo.value.args
|
||||
assert msg == 'Executable `{}` is a directory'.format(exe)
|
||||
assert msg == f'Executable `{exe}` is a directory'
|
||||
|
||||
|
||||
def test_normexe_already_full_path():
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
|
|
@ -473,7 +470,7 @@ def _norm_pwd(path):
|
|||
# Under windows bash's temp and windows temp is different.
|
||||
# This normalizes to the bash /tmp
|
||||
return cmd_output_b(
|
||||
'bash', '-c', "cd '{}' && pwd".format(path),
|
||||
'bash', '-c', f"cd '{path}' && pwd",
|
||||
)[1].strip()
|
||||
|
||||
|
||||
|
|
@ -844,7 +841,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
|||
hook = _get_hook(config, store, 'bash_hook')
|
||||
|
||||
assert hook == Hook(
|
||||
src='file://{}'.format(path),
|
||||
src=f'file://{path}',
|
||||
prefix=Prefix(mock.ANY),
|
||||
additional_dependencies=[],
|
||||
alias='',
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import itertools
|
||||
import os.path
|
||||
import shutil
|
||||
|
|
@ -47,7 +42,7 @@ def _test_foo_state(
|
|||
encoding='UTF-8',
|
||||
):
|
||||
assert os.path.exists(path.foo_filename)
|
||||
with io.open(path.foo_filename, encoding=encoding) as f:
|
||||
with open(path.foo_filename, encoding=encoding) as f:
|
||||
assert f.read() == foo_contents
|
||||
actual_status = get_short_git_status()['foo']
|
||||
assert status == actual_status
|
||||
|
|
@ -64,7 +59,7 @@ def test_foo_nothing_unstaged(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_foo_something_unstaged(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write('herp\nderp\n')
|
||||
|
||||
_test_foo_state(foo_staged, 'herp\nderp\n', 'AM')
|
||||
|
|
@ -76,7 +71,7 @@ def test_foo_something_unstaged(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_does_not_crash_patch_dir_does_not_exist(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write('hello\nworld\n')
|
||||
|
||||
shutil.rmtree(patch_dir)
|
||||
|
|
@ -97,7 +92,7 @@ def test_foo_something_unstaged_diff_color_always(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_foo_both_modify_non_conflicting(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS + '9\n')
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS + '9\n', 'AM')
|
||||
|
|
@ -106,7 +101,7 @@ def test_foo_both_modify_non_conflicting(foo_staged, patch_dir):
|
|||
_test_foo_state(foo_staged)
|
||||
|
||||
# Modify the file as part of the "pre-commit"
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS.replace('1', 'a'))
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS.replace('1', 'a'), 'AM')
|
||||
|
|
@ -115,7 +110,7 @@ def test_foo_both_modify_non_conflicting(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_foo_both_modify_conflicting(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS.replace('1', 'a'))
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS.replace('1', 'a'), 'AM')
|
||||
|
|
@ -124,7 +119,7 @@ def test_foo_both_modify_conflicting(foo_staged, patch_dir):
|
|||
_test_foo_state(foo_staged)
|
||||
|
||||
# Modify in the same place as the stashed diff
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS.replace('1', 'b'))
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS.replace('1', 'b'), 'AM')
|
||||
|
|
@ -142,8 +137,8 @@ def img_staged(in_git_dir):
|
|||
|
||||
def _test_img_state(path, expected_file='img1.jpg', status='A'):
|
||||
assert os.path.exists(path.img_filename)
|
||||
with io.open(path.img_filename, 'rb') as f1:
|
||||
with io.open(get_resource_path(expected_file), 'rb') as f2:
|
||||
with open(path.img_filename, 'rb') as f1:
|
||||
with open(get_resource_path(expected_file), 'rb') as f2:
|
||||
assert f1.read() == f2.read()
|
||||
actual_status = get_short_git_status()['img.jpg']
|
||||
assert status == actual_status
|
||||
|
|
@ -248,7 +243,7 @@ def test_sub_something_unstaged(sub_staged, patch_dir):
|
|||
|
||||
def test_stage_utf8_changes(foo_staged, patch_dir):
|
||||
contents = '\u2603'
|
||||
with io.open('foo', 'w', encoding='UTF-8') as foo_file:
|
||||
with open('foo', 'w', encoding='UTF-8') as foo_file:
|
||||
foo_file.write(contents)
|
||||
|
||||
_test_foo_state(foo_staged, contents, 'AM')
|
||||
|
|
@ -260,7 +255,7 @@ def test_stage_utf8_changes(foo_staged, patch_dir):
|
|||
def test_stage_non_utf8_changes(foo_staged, patch_dir):
|
||||
contents = 'ú'
|
||||
# Produce a latin-1 diff
|
||||
with io.open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
with open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
foo_file.write(contents)
|
||||
|
||||
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
|
||||
|
|
@ -282,14 +277,14 @@ def test_non_utf8_conflicting_diff(foo_staged, patch_dir):
|
|||
# Previously, the error message (though discarded immediately) was being
|
||||
# decoded with the UTF-8 codec (causing a crash)
|
||||
contents = 'ú \n'
|
||||
with io.open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
with open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
foo_file.write(contents)
|
||||
|
||||
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
|
||||
with staged_files_only(patch_dir):
|
||||
_test_foo_state(foo_staged)
|
||||
# Create a conflicting diff that will need to be rolled back
|
||||
with io.open('foo', 'w') as foo_file:
|
||||
with open('foo', 'w') as foo_file:
|
||||
foo_file.write('')
|
||||
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import sqlite3
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit import git
|
||||
from pre_commit.store import _get_default_directory
|
||||
|
|
@ -53,7 +48,7 @@ def test_store_init(store):
|
|||
# Should create the store directory
|
||||
assert os.path.exists(store.directory)
|
||||
# Should create a README file indicating what the directory is about
|
||||
with io.open(os.path.join(store.directory, 'README')) as readme_file:
|
||||
with open(os.path.join(store.directory, 'README')) as readme_file:
|
||||
readme_contents = readme_file.read()
|
||||
for text_line in (
|
||||
'This directory is maintained by the pre-commit project.',
|
||||
|
|
@ -93,7 +88,7 @@ def test_clone_cleans_up_on_checkout_failure(store):
|
|||
# This raises an exception because you can't clone something that
|
||||
# doesn't exist!
|
||||
store.clone('/i_dont_exist_lol', 'fake_rev')
|
||||
assert '/i_dont_exist_lol' in six.text_type(excinfo.value)
|
||||
assert '/i_dont_exist_lol' in str(excinfo.value)
|
||||
|
||||
repo_dirs = [
|
||||
d for d in os.listdir(store.directory) if d.startswith('repo')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import stat
|
||||
import subprocess
|
||||
|
|
@ -17,7 +15,7 @@ from pre_commit.util import tmpdir
|
|||
|
||||
|
||||
def test_CalledProcessError_str():
|
||||
error = CalledProcessError(1, [str('exe')], 0, b'output', b'errors')
|
||||
error = CalledProcessError(1, ['exe'], 0, b'output', b'errors')
|
||||
assert str(error) == (
|
||||
"command: ['exe']\n"
|
||||
'return code: 1\n'
|
||||
|
|
@ -30,7 +28,7 @@ def test_CalledProcessError_str():
|
|||
|
||||
|
||||
def test_CalledProcessError_str_nooutput():
|
||||
error = CalledProcessError(1, [str('exe')], 0, b'', b'')
|
||||
error = CalledProcessError(1, ['exe'], 0, b'', b'')
|
||||
assert str(error) == (
|
||||
"command: ['exe']\n"
|
||||
'return code: 1\n'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import concurrent.futures
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
2
tox.ini
2
tox.ini
|
|
@ -1,5 +1,5 @@
|
|||
[tox]
|
||||
envlist = py27,py36,py37,pypy,pypy3,pre-commit
|
||||
envlist = py36,py37,py38,pypy3,pre-commit
|
||||
|
||||
[testenv]
|
||||
deps = -rrequirements-dev.txt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue