mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1875 from pre-commit/skip-installation-for-skip
skip installation for SKIP'd hooks
This commit is contained in:
commit
24d9dc7469
2 changed files with 28 additions and 3 deletions
|
|
@ -271,11 +271,11 @@ def _get_diff() -> bytes:
|
||||||
def _run_hooks(
|
def _run_hooks(
|
||||||
config: Dict[str, Any],
|
config: Dict[str, Any],
|
||||||
hooks: Sequence[Hook],
|
hooks: Sequence[Hook],
|
||||||
|
skips: Set[str],
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
environ: MutableMapping[str, str],
|
environ: MutableMapping[str, str],
|
||||||
) -> int:
|
) -> int:
|
||||||
"""Actually run the hooks."""
|
"""Actually run the hooks."""
|
||||||
skips = _get_skips(environ)
|
|
||||||
cols = _compute_cols(hooks)
|
cols = _compute_cols(hooks)
|
||||||
classifier = Classifier.from_config(
|
classifier = Classifier.from_config(
|
||||||
_all_filenames(args), config['files'], config['exclude'],
|
_all_filenames(args), config['files'], config['exclude'],
|
||||||
|
|
@ -403,9 +403,11 @@ def run(
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
install_hook_envs(hooks, store)
|
skips = _get_skips(environ)
|
||||||
|
to_install = [hook for hook in hooks if hook.id not in skips]
|
||||||
|
install_hook_envs(to_install, store)
|
||||||
|
|
||||||
return _run_hooks(config, hooks, args, environ)
|
return _run_hooks(config, hooks, skips, args, environ)
|
||||||
|
|
||||||
# https://github.com/python/mypy/issues/7726
|
# https://github.com/python/mypy/issues/7726
|
||||||
raise AssertionError('unreachable')
|
raise AssertionError('unreachable')
|
||||||
|
|
|
||||||
|
|
@ -600,6 +600,29 @@ def test_skip_aliased_hook(cap_out, store, aliased_repo):
|
||||||
assert printed.count(msg) == 1
|
assert printed.count(msg) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_skip_bypasses_installation(cap_out, store, repo_with_passing_hook):
|
||||||
|
config = {
|
||||||
|
'repo': 'local',
|
||||||
|
'hooks': [
|
||||||
|
{
|
||||||
|
'id': 'skipme',
|
||||||
|
'name': 'skipme',
|
||||||
|
'entry': 'skipme',
|
||||||
|
'language': 'python',
|
||||||
|
'additional_dependencies': ['/pre-commit-does-not-exist'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
add_config_to_repo(repo_with_passing_hook, config)
|
||||||
|
|
||||||
|
ret, printed = _do_run(
|
||||||
|
cap_out, store, repo_with_passing_hook,
|
||||||
|
run_opts(all_files=True),
|
||||||
|
{'SKIP': 'skipme'},
|
||||||
|
)
|
||||||
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
def test_hook_id_not_in_non_verbose_output(
|
def test_hook_id_not_in_non_verbose_output(
|
||||||
cap_out, store, repo_with_passing_hook,
|
cap_out, store, repo_with_passing_hook,
|
||||||
):
|
):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue