upgrade hooks, pyupgrade pre-commit

This commit is contained in:
Anthony Sottile 2020-01-08 20:49:09 -08:00
parent 764c765d29
commit 30c1e8289f
91 changed files with 176 additions and 437 deletions

View file

@ -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

View file

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import os.path
import mock

View file

@ -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()

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
import pre_commit.constants as C

View file

@ -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')

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from pre_commit.commands.sample_config import sample_config

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import os.path
import re
import time