@@ -252,50 +252,56 @@ def _venvs(self):
252252
253253
254254class MetaRepository (LocalRepository ):
255- # Note: the hook `entry` is passed through `shlex.split()` by the command
256- # runner, so to prevent issues with spaces and backslashes (on Windows) it
257- # must be quoted here.
258- meta_hooks = {
259- 'check-useless-excludes' : {
260- 'name' : 'Check for useless excludes' ,
261- 'files' : '.pre-commit-config.yaml' ,
262- 'language' : 'system' ,
263- 'entry' : pipes .quote (sys .executable ),
264- 'args' : ['-m' , 'pre_commit.meta_hooks.check_useless_excludes' ],
265- },
266- 'check-files-matches-any' : {
267- 'name' : 'Check hooks match any files' ,
268- 'files' : '.pre-commit-config.yaml' ,
269- 'language' : 'system' ,
270- 'entry' : pipes .quote (sys .executable ),
271- 'args' : ['-m' , 'pre_commit.meta_hooks.check_files_matches_any' ],
272- },
273- }
255+ @cached_property
256+ def manifest_hooks (self ):
257+ # The hooks are imported here to prevent circular imports.
258+ from pre_commit .meta_hooks import check_files_matches_any
259+ from pre_commit .meta_hooks import check_useless_excludes
260+
261+ # Note: the hook `entry` is passed through `shlex.split()` by the
262+ # command runner, so to prevent issues with spaces and backslashes
263+ # (on Windows) it must be quoted here.
264+ meta_hooks = [
265+ {
266+ 'id' : 'check-useless-excludes' ,
267+ 'name' : 'Check for useless excludes' ,
268+ 'files' : '.pre-commit-config.yaml' ,
269+ 'language' : 'system' ,
270+ 'entry' : pipes .quote (sys .executable ),
271+ 'args' : ['-m' , check_useless_excludes .__name__ ],
272+ },
273+ {
274+ 'id' : 'check-files-matches-any' ,
275+ 'name' : 'Check hooks match any files' ,
276+ 'files' : '.pre-commit-config.yaml' ,
277+ 'language' : 'system' ,
278+ 'entry' : pipes .quote (sys .executable ),
279+ 'args' : ['-m' , check_files_matches_any .__name__ ],
280+ },
281+ ]
282+
283+ return {
284+ hook ['id' ]: apply_defaults (
285+ validate (hook , MANIFEST_HOOK_DICT ),
286+ MANIFEST_HOOK_DICT ,
287+ )
288+ for hook in meta_hooks
289+ }
274290
275291 @cached_property
276292 def hooks (self ):
277293 for hook in self .repo_config ['hooks' ]:
278- if hook ['id' ] not in self .meta_hooks :
294+ if hook ['id' ] not in self .manifest_hooks :
279295 logger .error (
280296 '`{}` is not a valid meta hook. '
281297 'Typo? Perhaps it is introduced in a newer version? '
282- 'Often `pre-commit autoupdate` fixes this.' .format (
283- hook ['id' ],
284- ),
298+ 'Often `pip install --upgrade pre-commit` fixes this.'
299+ .format (hook ['id' ]),
285300 )
286301 exit (1 )
287302
288303 return tuple (
289- (
290- hook ['id' ],
291- apply_defaults (
292- validate (
293- dict (self .meta_hooks [hook ['id' ]], ** hook ),
294- MANIFEST_HOOK_DICT ,
295- ),
296- MANIFEST_HOOK_DICT ,
297- ),
298- )
304+ (hook ['id' ], _hook (self .manifest_hooks [hook ['id' ]], hook ))
299305 for hook in self .repo_config ['hooks' ]
300306 )
301307
0 commit comments