mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #977 from asottile/minimum_pre_commit_version
Add top level minimum_pre_commit_version
This commit is contained in:
commit
06d01c8c9d
2 changed files with 37 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ from identify.identify import ALL_TAGS
|
|||
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_type_tag(tag):
|
|||
)
|
||||
|
||||
|
||||
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 @@ CONFIG_SCHEMA = cfgv.Map(
|
|||
),
|
||||
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',
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||
import cfgv
|
||||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.clientlib import check_type_tag
|
||||
from pre_commit.clientlib import CONFIG_HOOK_DICT
|
||||
from pre_commit.clientlib import CONFIG_REPO_DICT
|
||||
|
|
@ -234,3 +235,23 @@ def test_meta_hook_invalid(config_repo):
|
|||
def test_default_language_version_invalid(mapping):
|
||||
with pytest.raises(cfgv.ValidationError):
|
||||
cfgv.validate(mapping, DEFAULT_LANGUAGE_VERSION)
|
||||
|
||||
|
||||
def test_minimum_pre_commit_version_failing():
|
||||
with pytest.raises(cfgv.ValidationError) as excinfo:
|
||||
cfg = {'repos': [], 'minimum_pre_commit_version': '999'}
|
||||
cfgv.validate(cfg, CONFIG_SCHEMA)
|
||||
assert str(excinfo.value) == (
|
||||
'\n'
|
||||
'==> At Config()\n'
|
||||
'==> At key: minimum_pre_commit_version\n'
|
||||
'=====> pre-commit version 999 is required but version {} is '
|
||||
'installed. Perhaps run `pip install --upgrade pre-commit`.'.format(
|
||||
C.VERSION,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_minimum_pre_commit_version_passing():
|
||||
cfg = {'repos': [], 'minimum_pre_commit_version': '0'}
|
||||
cfgv.validate(cfg, CONFIG_SCHEMA)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue