Skip to content

Commit 7f18926

Browse files
authored
Merge pull request #2362 from pre-commit/deprecate-separate-entry-points
deprecate pre-commit-validate-{config,manifest}
2 parents e1ce4c0 + 3929fe4 commit 7f18926

File tree

10 files changed

+93
-26
lines changed

10 files changed

+93
-26
lines changed

.pre-commit-hooks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- id: validate_manifest
22
name: validate pre-commit manifest
33
description: This validator validates a pre-commit hooks manifest file
4-
entry: pre-commit-validate-manifest
4+
entry: pre-commit validate-manifest
55
language: python
6-
files: ^(\.pre-commit-hooks\.yaml|hooks\.yaml)$
6+
files: ^\.pre-commit-hooks\.yaml$

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resources:
1010
type: github
1111
endpoint: github
1212
name: asottile/azure-pipeline-templates
13-
ref: refs/tags/v2.1.0
13+
ref: refs/tags/v2.4.1
1414

1515
jobs:
1616
- template: job--python-tox.yml@asottile

pre_commit/clientlib.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import pre_commit.constants as C
1616
from pre_commit.color import add_color_option
17+
from pre_commit.commands.validate_config import validate_config
18+
from pre_commit.commands.validate_manifest import validate_manifest
1719
from pre_commit.errors import FatalError
1820
from pre_commit.languages.all import all_languages
1921
from pre_commit.logging_handler import logging_handler
@@ -100,14 +102,12 @@ def validate_manifest_main(argv: Sequence[str] | None = None) -> int:
100102
args = parser.parse_args(argv)
101103

102104
with logging_handler(args.color):
103-
ret = 0
104-
for filename in args.filenames:
105-
try:
106-
load_manifest(filename)
107-
except InvalidManifestError as e:
108-
print(e)
109-
ret = 1
110-
return ret
105+
logger.warning(
106+
'pre-commit-validate-manifest is deprecated -- '
107+
'use `pre-commit validate-manifest` instead.',
108+
)
109+
110+
return validate_manifest(args.filenames)
111111

112112

113113
LOCAL = 'local'
@@ -409,11 +409,9 @@ def validate_config_main(argv: Sequence[str] | None = None) -> int:
409409
args = parser.parse_args(argv)
410410

411411
with logging_handler(args.color):
412-
ret = 0
413-
for filename in args.filenames:
414-
try:
415-
load_config(filename)
416-
except InvalidConfigError as e:
417-
print(e)
418-
ret = 1
419-
return ret
412+
logger.warning(
413+
'pre-commit-validate-config is deprecated -- '
414+
'use `pre-commit validate-config` instead.',
415+
)
416+
417+
return validate_config(args.filenames)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from __future__ import annotations
2+
3+
from pre_commit import clientlib
4+
5+
6+
def validate_config(filenames: list[str]) -> int:
7+
ret = 0
8+
9+
for filename in filenames:
10+
try:
11+
clientlib.load_config(filename)
12+
except clientlib.InvalidConfigError as e:
13+
print(e)
14+
ret = 1
15+
16+
return ret
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from __future__ import annotations
2+
3+
from pre_commit import clientlib
4+
5+
6+
def validate_manifest(filenames: list[str]) -> int:
7+
ret = 0
8+
9+
for filename in filenames:
10+
try:
11+
clientlib.load_manifest(filename)
12+
except clientlib.InvalidManifestError as e:
13+
print(e)
14+
ret = 1
15+
16+
return ret

pre_commit/main.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from pre_commit.commands.run import run
2222
from pre_commit.commands.sample_config import sample_config
2323
from pre_commit.commands.try_repo import try_repo
24+
from pre_commit.commands.validate_config import validate_config
25+
from pre_commit.commands.validate_manifest import validate_manifest
2426
from pre_commit.error_handler import error_handler
2527
from pre_commit.logging_handler import logging_handler
2628
from pre_commit.store import Store
@@ -34,8 +36,10 @@
3436
# pyvenv
3537
os.environ.pop('__PYVENV_LAUNCHER__', None)
3638

37-
38-
COMMANDS_NO_GIT = {'clean', 'gc', 'init-templatedir', 'sample-config'}
39+
COMMANDS_NO_GIT = {
40+
'clean', 'gc', 'init-templatedir', 'sample-config',
41+
'validate-config', 'validate-manifest',
42+
}
3943

4044

4145
def _add_config_option(parser: argparse.ArgumentParser) -> None:
@@ -304,6 +308,20 @@ def main(argv: Sequence[str] | None = None) -> int:
304308
_add_config_option(uninstall_parser)
305309
_add_hook_type_option(uninstall_parser)
306310

311+
validate_config_parser = subparsers.add_parser(
312+
'validate-config', help='Validate .pre-commit-config.yaml files',
313+
)
314+
add_color_option(validate_config_parser)
315+
_add_config_option(validate_config_parser)
316+
validate_config_parser.add_argument('filenames', nargs='*')
317+
318+
validate_manifest_parser = subparsers.add_parser(
319+
'validate-manifest', help='Validate .pre-commit-hooks.yaml files',
320+
)
321+
add_color_option(validate_manifest_parser)
322+
_add_config_option(validate_manifest_parser)
323+
validate_manifest_parser.add_argument('filenames', nargs='*')
324+
307325
help = subparsers.add_parser(
308326
'help', help='Show help for a specific command.',
309327
)
@@ -378,6 +396,10 @@ def main(argv: Sequence[str] | None = None) -> int:
378396
config_file=args.config,
379397
hook_types=args.hook_types,
380398
)
399+
elif args.command == 'validate-config':
400+
return validate_config(args.filenames)
401+
elif args.command == 'validate-manifest':
402+
return validate_manifest(args.filenames)
381403
else:
382404
raise NotImplementedError(
383405
f'Command {args.command} not implemented.',

testing/get-swift.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
set -euo pipefail
44

55
. /etc/lsb-release
6-
if [ "$DISTRIB_CODENAME" = "bionic" ]; then
7-
SWIFT_URL='https://swift.org/builds/swift-5.1.3-release/ubuntu1804/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu18.04.tar.gz'
8-
SWIFT_HASH='ac82ccd773fe3d586fc340814e31e120da1ff695c6a712f6634e9cc720769610'
6+
if [ "$DISTRIB_CODENAME" = "focal" ]; then
7+
SWIFT_URL='https://download.swift.org/swift-5.6.1-release/ubuntu2004/swift-5.6.1-RELEASE/swift-5.6.1-RELEASE-ubuntu20.04.tar.gz'
8+
SWIFT_HASH='2b4f22d4a8b59fe8e050f0b7f020f8d8f12553cbda56709b2340a4a3bb90cfea'
99
else
1010
echo "unknown dist: ${DISTRIB_CODENAME}" 1>&2
1111
exit 1

tests/clientlib_test.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def test_validate_config_old_list_format_ok(tmpdir, cap_out):
122122
f = tmpdir.join('cfg.yaml')
123123
f.write('- {repo: meta, hooks: [{id: identity}]}')
124124
assert not validate_config_main((f.strpath,))
125-
start = '[WARNING] normalizing pre-commit configuration to a top-level map'
126-
assert cap_out.get().startswith(start)
125+
msg = '[WARNING] normalizing pre-commit configuration to a top-level map'
126+
assert msg in cap_out.get()
127127

128128

129129
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):
139139
ret_val = validate_config_main((f.strpath,))
140140
assert not ret_val
141141
assert caplog.record_tuples == [
142+
(
143+
'pre_commit',
144+
logging.WARNING,
145+
'pre-commit-validate-config is deprecated -- '
146+
'use `pre-commit validate-config` instead.',
147+
),
142148
(
143149
'pre_commit',
144150
logging.WARNING,
@@ -162,6 +168,12 @@ def test_validate_warn_on_unknown_keys_at_top_level(tmpdir, caplog):
162168
ret_val = validate_config_main((f.strpath,))
163169
assert not ret_val
164170
assert caplog.record_tuples == [
171+
(
172+
'pre_commit',
173+
logging.WARNING,
174+
'pre-commit-validate-config is deprecated -- '
175+
'use `pre-commit validate-config` instead.',
176+
),
165177
(
166178
'pre_commit',
167179
logging.WARNING,

tests/main_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_adjust_args_try_repo_repo_relative(in_git_dir):
7979
FNS = (
8080
'autoupdate', 'clean', 'gc', 'hook_impl', 'install', 'install_hooks',
8181
'migrate_config', 'run', 'sample_config', 'uninstall',
82+
'validate_config', 'validate_manifest',
8283
)
8384
CMDS = tuple(fn.replace('_', '-') for fn in FNS)
8485

tests/repository_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def test_python_venv(tempdir_factory, store):
173173
)
174174

175175

176+
@xfailif_windows # pragma: win32 no cover # no python 2 in GHA
176177
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
177178
# We're using the python3 repo because it prints the python version
178179
path = make_repo(tempdir_factory, 'python3_hooks_repo')
@@ -892,6 +893,7 @@ def test_local_python_repo(store, local_python_config):
892893
assert _norm_out(out) == b"3\n['filename']\nHello World\n"
893894

894895

896+
@xfailif_windows # pragma: win32 no cover # no python2 in GHA
895897
def test_local_python_repo_python2(store, local_python_config):
896898
local_python_config['hooks'][0]['language_version'] = 'python2'
897899
hook = _get_hook(local_python_config, store, 'python3-hook')

0 commit comments

Comments
 (0)