mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
py27+ syntax improvements
This commit is contained in:
parent
0a93f3bfdd
commit
ba75867c93
9 changed files with 31 additions and 34 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue