Replace aspy.yaml with sort_keys=False

This commit is contained in:
Anthony Sottile
2020-01-31 17:18:59 -08:00
parent f0ee93c5a7
commit a64fa6d478
8 changed files with 36 additions and 26 deletions

View File

@@ -8,9 +8,6 @@ from typing import Optional
from typing import Sequence
from typing import Tuple
from aspy.yaml import ordered_dump
from aspy.yaml import ordered_load
import pre_commit.constants as C
from pre_commit import git
from pre_commit import output
@@ -25,6 +22,8 @@ from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
from pre_commit.util import tmpdir
from pre_commit.util import yaml_dump
from pre_commit.util import yaml_load
class RevInfo(NamedTuple):
@@ -105,7 +104,7 @@ def _original_lines(
raise AssertionError('could not find rev lines')
else:
with open(path, 'w') as f:
f.write(ordered_dump(ordered_load(original), **C.YAML_DUMP_KWARGS))
f.write(yaml_dump(yaml_load(original)))
return _original_lines(path, rev_infos, retry=True)
@@ -117,7 +116,7 @@ def _write_new_config(path: str, rev_infos: List[Optional[RevInfo]]) -> None:
continue
match = REV_LINE_RE.match(lines[idx])
assert match is not None
new_rev_s = ordered_dump({'rev': rev_info.rev}, **C.YAML_DUMP_KWARGS)
new_rev_s = yaml_dump({'rev': rev_info.rev})
new_rev = new_rev_s.split(':', 1)[1].strip()
if rev_info.frozen is not None:
comment = f' # frozen: {rev_info.frozen}'

View File

@@ -1,7 +1,8 @@
import re
import yaml
from aspy.yaml import ordered_load
from pre_commit.util import yaml_load
def _indent(s: str) -> str:
@@ -24,12 +25,12 @@ def _migrate_map(contents: str) -> str:
header = ''.join(lines[:i])
rest = ''.join(lines[i:])
if isinstance(ordered_load(contents), list):
if isinstance(yaml_load(contents), list):
# If they are using the "default" flow style of yaml, this operation
# will yield a valid configuration
try:
trial_contents = f'{header}repos:\n{rest}'
ordered_load(trial_contents)
yaml_load(trial_contents)
contents = trial_contents
except yaml.YAMLError:
contents = f'{header}repos:\n{_indent(rest)}'

View File

@@ -4,8 +4,6 @@ import os.path
from typing import Optional
from typing import Tuple
from aspy.yaml import ordered_dump
import pre_commit.constants as C
from pre_commit import git
from pre_commit import output
@@ -14,6 +12,7 @@ from pre_commit.commands.run import run
from pre_commit.store import Store
from pre_commit.util import cmd_output_b
from pre_commit.util import tmpdir
from pre_commit.util import yaml_dump
from pre_commit.xargs import xargs
logger = logging.getLogger(__name__)
@@ -63,7 +62,7 @@ def try_repo(args: argparse.Namespace) -> int:
hooks = [{'id': hook['id']} for hook in manifest]
config = {'repos': [{'repo': repo, 'rev': ref, 'hooks': hooks}]}
config_s = ordered_dump(config, **C.YAML_DUMP_KWARGS)
config_s = yaml_dump(config)
config_filename = os.path.join(tempdir, C.CONFIG_FILE)
with open(config_filename, 'w') as cfg: