Fix precommit issues

This commit is contained in:
Josh Abrams 2022-11-12 02:26:00 -05:00
parent 189490a938
commit 0d40562dcb
4 changed files with 35 additions and 15 deletions

View file

@ -100,6 +100,7 @@ def _ns(
rewrite_command=rewrite_command,
files=(),
hook=None,
tags=(),
verbose=False,
show_diff_on_failure=False,
)

View file

@ -11,6 +11,7 @@ import time
import unicodedata
from typing import Any
from typing import Collection
from typing import Iterable
from typing import MutableMapping
from typing import Sequence
@ -323,26 +324,29 @@ def _has_unstaged_config(config_file: str) -> bool:
# be explicit, other git errors don't mean it has an unstaged config.
return retcode == 1
def _hook_should_run(args: argparse.Namespace, hook: Hook) -> bool:
if args.hook_stage not in hook.stages:
return False
if args.tags:
return len(set(hook.tags) & set(args.tags)) > 0
return (
not args.hook
or hook.id == args.hook
or hook.alias == args.hook
not args.hook or
hook.id == args.hook or
hook.alias == args.hook
)
def _hook_is_skipped(skips: Sequence[str], hook: Hook) -> bool:
def _hook_is_skipped(skips: Iterable[str], hook: Hook) -> bool:
return (
hook.id in skips
or hook.alias in skips
or len(set(hook.tags) & set(skips)) > 0
hook.id in skips or
hook.alias in skips or
len(set(hook.tags) & set(skips)) > 0
)
def run(
config_file: str,
store: Store,
@ -438,7 +442,8 @@ def run(
return 1
if args.tags and not hooks:
output.write_line(
f'No hooks with tags matching `{args.tags}` in stage `{args.hook_stage}`'
f'No hooks with tags matching `{args.tags}` '
f'in stage `{args.hook_stage}`',
)
return 1