Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24d9dc7

Browse files
authored
Merge pull request #1875 from pre-commit/skip-installation-for-skip
skip installation for SKIP'd hooks
2 parents 9b4e769 + 12a7075 commit 24d9dc7

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

pre_commit/commands/run.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ def _get_diff() -> bytes:
271271
def _run_hooks(
272272
config: Dict[str, Any],
273273
hooks: Sequence[Hook],
274+
skips: Set[str],
274275
args: argparse.Namespace,
275276
environ: MutableMapping[str, str],
276277
) -> int:
277278
"""Actually run the hooks."""
278-
skips = _get_skips(environ)
279279
cols = _compute_cols(hooks)
280280
classifier = Classifier.from_config(
281281
_all_filenames(args), config['files'], config['exclude'],
@@ -403,9 +403,11 @@ def run(
403403
)
404404
return 1
405405

406-
install_hook_envs(hooks, store)
406+
skips = _get_skips(environ)
407+
to_install = [hook for hook in hooks if hook.id not in skips]
408+
install_hook_envs(to_install, store)
407409

408-
return _run_hooks(config, hooks, args, environ)
410+
return _run_hooks(config, hooks, skips, args, environ)
409411

410412
# https://github.com/python/mypy/issues/7726
411413
raise AssertionError('unreachable')

tests/commands/run_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,29 @@ def test_skip_aliased_hook(cap_out, store, aliased_repo):
600600
assert printed.count(msg) == 1
601601

602602

603+
def test_skip_bypasses_installation(cap_out, store, repo_with_passing_hook):
604+
config = {
605+
'repo': 'local',
606+
'hooks': [
607+
{
608+
'id': 'skipme',
609+
'name': 'skipme',
610+
'entry': 'skipme',
611+
'language': 'python',
612+
'additional_dependencies': ['/pre-commit-does-not-exist'],
613+
},
614+
],
615+
}
616+
add_config_to_repo(repo_with_passing_hook, config)
617+
618+
ret, printed = _do_run(
619+
cap_out, store, repo_with_passing_hook,
620+
run_opts(all_files=True),
621+
{'SKIP': 'skipme'},
622+
)
623+
assert ret == 0
624+
625+
603626
def test_hook_id_not_in_non_verbose_output(
604627
cap_out, store, repo_with_passing_hook,
605628
):

0 commit comments

Comments
 (0)