mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
deprecate pre-commit-validate-{config,manifest}
This commit is contained in:
parent
e1ce4c0bf3
commit
777ffdd692
7 changed files with 87 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
- id: validate_manifest
|
- id: validate_manifest
|
||||||
name: validate pre-commit manifest
|
name: validate pre-commit manifest
|
||||||
description: This validator validates a pre-commit hooks manifest file
|
description: This validator validates a pre-commit hooks manifest file
|
||||||
entry: pre-commit-validate-manifest
|
entry: pre-commit validate-manifest
|
||||||
language: python
|
language: python
|
||||||
files: ^(\.pre-commit-hooks\.yaml|hooks\.yaml)$
|
files: ^\.pre-commit-hooks\.yaml$
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ from identify.identify import ALL_TAGS
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit.color import add_color_option
|
from pre_commit.color import add_color_option
|
||||||
|
from pre_commit.commands.validate_config import validate_config
|
||||||
|
from pre_commit.commands.validate_manifest import validate_manifest
|
||||||
from pre_commit.errors import FatalError
|
from pre_commit.errors import FatalError
|
||||||
from pre_commit.languages.all import all_languages
|
from pre_commit.languages.all import all_languages
|
||||||
from pre_commit.logging_handler import logging_handler
|
from pre_commit.logging_handler import logging_handler
|
||||||
|
|
@ -100,14 +102,12 @@ def validate_manifest_main(argv: Sequence[str] | None = None) -> int:
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
with logging_handler(args.color):
|
with logging_handler(args.color):
|
||||||
ret = 0
|
logger.warning(
|
||||||
for filename in args.filenames:
|
'pre-commit-validate-manifest is deprecated -- '
|
||||||
try:
|
'use `pre-commit validate-manifest` instead.',
|
||||||
load_manifest(filename)
|
)
|
||||||
except InvalidManifestError as e:
|
|
||||||
print(e)
|
return validate_manifest(args.filenames)
|
||||||
ret = 1
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL = 'local'
|
LOCAL = 'local'
|
||||||
|
|
@ -409,11 +409,9 @@ def validate_config_main(argv: Sequence[str] | None = None) -> int:
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
with logging_handler(args.color):
|
with logging_handler(args.color):
|
||||||
ret = 0
|
logger.warning(
|
||||||
for filename in args.filenames:
|
'pre-commit-validate-config is deprecated -- '
|
||||||
try:
|
'use `pre-commit validate-config` instead.',
|
||||||
load_config(filename)
|
)
|
||||||
except InvalidConfigError as e:
|
|
||||||
print(e)
|
return validate_config(args.filenames)
|
||||||
ret = 1
|
|
||||||
return ret
|
|
||||||
|
|
|
||||||
16
pre_commit/commands/validate_config.py
Normal file
16
pre_commit/commands/validate_config.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pre_commit import clientlib
|
||||||
|
|
||||||
|
|
||||||
|
def validate_config(filenames: list[str]) -> int:
|
||||||
|
ret = 0
|
||||||
|
|
||||||
|
for filename in filenames:
|
||||||
|
try:
|
||||||
|
clientlib.load_config(filename)
|
||||||
|
except clientlib.InvalidConfigError as e:
|
||||||
|
print(e)
|
||||||
|
ret = 1
|
||||||
|
|
||||||
|
return ret
|
||||||
16
pre_commit/commands/validate_manifest.py
Normal file
16
pre_commit/commands/validate_manifest.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pre_commit import clientlib
|
||||||
|
|
||||||
|
|
||||||
|
def validate_manifest(filenames: list[str]) -> int:
|
||||||
|
ret = 0
|
||||||
|
|
||||||
|
for filename in filenames:
|
||||||
|
try:
|
||||||
|
clientlib.load_manifest(filename)
|
||||||
|
except clientlib.InvalidManifestError as e:
|
||||||
|
print(e)
|
||||||
|
ret = 1
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
@ -21,6 +21,8 @@ from pre_commit.commands.migrate_config import migrate_config
|
||||||
from pre_commit.commands.run import run
|
from pre_commit.commands.run import run
|
||||||
from pre_commit.commands.sample_config import sample_config
|
from pre_commit.commands.sample_config import sample_config
|
||||||
from pre_commit.commands.try_repo import try_repo
|
from pre_commit.commands.try_repo import try_repo
|
||||||
|
from pre_commit.commands.validate_config import validate_config
|
||||||
|
from pre_commit.commands.validate_manifest import validate_manifest
|
||||||
from pre_commit.error_handler import error_handler
|
from pre_commit.error_handler import error_handler
|
||||||
from pre_commit.logging_handler import logging_handler
|
from pre_commit.logging_handler import logging_handler
|
||||||
from pre_commit.store import Store
|
from pre_commit.store import Store
|
||||||
|
|
@ -34,8 +36,10 @@ logger = logging.getLogger('pre_commit')
|
||||||
# pyvenv
|
# pyvenv
|
||||||
os.environ.pop('__PYVENV_LAUNCHER__', None)
|
os.environ.pop('__PYVENV_LAUNCHER__', None)
|
||||||
|
|
||||||
|
COMMANDS_NO_GIT = {
|
||||||
COMMANDS_NO_GIT = {'clean', 'gc', 'init-templatedir', 'sample-config'}
|
'clean', 'gc', 'init-templatedir', 'sample-config',
|
||||||
|
'validate-config', 'validate-manifest',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _add_config_option(parser: argparse.ArgumentParser) -> None:
|
def _add_config_option(parser: argparse.ArgumentParser) -> None:
|
||||||
|
|
@ -304,6 +308,20 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||||
_add_config_option(uninstall_parser)
|
_add_config_option(uninstall_parser)
|
||||||
_add_hook_type_option(uninstall_parser)
|
_add_hook_type_option(uninstall_parser)
|
||||||
|
|
||||||
|
validate_config_parser = subparsers.add_parser(
|
||||||
|
'validate-config', help='Validate .pre-commit-config.yaml files',
|
||||||
|
)
|
||||||
|
add_color_option(validate_config_parser)
|
||||||
|
_add_config_option(validate_config_parser)
|
||||||
|
validate_config_parser.add_argument('filenames', nargs='*')
|
||||||
|
|
||||||
|
validate_manifest_parser = subparsers.add_parser(
|
||||||
|
'validate-manifest', help='Validate .pre-commit-hooks.yaml files',
|
||||||
|
)
|
||||||
|
add_color_option(validate_manifest_parser)
|
||||||
|
_add_config_option(validate_manifest_parser)
|
||||||
|
validate_manifest_parser.add_argument('filenames', nargs='*')
|
||||||
|
|
||||||
help = subparsers.add_parser(
|
help = subparsers.add_parser(
|
||||||
'help', help='Show help for a specific command.',
|
'help', help='Show help for a specific command.',
|
||||||
)
|
)
|
||||||
|
|
@ -378,6 +396,10 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||||
config_file=args.config,
|
config_file=args.config,
|
||||||
hook_types=args.hook_types,
|
hook_types=args.hook_types,
|
||||||
)
|
)
|
||||||
|
elif args.command == 'validate-config':
|
||||||
|
return validate_config(args.filenames)
|
||||||
|
elif args.command == 'validate-manifest':
|
||||||
|
return validate_manifest(args.filenames)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
f'Command {args.command} not implemented.',
|
f'Command {args.command} not implemented.',
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,8 @@ def test_validate_config_old_list_format_ok(tmpdir, cap_out):
|
||||||
f = tmpdir.join('cfg.yaml')
|
f = tmpdir.join('cfg.yaml')
|
||||||
f.write('- {repo: meta, hooks: [{id: identity}]}')
|
f.write('- {repo: meta, hooks: [{id: identity}]}')
|
||||||
assert not validate_config_main((f.strpath,))
|
assert not validate_config_main((f.strpath,))
|
||||||
start = '[WARNING] normalizing pre-commit configuration to a top-level map'
|
msg = '[WARNING] normalizing pre-commit configuration to a top-level map'
|
||||||
assert cap_out.get().startswith(start)
|
assert msg in cap_out.get()
|
||||||
|
|
||||||
|
|
||||||
def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
||||||
|
|
@ -139,6 +139,12 @@ def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
||||||
ret_val = validate_config_main((f.strpath,))
|
ret_val = validate_config_main((f.strpath,))
|
||||||
assert not ret_val
|
assert not ret_val
|
||||||
assert caplog.record_tuples == [
|
assert caplog.record_tuples == [
|
||||||
|
(
|
||||||
|
'pre_commit',
|
||||||
|
logging.WARNING,
|
||||||
|
'pre-commit-validate-config is deprecated -- '
|
||||||
|
'use `pre-commit validate-config` instead.',
|
||||||
|
),
|
||||||
(
|
(
|
||||||
'pre_commit',
|
'pre_commit',
|
||||||
logging.WARNING,
|
logging.WARNING,
|
||||||
|
|
@ -162,6 +168,12 @@ def test_validate_warn_on_unknown_keys_at_top_level(tmpdir, caplog):
|
||||||
ret_val = validate_config_main((f.strpath,))
|
ret_val = validate_config_main((f.strpath,))
|
||||||
assert not ret_val
|
assert not ret_val
|
||||||
assert caplog.record_tuples == [
|
assert caplog.record_tuples == [
|
||||||
|
(
|
||||||
|
'pre_commit',
|
||||||
|
logging.WARNING,
|
||||||
|
'pre-commit-validate-config is deprecated -- '
|
||||||
|
'use `pre-commit validate-config` instead.',
|
||||||
|
),
|
||||||
(
|
(
|
||||||
'pre_commit',
|
'pre_commit',
|
||||||
logging.WARNING,
|
logging.WARNING,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ def test_adjust_args_try_repo_repo_relative(in_git_dir):
|
||||||
FNS = (
|
FNS = (
|
||||||
'autoupdate', 'clean', 'gc', 'hook_impl', 'install', 'install_hooks',
|
'autoupdate', 'clean', 'gc', 'hook_impl', 'install', 'install_hooks',
|
||||||
'migrate_config', 'run', 'sample_config', 'uninstall',
|
'migrate_config', 'run', 'sample_config', 'uninstall',
|
||||||
|
'validate_config', 'validate_manifest',
|
||||||
)
|
)
|
||||||
CMDS = tuple(fn.replace('_', '-') for fn in FNS)
|
CMDS = tuple(fn.replace('_', '-') for fn in FNS)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue