mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 20:40:08 -06:00
py27+ syntax improvements
This commit is contained in:
@@ -50,8 +50,8 @@ def _update_repository(repo_config, runner):
|
||||
new_repo = Repository.create(new_config, runner.store)
|
||||
|
||||
# See if any of our hooks were deleted with the new commits
|
||||
hooks = set(hook_id for hook_id, _ in repo.hooks)
|
||||
hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks.keys()))
|
||||
hooks = {hook_id for hook_id, _ in repo.hooks}
|
||||
hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks))
|
||||
if hooks_missing:
|
||||
raise RepositoryCannotBeUpdatedError(
|
||||
'Cannot update because the tip of master is missing these hooks:\n'
|
||||
|
||||
@@ -19,7 +19,7 @@ logger = logging.getLogger('pre_commit')
|
||||
|
||||
def _get_skips(environ):
|
||||
skips = environ.get('SKIP', '')
|
||||
return set(skip.strip() for skip in skips.split(',') if skip.strip())
|
||||
return {skip.strip() for skip in skips.split(',') if skip.strip()}
|
||||
|
||||
|
||||
def _hook_msg_start(hook, verbose):
|
||||
|
||||
@@ -88,7 +88,7 @@ def get_files_matching(all_file_list_strategy):
|
||||
def wrapper(include_expr, exclude_expr):
|
||||
include_regex = re.compile(include_expr)
|
||||
exclude_regex = re.compile(exclude_expr)
|
||||
return set(
|
||||
return {
|
||||
filename
|
||||
for filename in all_file_list_strategy()
|
||||
if (
|
||||
@@ -96,7 +96,7 @@ def get_files_matching(all_file_list_strategy):
|
||||
not exclude_regex.search(filename) and
|
||||
os.path.lexists(filename)
|
||||
)
|
||||
)
|
||||
}
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
@@ -21,4 +21,4 @@ class Manifest(object):
|
||||
|
||||
@cached_property
|
||||
def hooks(self):
|
||||
return dict((hook['id'], hook) for hook in self.manifest_contents)
|
||||
return {hook['id']: hook for hook in self.manifest_contents}
|
||||
|
||||
@@ -57,10 +57,10 @@ class Repository(object):
|
||||
|
||||
@cached_property
|
||||
def languages(self):
|
||||
return set(
|
||||
return {
|
||||
(hook['language'], hook['language_version'])
|
||||
for _, hook in self.hooks
|
||||
)
|
||||
}
|
||||
|
||||
@cached_property
|
||||
def additional_dependencies(self):
|
||||
|
||||
@@ -75,9 +75,9 @@ def no_git_env():
|
||||
# while running pre-commit hooks in submodules.
|
||||
# GIT_DIR: Causes git clone to clone wrong thing
|
||||
# GIT_INDEX_FILE: Causes 'error invalid object ...' during commit
|
||||
return dict(
|
||||
(k, v) for k, v in os.environ.items() if not k.startswith('GIT_')
|
||||
)
|
||||
return {
|
||||
k: v for k, v in os.environ.items() if not k.startswith('GIT_')
|
||||
}
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@@ -164,10 +164,10 @@ def cmd_output(*cmd, **kwargs):
|
||||
|
||||
# py2/py3 on windows are more strict about the types here
|
||||
cmd = tuple(five.n(arg) for arg in cmd)
|
||||
kwargs['env'] = dict(
|
||||
(five.n(key), five.n(value))
|
||||
kwargs['env'] = {
|
||||
five.n(key): five.n(value)
|
||||
for key, value in kwargs.pop('env', {}).items()
|
||||
) or None
|
||||
} or None
|
||||
|
||||
try:
|
||||
cmd = parse_shebang.normalize_cmd(cmd)
|
||||
|
||||
@@ -339,13 +339,13 @@ def test_compute_cols(hooks, verbose, expected):
|
||||
@pytest.mark.parametrize(
|
||||
('environ', 'expected_output'),
|
||||
(
|
||||
({}, set([])),
|
||||
({'SKIP': ''}, set([])),
|
||||
({'SKIP': ','}, set([])),
|
||||
({'SKIP': ',foo'}, set(['foo'])),
|
||||
({'SKIP': 'foo'}, set(['foo'])),
|
||||
({'SKIP': 'foo,bar'}, set(['foo', 'bar'])),
|
||||
({'SKIP': ' foo , bar'}, set(['foo', 'bar'])),
|
||||
({}, set()),
|
||||
({'SKIP': ''}, set()),
|
||||
({'SKIP': ','}, set()),
|
||||
({'SKIP': ',foo'}, {'foo'}),
|
||||
({'SKIP': 'foo'}, {'foo'}),
|
||||
({'SKIP': 'foo,bar'}, {'foo', 'bar'}),
|
||||
({'SKIP': ' foo , bar'}, {'foo', 'bar'}),
|
||||
),
|
||||
)
|
||||
def test_get_skips(environ, expected_output):
|
||||
|
||||
@@ -80,25 +80,22 @@ def get_files_matching_func():
|
||||
|
||||
def test_get_files_matching_base(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '^$')
|
||||
assert ret == set([
|
||||
assert ret == {
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
'hooks.yaml',
|
||||
'testing/test_symlink'
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
def test_get_files_matching_total_match(get_files_matching_func):
|
||||
ret = get_files_matching_func('^.*\\.py$', '^$')
|
||||
assert ret == set([
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
])
|
||||
assert ret == {'pre_commit/main.py', 'pre_commit/git.py'}
|
||||
|
||||
|
||||
def test_does_search_instead_of_match(get_files_matching_func):
|
||||
ret = get_files_matching_func('\\.yaml$', '^$')
|
||||
assert ret == set(['hooks.yaml'])
|
||||
assert ret == {'hooks.yaml'}
|
||||
|
||||
|
||||
def test_does_not_include_deleted_fileS(get_files_matching_func):
|
||||
@@ -108,7 +105,7 @@ def test_does_not_include_deleted_fileS(get_files_matching_func):
|
||||
|
||||
def test_exclude_removes_files(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '\\.py$')
|
||||
assert ret == set(['hooks.yaml', 'testing/test_symlink'])
|
||||
assert ret == {'hooks.yaml', 'testing/test_symlink'}
|
||||
|
||||
|
||||
def resolve_conflict():
|
||||
@@ -124,12 +121,12 @@ def test_get_conflicted_files(in_merge_conflict):
|
||||
cmd_output('git', 'add', 'other_file')
|
||||
|
||||
ret = set(git.get_conflicted_files())
|
||||
assert ret == set(('conflict_file', 'other_file'))
|
||||
assert ret == {'conflict_file', 'other_file'}
|
||||
|
||||
|
||||
def test_get_conflicted_files_in_submodule(in_conflicting_submodule):
|
||||
resolve_conflict()
|
||||
assert set(git.get_conflicted_files()) == set(('conflict_file',))
|
||||
assert set(git.get_conflicted_files()) == {'conflict_file'}
|
||||
|
||||
|
||||
def test_get_conflicted_files_unstaged_files(in_merge_conflict):
|
||||
@@ -142,7 +139,7 @@ def test_get_conflicted_files_unstaged_files(in_merge_conflict):
|
||||
bar_only_file.write('new contents!\n')
|
||||
|
||||
ret = set(git.get_conflicted_files())
|
||||
assert ret == set(('conflict_file',))
|
||||
assert ret == {'conflict_file'}
|
||||
|
||||
|
||||
MERGE_MSG = "Merge branch 'foo' into bar\n\nConflicts:\n\tconflict_file\n"
|
||||
|
||||
@@ -426,7 +426,7 @@ def test_languages(tempdir_factory, store):
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
assert repo.languages == set([('python', 'default')])
|
||||
assert repo.languages == {('python', 'default')}
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -435,7 +435,7 @@ def test_additional_dependencies(tempdir_factory, store):
|
||||
config = make_config_from_repo(path)
|
||||
config['hooks'][0]['additional_dependencies'] = ['pep8']
|
||||
repo = Repository.create(config, store)
|
||||
assert repo.additional_dependencies['python']['default'] == set(('pep8',))
|
||||
assert repo.additional_dependencies['python']['default'] == {'pep8'}
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
||||
Reference in New Issue
Block a user