mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
add in an option to disable a hook when run with --all-files
This commit is contained in:
parent
cb0bcfd67f
commit
3a8b270dc0
3 changed files with 7 additions and 3 deletions
|
|
@ -81,6 +81,7 @@ MANIFEST_HOOK_DICT = cfgv.Map(
|
|||
cfgv.Optional('require_serial', cfgv.check_bool, False),
|
||||
cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),
|
||||
cfgv.Optional('verbose', cfgv.check_bool, False),
|
||||
cfgv.Optional('run_all', cfgv.check_bool, True),
|
||||
)
|
||||
MANIFEST_SCHEMA = cfgv.Array(MANIFEST_HOOK_DICT)
|
||||
|
||||
|
|
|
|||
|
|
@ -126,9 +126,11 @@ class Classifier:
|
|||
return Classifier(filenames)
|
||||
|
||||
|
||||
def _get_skips(environ: MutableMapping[str, str]) -> set[str]:
|
||||
def _get_skips(environ: MutableMapping[str, str], args: argparse.Namespace, hooks: list[Hook]) -> set[str]:
|
||||
skips = environ.get('SKIP', '')
|
||||
return {skip.strip() for skip in skips.split(',') if skip.strip()}
|
||||
environ_skips = {skip.strip() for skip in skips.split(',') if skip.strip()}
|
||||
context_skips = {h.id for h in hooks if args.all_files and not h.run_all}
|
||||
return environ_skips | context_skips
|
||||
|
||||
|
||||
SKIPPED = 'Skipped'
|
||||
|
|
@ -419,7 +421,7 @@ def run(
|
|||
)
|
||||
return 1
|
||||
|
||||
skips = _get_skips(environ)
|
||||
skips = _get_skips(environ, args, hooks)
|
||||
to_install = [
|
||||
hook
|
||||
for hook in hooks
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class Hook(NamedTuple):
|
|||
require_serial: bool
|
||||
stages: Sequence[str]
|
||||
verbose: bool
|
||||
run_all: bool
|
||||
|
||||
@property
|
||||
def cmd(self) -> tuple[str, ...]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue