mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Merge ebaf7da989 into 1adfa24124
This commit is contained in:
commit
5dbf5da372
6 changed files with 35 additions and 19 deletions
|
|
@ -9,9 +9,9 @@ import sys
|
|||
import jsonschema
|
||||
import jsonschema.exceptions
|
||||
import pkg_resources
|
||||
import yaml
|
||||
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.yaml import yaml_load
|
||||
|
||||
|
||||
def is_regex_valid(regex):
|
||||
|
|
@ -36,7 +36,7 @@ def get_validator(
|
|||
the object read from the file. The function should either raise
|
||||
exception_type on failure.
|
||||
"""
|
||||
def validate(filename, load_strategy=yaml.load):
|
||||
def validate(filename, load_strategy=yaml_load):
|
||||
if not os.path.exists(filename):
|
||||
raise exception_type('File {} does not exist'.format(filename))
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ from __future__ import unicode_literals
|
|||
import logging
|
||||
import sys
|
||||
|
||||
from aspy.yaml import ordered_dump
|
||||
from aspy.yaml import ordered_load
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import is_local_hooks
|
||||
|
|
@ -18,6 +15,8 @@ from pre_commit.repository import Repository
|
|||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.yaml import yaml_dump
|
||||
from pre_commit.yaml import yaml_load
|
||||
|
||||
|
||||
logger = logging.getLogger('pre_commit')
|
||||
|
|
@ -79,7 +78,7 @@ def autoupdate(runner):
|
|||
|
||||
input_configs = load_config(
|
||||
runner.config_file_path,
|
||||
load_strategy=ordered_load,
|
||||
load_strategy=yaml_load,
|
||||
)
|
||||
|
||||
for repo_config in input_configs:
|
||||
|
|
@ -111,7 +110,7 @@ def autoupdate(runner):
|
|||
if changed:
|
||||
with open(runner.config_file_path, 'w') as config_file:
|
||||
config_file.write(
|
||||
ordered_dump(
|
||||
yaml_dump(
|
||||
remove_defaults(output_configs, CONFIG_JSON_SCHEMA),
|
||||
**C.YAML_DUMP_KWARGS
|
||||
)
|
||||
|
|
|
|||
11
pre_commit/yaml.py
Executable file
11
pre_commit/yaml.py
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
from ruamel import yaml
|
||||
|
||||
|
||||
def yaml_dump(obj, **kwargs):
|
||||
"Ensure order & comments preservation"
|
||||
return yaml.dump(obj, Dumper=yaml.RoundTripDumper, **kwargs)
|
||||
|
||||
|
||||
def yaml_load(content):
|
||||
"Ensure order & comments preservation"
|
||||
return yaml.load(content, Loader=yaml.RoundTripLoader)
|
||||
Loading…
Add table
Add a link
Reference in a new issue