summaryrefslogtreecommitdiffstats
path: root/pre_commit/clientlib.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-08-30 11:22:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-08-30 11:22:53 +0000
commit6cfa8e0963e9a518a25528a248932fcf41b4f969 (patch)
tree6882a2a7a3214ef85d7a946f2506e9ed2c3f60f5 /pre_commit/clientlib.py
parentAdding upstream version 2.6.0. (diff)
downloadpre-commit-6cfa8e0963e9a518a25528a248932fcf41b4f969.tar.xz
pre-commit-6cfa8e0963e9a518a25528a248932fcf41b4f969.zip
Adding upstream version 2.7.1.upstream/2.7.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/clientlib.py')
-rw-r--r--pre_commit/clientlib.py45
1 files changed, 28 insertions, 17 deletions
diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py
index 56ec0dd..8dfa947 100644
--- a/pre_commit/clientlib.py
+++ b/pre_commit/clientlib.py
@@ -12,8 +12,10 @@ import cfgv
from identify.identify import ALL_TAGS
import pre_commit.constants as C
+from pre_commit.color import add_color_option
from pre_commit.error_handler import FatalError
from pre_commit.languages.all import all_languages
+from pre_commit.logging_handler import logging_handler
from pre_commit.util import parse_version
from pre_commit.util import yaml_load
@@ -43,6 +45,7 @@ def _make_argparser(filenames_help: str) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help=filenames_help)
parser.add_argument('-V', '--version', action='version', version=C.VERSION)
+ add_color_option(parser)
return parser
@@ -92,14 +95,16 @@ load_manifest = functools.partial(
def validate_manifest_main(argv: Optional[Sequence[str]] = None) -> int:
parser = _make_argparser('Manifest filenames.')
args = parser.parse_args(argv)
- ret = 0
- for filename in args.filenames:
- try:
- load_manifest(filename)
- except InvalidManifestError as e:
- print(e)
- ret = 1
- return ret
+
+ with logging_handler(args.color):
+ ret = 0
+ for filename in args.filenames:
+ try:
+ load_manifest(filename)
+ except InvalidManifestError as e:
+ print(e)
+ ret = 1
+ return ret
LOCAL = 'local'
@@ -290,7 +295,11 @@ class InvalidConfigError(FatalError):
def ordered_load_normalize_legacy_config(contents: str) -> Dict[str, Any]:
data = yaml_load(contents)
if isinstance(data, list):
- # TODO: Once happy, issue a deprecation warning and instructions
+ logger.warning(
+ 'normalizing pre-commit configuration to a top-level map. '
+ 'support for top level list will be removed in a future version. '
+ 'run: `pre-commit migrate-config` to automatically fix this.',
+ )
return {'repos': data}
else:
return data
@@ -307,11 +316,13 @@ load_config = functools.partial(
def validate_config_main(argv: Optional[Sequence[str]] = None) -> int:
parser = _make_argparser('Config filenames.')
args = parser.parse_args(argv)
- ret = 0
- for filename in args.filenames:
- try:
- load_config(filename)
- except InvalidConfigError as e:
- print(e)
- ret = 1
- return ret
+
+ with logging_handler(args.color):
+ ret = 0
+ for filename in args.filenames:
+ try:
+ load_config(filename)
+ except InvalidConfigError as e:
+ print(e)
+ ret = 1
+ return ret