We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`minimum_pre_commit_version` at the top level in configuration
Similar to the one that's currently allowed on individual hooks, allow this at the top level of the `.pre-commit-config.yaml`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/clientlib.py`
Content:
```
1 from __future__ import absolute_import
2 from __future__ import unicode_literals
3 
4 import argparse
5 import functools
6 import pipes
7 import sys
8 
9 import cfgv
10 from aspy.yaml import ordered_load
11 from identify.identify import ALL_TAGS
12 
13 import pre_commit.constants as C
14 from pre_commit.error_handler import FatalError
15 from pre_commit.languages.all import all_languages
16 
17 
18 def check_type_tag(tag):
19     if tag not in ALL_TAGS:
20         raise cfgv.ValidationError(
21             'Type tag {!r} is not recognized.  '
22             'Try upgrading identify and pre-commit?'.format(tag),
23         )
24 
25 
26 def _make_argparser(filenames_help):
27     parser = argparse.ArgumentParser()
28     parser.add_argument('filenames', nargs='*', help=filenames_help)
29     parser.add_argument('-V', '--version', action='version', version=C.VERSION)
30     return parser
31 
32 
33 MANIFEST_HOOK_DICT = cfgv.Map(
34     'Hook', 'id',
35 
36     cfgv.Required('id', cfgv.check_string),
37     cfgv.Required('name', cfgv.check_string),
38     cfgv.Required('entry', cfgv.check_string),
39     cfgv.Required('language', cfgv.check_one_of(all_languages)),
40     cfgv.Optional('alias', cfgv.check_string, ''),
41 
42     cfgv.Optional(
43         'files', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '',
44     ),
45     cfgv.Optional(
46         'exclude', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '^$',
47     ),
48     cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),
49     cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),
50 
51     cfgv.Optional(
52         'additional_dependencies', cfgv.check_array(cfgv.check_string), [],
53     ),
54     cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),
55     cfgv.Optional('always_run', cfgv.check_bool, False),
56     cfgv.Optional('pass_filenames', cfgv.check_bool, True),
57     cfgv.Optional('description', cfgv.check_string, ''),
58     cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),
59     cfgv.Optional('log_file', cfgv.check_string, ''),
60     cfgv.Optional('minimum_pre_commit_version', cfgv.check_string, '0'),
61     cfgv.Optional('require_serial', cfgv.check_bool, False),
62     cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),
63     cfgv.Optional('verbose', cfgv.check_bool, False),
64 )
65 MANIFEST_SCHEMA = cfgv.Array(MANIFEST_HOOK_DICT)
66 
67 
68 class InvalidManifestError(FatalError):
69     pass
70 
71 
72 load_manifest = functools.partial(
73     cfgv.load_from_filename,
74     schema=MANIFEST_SCHEMA,
75     load_strategy=ordered_load,
76     exc_tp=InvalidManifestError,
77 )
78 
79 
80 def validate_manifest_main(argv=None):
81     parser = _make_argparser('Manifest filenames.')
82     args = parser.parse_args(argv)
83     ret = 0
84     for filename in args.filenames:
85         try:
86             load_manifest(filename)
87         except InvalidManifestError as e:
88             print(e)
89             ret = 1
90     return ret
91 
92 
93 LOCAL = 'local'
94 META = 'meta'
95 
96 
97 class MigrateShaToRev(object):
98     @staticmethod
99     def _cond(key):
100         return cfgv.Conditional(
101             key, cfgv.check_string,
102             condition_key='repo',
103             condition_value=cfgv.NotIn(LOCAL, META),
104             ensure_absent=True,
105         )
106 
107     def check(self, dct):
108         if dct.get('repo') in {LOCAL, META}:
109             self._cond('rev').check(dct)
110             self._cond('sha').check(dct)
111         elif 'sha' in dct and 'rev' in dct:
112             raise cfgv.ValidationError('Cannot specify both sha and rev')
113         elif 'sha' in dct:
114             self._cond('sha').check(dct)
115         else:
116             self._cond('rev').check(dct)
117 
118     def apply_default(self, dct):
119         if 'sha' in dct:
120             dct['rev'] = dct.pop('sha')
121 
122     def remove_default(self, dct):
123         pass
124 
125 
126 def _entry(modname):
127     """the hook `entry` is passed through `shlex.split()` by the command
128     runner, so to prevent issues with spaces and backslashes (on Windows)
129     it must be quoted here.
130     """
131     return '{} -m pre_commit.meta_hooks.{}'.format(
132         pipes.quote(sys.executable), modname,
133     )
134 
135 
136 _meta = (
137     (
138         'check-hooks-apply', (
139             ('name', 'Check hooks apply to the repository'),
140             ('files', C.CONFIG_FILE),
141             ('entry', _entry('check_hooks_apply')),
142         ),
143     ),
144     (
145         'check-useless-excludes', (
146             ('name', 'Check for useless excludes'),
147             ('files', C.CONFIG_FILE),
148             ('entry', _entry('check_useless_excludes')),
149         ),
150     ),
151     (
152         'identity', (
153             ('name', 'identity'),
154             ('verbose', True),
155             ('entry', _entry('identity')),
156         ),
157     ),
158 )
159 
160 META_HOOK_DICT = cfgv.Map(
161     'Hook', 'id',
162     cfgv.Required('id', cfgv.check_string),
163     cfgv.Required('id', cfgv.check_one_of(tuple(k for k, _ in _meta))),
164     # language must be system
165     cfgv.Optional('language', cfgv.check_one_of({'system'}), 'system'),
166     *([
167         # default to the hook definition for the meta hooks
168         cfgv.ConditionalOptional(key, cfgv.check_any, value, 'id', hook_id)
169         for hook_id, values in _meta
170         for key, value in values
171     ] + [
172         # default to the "manifest" parsing
173         cfgv.OptionalNoDefault(item.key, item.check_fn)
174         # these will always be defaulted above
175         if item.key in {'name', 'language', 'entry'} else
176         item
177         for item in MANIFEST_HOOK_DICT.items
178     ])
179 )
180 CONFIG_HOOK_DICT = cfgv.Map(
181     'Hook', 'id',
182 
183     cfgv.Required('id', cfgv.check_string),
184 
185     # All keys in manifest hook dict are valid in a config hook dict, but
186     # are optional.
187     # No defaults are provided here as the config is merged on top of the
188     # manifest.
189     *[
190         cfgv.OptionalNoDefault(item.key, item.check_fn)
191         for item in MANIFEST_HOOK_DICT.items
192         if item.key != 'id'
193     ]
194 )
195 CONFIG_REPO_DICT = cfgv.Map(
196     'Repository', 'repo',
197 
198     cfgv.Required('repo', cfgv.check_string),
199 
200     cfgv.ConditionalRecurse(
201         'hooks', cfgv.Array(CONFIG_HOOK_DICT),
202         'repo', cfgv.NotIn(LOCAL, META),
203     ),
204     cfgv.ConditionalRecurse(
205         'hooks', cfgv.Array(MANIFEST_HOOK_DICT),
206         'repo', LOCAL,
207     ),
208     cfgv.ConditionalRecurse(
209         'hooks', cfgv.Array(META_HOOK_DICT),
210         'repo', META,
211     ),
212 
213     MigrateShaToRev(),
214 )
215 DEFAULT_LANGUAGE_VERSION = cfgv.Map(
216     'DefaultLanguageVersion', None,
217     cfgv.NoAdditionalKeys(all_languages),
218     *[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages]
219 )
220 CONFIG_SCHEMA = cfgv.Map(
221     'Config', None,
222 
223     cfgv.RequiredRecurse('repos', cfgv.Array(CONFIG_REPO_DICT)),
224     cfgv.OptionalRecurse(
225         'default_language_version', DEFAULT_LANGUAGE_VERSION, {},
226     ),
227     cfgv.Optional(
228         'default_stages',
229         cfgv.check_array(cfgv.check_one_of(C.STAGES)),
230         C.STAGES,
231     ),
232     cfgv.Optional('exclude', cfgv.check_regex, '^$'),
233     cfgv.Optional('fail_fast', cfgv.check_bool, False),
234 )
235 
236 
237 class InvalidConfigError(FatalError):
238     pass
239 
240 
241 def ordered_load_normalize_legacy_config(contents):
242     data = ordered_load(contents)
243     if isinstance(data, list):
244         # TODO: Once happy, issue a deprecation warning and instructions
245         return {'repos': data}
246     else:
247         return data
248 
249 
250 load_config = functools.partial(
251     cfgv.load_from_filename,
252     schema=CONFIG_SCHEMA,
253     load_strategy=ordered_load_normalize_legacy_config,
254     exc_tp=InvalidConfigError,
255 )
256 
257 
258 def validate_config_main(argv=None):
259     parser = _make_argparser('Config filenames.')
260     args = parser.parse_args(argv)
261     ret = 0
262     for filename in args.filenames:
263         try:
264             load_config(filename)
265         except InvalidConfigError as e:
266             print(e)
267             ret = 1
268     return ret
269
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py
--- a/pre_commit/clientlib.py
+++ b/pre_commit/clientlib.py
@@ -13,6 +13,7 @@
 import pre_commit.constants as C
 from pre_commit.error_handler import FatalError
 from pre_commit.languages.all import all_languages
+from pre_commit.util import parse_version
 
 
 def check_type_tag(tag):
@@ -23,6 +24,16 @@
         )
 
 
+def check_min_version(version):
+    if parse_version(version) > parse_version(C.VERSION):
+        raise cfgv.ValidationError(
+            'pre-commit version {} is required but version {} is installed.  '
+            'Perhaps run `pip install --upgrade pre-commit`.'.format(
+                version, C.VERSION,
+            ),
+        )
+
+
 def _make_argparser(filenames_help):
     parser = argparse.ArgumentParser()
     parser.add_argument('filenames', nargs='*', help=filenames_help)
@@ -231,6 +242,11 @@
     ),
     cfgv.Optional('exclude', cfgv.check_regex, '^$'),
     cfgv.Optional('fail_fast', cfgv.check_bool, False),
+    cfgv.Optional(
+        'minimum_pre_commit_version',
+        cfgv.check_and(cfgv.check_string, check_min_version),
+        '0',
+    ),
 )

{"golden_diff": "diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py\n--- a/pre_commit/clientlib.py\n+++ b/pre_commit/clientlib.py\n@@ -13,6 +13,7 @@\n import pre_commit.constants as C\n from pre_commit.error_handler import FatalError\n from pre_commit.languages.all import all_languages\n+from pre_commit.util import parse_version\n \n \n def check_type_tag(tag):\n@@ -23,6 +24,16 @@\n         )\n \n \n+def check_min_version(version):\n+    if parse_version(version) > parse_version(C.VERSION):\n+        raise cfgv.ValidationError(\n+            'pre-commit version {} is required but version {} is installed.  '\n+            'Perhaps run `pip install --upgrade pre-commit`.'.format(\n+                version, C.VERSION,\n+            ),\n+        )\n+\n+\n def _make_argparser(filenames_help):\n     parser = argparse.ArgumentParser()\n     parser.add_argument('filenames', nargs='*', help=filenames_help)\n@@ -231,6 +242,11 @@\n     ),\n     cfgv.Optional('exclude', cfgv.check_regex, '^$'),\n     cfgv.Optional('fail_fast', cfgv.check_bool, False),\n+    cfgv.Optional(\n+        'minimum_pre_commit_version',\n+        cfgv.check_and(cfgv.check_string, check_min_version),\n+        '0',\n+    ),\n )\n", "issue": "`minimum_pre_commit_version` at the top level in configuration\nSimilar to the one that's currently allowed on individual hooks, allow this at the top level of the `.pre-commit-config.yaml`\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import unicode_literals\n\nimport argparse\nimport functools\nimport pipes\nimport sys\n\nimport cfgv\nfrom aspy.yaml import ordered_load\nfrom identify.identify import ALL_TAGS\n\nimport pre_commit.constants as C\nfrom pre_commit.error_handler import FatalError\nfrom pre_commit.languages.all import all_languages\n\n\ndef check_type_tag(tag):\n    if tag not in ALL_TAGS:\n        raise cfgv.ValidationError(\n            'Type tag {!r} is not recognized.  '\n            'Try upgrading identify and pre-commit?'.format(tag),\n        )\n\n\ndef _make_argparser(filenames_help):\n    parser = argparse.ArgumentParser()\n    parser.add_argument('filenames', nargs='*', help=filenames_help)\n    parser.add_argument('-V', '--version', action='version', version=C.VERSION)\n    return parser\n\n\nMANIFEST_HOOK_DICT = cfgv.Map(\n    'Hook', 'id',\n\n    cfgv.Required('id', cfgv.check_string),\n    cfgv.Required('name', cfgv.check_string),\n    cfgv.Required('entry', cfgv.check_string),\n    cfgv.Required('language', cfgv.check_one_of(all_languages)),\n    cfgv.Optional('alias', cfgv.check_string, ''),\n\n    cfgv.Optional(\n        'files', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '',\n    ),\n    cfgv.Optional(\n        'exclude', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '^$',\n    ),\n    cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),\n    cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),\n\n    cfgv.Optional(\n        'additional_dependencies', cfgv.check_array(cfgv.check_string), [],\n    ),\n    cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),\n    cfgv.Optional('always_run', cfgv.check_bool, False),\n    cfgv.Optional('pass_filenames', cfgv.check_bool, True),\n    cfgv.Optional('description', cfgv.check_string, ''),\n    cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),\n    cfgv.Optional('log_file', cfgv.check_string, ''),\n    cfgv.Optional('minimum_pre_commit_version', cfgv.check_string, '0'),\n    cfgv.Optional('require_serial', cfgv.check_bool, False),\n    cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),\n    cfgv.Optional('verbose', cfgv.check_bool, False),\n)\nMANIFEST_SCHEMA = cfgv.Array(MANIFEST_HOOK_DICT)\n\n\nclass InvalidManifestError(FatalError):\n    pass\n\n\nload_manifest = functools.partial(\n    cfgv.load_from_filename,\n    schema=MANIFEST_SCHEMA,\n    load_strategy=ordered_load,\n    exc_tp=InvalidManifestError,\n)\n\n\ndef validate_manifest_main(argv=None):\n    parser = _make_argparser('Manifest filenames.')\n    args = parser.parse_args(argv)\n    ret = 0\n    for filename in args.filenames:\n        try:\n            load_manifest(filename)\n        except InvalidManifestError as e:\n            print(e)\n            ret = 1\n    return ret\n\n\nLOCAL = 'local'\nMETA = 'meta'\n\n\nclass MigrateShaToRev(object):\n    @staticmethod\n    def _cond(key):\n        return cfgv.Conditional(\n            key, cfgv.check_string,\n            condition_key='repo',\n            condition_value=cfgv.NotIn(LOCAL, META),\n            ensure_absent=True,\n        )\n\n    def check(self, dct):\n        if dct.get('repo') in {LOCAL, META}:\n            self._cond('rev').check(dct)\n            self._cond('sha').check(dct)\n        elif 'sha' in dct and 'rev' in dct:\n            raise cfgv.ValidationError('Cannot specify both sha and rev')\n        elif 'sha' in dct:\n            self._cond('sha').check(dct)\n        else:\n            self._cond('rev').check(dct)\n\n    def apply_default(self, dct):\n        if 'sha' in dct:\n            dct['rev'] = dct.pop('sha')\n\n    def remove_default(self, dct):\n        pass\n\n\ndef _entry(modname):\n    \"\"\"the hook `entry` is passed through `shlex.split()` by the command\n    runner, so to prevent issues with spaces and backslashes (on Windows)\n    it must be quoted here.\n    \"\"\"\n    return '{} -m pre_commit.meta_hooks.{}'.format(\n        pipes.quote(sys.executable), modname,\n    )\n\n\n_meta = (\n    (\n        'check-hooks-apply', (\n            ('name', 'Check hooks apply to the repository'),\n            ('files', C.CONFIG_FILE),\n            ('entry', _entry('check_hooks_apply')),\n        ),\n    ),\n    (\n        'check-useless-excludes', (\n            ('name', 'Check for useless excludes'),\n            ('files', C.CONFIG_FILE),\n            ('entry', _entry('check_useless_excludes')),\n        ),\n    ),\n    (\n        'identity', (\n            ('name', 'identity'),\n            ('verbose', True),\n            ('entry', _entry('identity')),\n        ),\n    ),\n)\n\nMETA_HOOK_DICT = cfgv.Map(\n    'Hook', 'id',\n    cfgv.Required('id', cfgv.check_string),\n    cfgv.Required('id', cfgv.check_one_of(tuple(k for k, _ in _meta))),\n    # language must be system\n    cfgv.Optional('language', cfgv.check_one_of({'system'}), 'system'),\n    *([\n        # default to the hook definition for the meta hooks\n        cfgv.ConditionalOptional(key, cfgv.check_any, value, 'id', hook_id)\n        for hook_id, values in _meta\n        for key, value in values\n    ] + [\n        # default to the \"manifest\" parsing\n        cfgv.OptionalNoDefault(item.key, item.check_fn)\n        # these will always be defaulted above\n        if item.key in {'name', 'language', 'entry'} else\n        item\n        for item in MANIFEST_HOOK_DICT.items\n    ])\n)\nCONFIG_HOOK_DICT = cfgv.Map(\n    'Hook', 'id',\n\n    cfgv.Required('id', cfgv.check_string),\n\n    # All keys in manifest hook dict are valid in a config hook dict, but\n    # are optional.\n    # No defaults are provided here as the config is merged on top of the\n    # manifest.\n    *[\n        cfgv.OptionalNoDefault(item.key, item.check_fn)\n        for item in MANIFEST_HOOK_DICT.items\n        if item.key != 'id'\n    ]\n)\nCONFIG_REPO_DICT = cfgv.Map(\n    'Repository', 'repo',\n\n    cfgv.Required('repo', cfgv.check_string),\n\n    cfgv.ConditionalRecurse(\n        'hooks', cfgv.Array(CONFIG_HOOK_DICT),\n        'repo', cfgv.NotIn(LOCAL, META),\n    ),\n    cfgv.ConditionalRecurse(\n        'hooks', cfgv.Array(MANIFEST_HOOK_DICT),\n        'repo', LOCAL,\n    ),\n    cfgv.ConditionalRecurse(\n        'hooks', cfgv.Array(META_HOOK_DICT),\n        'repo', META,\n    ),\n\n    MigrateShaToRev(),\n)\nDEFAULT_LANGUAGE_VERSION = cfgv.Map(\n    'DefaultLanguageVersion', None,\n    cfgv.NoAdditionalKeys(all_languages),\n    *[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages]\n)\nCONFIG_SCHEMA = cfgv.Map(\n    'Config', None,\n\n    cfgv.RequiredRecurse('repos', cfgv.Array(CONFIG_REPO_DICT)),\n    cfgv.OptionalRecurse(\n        'default_language_version', DEFAULT_LANGUAGE_VERSION, {},\n    ),\n    cfgv.Optional(\n        'default_stages',\n        cfgv.check_array(cfgv.check_one_of(C.STAGES)),\n        C.STAGES,\n    ),\n    cfgv.Optional('exclude', cfgv.check_regex, '^$'),\n    cfgv.Optional('fail_fast', cfgv.check_bool, False),\n)\n\n\nclass InvalidConfigError(FatalError):\n    pass\n\n\ndef ordered_load_normalize_legacy_config(contents):\n    data = ordered_load(contents)\n    if isinstance(data, list):\n        # TODO: Once happy, issue a deprecation warning and instructions\n        return {'repos': data}\n    else:\n        return data\n\n\nload_config = functools.partial(\n    cfgv.load_from_filename,\n    schema=CONFIG_SCHEMA,\n    load_strategy=ordered_load_normalize_legacy_config,\n    exc_tp=InvalidConfigError,\n)\n\n\ndef validate_config_main(argv=None):\n    parser = _make_argparser('Config filenames.')\n    args = parser.parse_args(argv)\n    ret = 0\n    for filename in args.filenames:\n        try:\n            load_config(filename)\n        except InvalidConfigError as e:\n            print(e)\n            ret = 1\n    return ret\n", "path": "pre_commit/clientlib.py"}], "after_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import unicode_literals\n\nimport argparse\nimport functools\nimport pipes\nimport sys\n\nimport cfgv\nfrom aspy.yaml import ordered_load\nfrom identify.identify import ALL_TAGS\n\nimport pre_commit.constants as C\nfrom pre_commit.error_handler import FatalError\nfrom pre_commit.languages.all import all_languages\nfrom pre_commit.util import parse_version\n\n\ndef check_type_tag(tag):\n    if tag not in ALL_TAGS:\n        raise cfgv.ValidationError(\n            'Type tag {!r} is not recognized.  '\n            'Try upgrading identify and pre-commit?'.format(tag),\n        )\n\n\ndef check_min_version(version):\n    if parse_version(version) > parse_version(C.VERSION):\n        raise cfgv.ValidationError(\n            'pre-commit version {} is required but version {} is installed.  '\n            'Perhaps run `pip install --upgrade pre-commit`.'.format(\n                version, C.VERSION,\n            ),\n        )\n\n\ndef _make_argparser(filenames_help):\n    parser = argparse.ArgumentParser()\n    parser.add_argument('filenames', nargs='*', help=filenames_help)\n    parser.add_argument('-V', '--version', action='version', version=C.VERSION)\n    return parser\n\n\nMANIFEST_HOOK_DICT = cfgv.Map(\n    'Hook', 'id',\n\n    cfgv.Required('id', cfgv.check_string),\n    cfgv.Required('name', cfgv.check_string),\n    cfgv.Required('entry', cfgv.check_string),\n    cfgv.Required('language', cfgv.check_one_of(all_languages)),\n    cfgv.Optional('alias', cfgv.check_string, ''),\n\n    cfgv.Optional(\n        'files', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '',\n    ),\n    cfgv.Optional(\n        'exclude', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '^$',\n    ),\n    cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),\n    cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),\n\n    cfgv.Optional(\n        'additional_dependencies', cfgv.check_array(cfgv.check_string), [],\n    ),\n    cfgv.Optional('args', cfgv.check_array(cfgv.check_string), []),\n    cfgv.Optional('always_run', cfgv.check_bool, False),\n    cfgv.Optional('pass_filenames', cfgv.check_bool, True),\n    cfgv.Optional('description', cfgv.check_string, ''),\n    cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),\n    cfgv.Optional('log_file', cfgv.check_string, ''),\n    cfgv.Optional('minimum_pre_commit_version', cfgv.check_string, '0'),\n    cfgv.Optional('require_serial', cfgv.check_bool, False),\n    cfgv.Optional('stages', cfgv.check_array(cfgv.check_one_of(C.STAGES)), []),\n    cfgv.Optional('verbose', cfgv.check_bool, False),\n)\nMANIFEST_SCHEMA = cfgv.Array(MANIFEST_HOOK_DICT)\n\n\nclass InvalidManifestError(FatalError):\n    pass\n\n\nload_manifest = functools.partial(\n    cfgv.load_from_filename,\n    schema=MANIFEST_SCHEMA,\n    load_strategy=ordered_load,\n    exc_tp=InvalidManifestError,\n)\n\n\ndef validate_manifest_main(argv=None):\n    parser = _make_argparser('Manifest filenames.')\n    args = parser.parse_args(argv)\n    ret = 0\n    for filename in args.filenames:\n        try:\n            load_manifest(filename)\n        except InvalidManifestError as e:\n            print(e)\n            ret = 1\n    return ret\n\n\nLOCAL = 'local'\nMETA = 'meta'\n\n\nclass MigrateShaToRev(object):\n    @staticmethod\n    def _cond(key):\n        return cfgv.Conditional(\n            key, cfgv.check_string,\n            condition_key='repo',\n            condition_value=cfgv.NotIn(LOCAL, META),\n            ensure_absent=True,\n        )\n\n    def check(self, dct):\n        if dct.get('repo') in {LOCAL, META}:\n            self._cond('rev').check(dct)\n            self._cond('sha').check(dct)\n        elif 'sha' in dct and 'rev' in dct:\n            raise cfgv.ValidationError('Cannot specify both sha and rev')\n        elif 'sha' in dct:\n            self._cond('sha').check(dct)\n        else:\n            self._cond('rev').check(dct)\n\n    def apply_default(self, dct):\n        if 'sha' in dct:\n            dct['rev'] = dct.pop('sha')\n\n    def remove_default(self, dct):\n        pass\n\n\ndef _entry(modname):\n    \"\"\"the hook `entry` is passed through `shlex.split()` by the command\n    runner, so to prevent issues with spaces and backslashes (on Windows)\n    it must be quoted here.\n    \"\"\"\n    return '{} -m pre_commit.meta_hooks.{}'.format(\n        pipes.quote(sys.executable), modname,\n    )\n\n\n_meta = (\n    (\n        'check-hooks-apply', (\n            ('name', 'Check hooks apply to the repository'),\n            ('files', C.CONFIG_FILE),\n            ('entry', _entry('check_hooks_apply')),\n        ),\n    ),\n    (\n        'check-useless-excludes', (\n            ('name', 'Check for useless excludes'),\n            ('files', C.CONFIG_FILE),\n            ('entry', _entry('check_useless_excludes')),\n        ),\n    ),\n    (\n        'identity', (\n            ('name', 'identity'),\n            ('verbose', True),\n            ('entry', _entry('identity')),\n        ),\n    ),\n)\n\nMETA_HOOK_DICT = cfgv.Map(\n    'Hook', 'id',\n    cfgv.Required('id', cfgv.check_string),\n    cfgv.Required('id', cfgv.check_one_of(tuple(k for k, _ in _meta))),\n    # language must be system\n    cfgv.Optional('language', cfgv.check_one_of({'system'}), 'system'),\n    *([\n        # default to the hook definition for the meta hooks\n        cfgv.ConditionalOptional(key, cfgv.check_any, value, 'id', hook_id)\n        for hook_id, values in _meta\n        for key, value in values\n    ] + [\n        # default to the \"manifest\" parsing\n        cfgv.OptionalNoDefault(item.key, item.check_fn)\n        # these will always be defaulted above\n        if item.key in {'name', 'language', 'entry'} else\n        item\n        for item in MANIFEST_HOOK_DICT.items\n    ])\n)\nCONFIG_HOOK_DICT = cfgv.Map(\n    'Hook', 'id',\n\n    cfgv.Required('id', cfgv.check_string),\n\n    # All keys in manifest hook dict are valid in a config hook dict, but\n    # are optional.\n    # No defaults are provided here as the config is merged on top of the\n    # manifest.\n    *[\n        cfgv.OptionalNoDefault(item.key, item.check_fn)\n        for item in MANIFEST_HOOK_DICT.items\n        if item.key != 'id'\n    ]\n)\nCONFIG_REPO_DICT = cfgv.Map(\n    'Repository', 'repo',\n\n    cfgv.Required('repo', cfgv.check_string),\n\n    cfgv.ConditionalRecurse(\n        'hooks', cfgv.Array(CONFIG_HOOK_DICT),\n        'repo', cfgv.NotIn(LOCAL, META),\n    ),\n    cfgv.ConditionalRecurse(\n        'hooks', cfgv.Array(MANIFEST_HOOK_DICT),\n        'repo', LOCAL,\n    ),\n    cfgv.ConditionalRecurse(\n        'hooks', cfgv.Array(META_HOOK_DICT),\n        'repo', META,\n    ),\n\n    MigrateShaToRev(),\n)\nDEFAULT_LANGUAGE_VERSION = cfgv.Map(\n    'DefaultLanguageVersion', None,\n    cfgv.NoAdditionalKeys(all_languages),\n    *[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages]\n)\nCONFIG_SCHEMA = cfgv.Map(\n    'Config', None,\n\n    cfgv.RequiredRecurse('repos', cfgv.Array(CONFIG_REPO_DICT)),\n    cfgv.OptionalRecurse(\n        'default_language_version', DEFAULT_LANGUAGE_VERSION, {},\n    ),\n    cfgv.Optional(\n        'default_stages',\n        cfgv.check_array(cfgv.check_one_of(C.STAGES)),\n        C.STAGES,\n    ),\n    cfgv.Optional('exclude', cfgv.check_regex, '^$'),\n    cfgv.Optional('fail_fast', cfgv.check_bool, False),\n    cfgv.Optional(\n        'minimum_pre_commit_version',\n        cfgv.check_and(cfgv.check_string, check_min_version),\n        '0',\n    ),\n)\n\n\nclass InvalidConfigError(FatalError):\n    pass\n\n\ndef ordered_load_normalize_legacy_config(contents):\n    data = ordered_load(contents)\n    if isinstance(data, list):\n        # TODO: Once happy, issue a deprecation warning and instructions\n        return {'repos': data}\n    else:\n        return data\n\n\nload_config = functools.partial(\n    cfgv.load_from_filename,\n    schema=CONFIG_SCHEMA,\n    load_strategy=ordered_load_normalize_legacy_config,\n    exc_tp=InvalidConfigError,\n)\n\n\ndef validate_config_main(argv=None):\n    parser = _make_argparser('Config filenames.')\n    args = parser.parse_args(argv)\n    ret = 0\n    for filename in args.filenames:\n        try:\n            load_config(filename)\n        except InvalidConfigError as e:\n            print(e)\n            ret = 1\n    return ret\n", "path": "pre_commit/clientlib.py"}]}