From d7c5e9f77558422ee0ecbb9fe3a602afb2a97046 Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Wed, 10 Jun 2026 12:07:32 -0400 Subject: [PATCH 1/2] merge main --- Published/CORE-000084/negative/02/results/results.csv | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Published/CORE-000084/negative/02/results/results.csv b/Published/CORE-000084/negative/02/results/results.csv index ac0a344f7..daf1aa5b6 100644 --- a/Published/CORE-000084/negative/02/results/results.csv +++ b/Published/CORE-000084/negative/02/results/results.csv @@ -1,14 +1,6 @@ Dataset,Record,Variable,Value -<<<<<<< HEAD -AE,0,AEENTPT,2013-05-20 -AE,1,AEENTPT,2013-05-20 -AE,2,AEENTPT,2013-01-14 -AE,3,AEENTPT,2013-01-14 -AE,4,AEENTPT, -======= AE.csv,1,AEENTPT,2013-05-20 AE.csv,2,AEENTPT,2013-05-20 AE.csv,3,AEENTPT,2013-01-14 AE.csv,4,AEENTPT,2013-01-14 AE.csv,5,AEENTPT, ->>>>>>> main From 2e79de3c53f86d9746dedcbb2d1b1ecb00df6e64 Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Fri, 10 Jul 2026 10:45:14 -0400 Subject: [PATCH 2/2] ruamel --- scripts/sort_yaml.py | 66 ++++++++++++++++++++--------------------- setup/bash_setup.sh | 3 ++ setup/windows_setup.bat | 10 +++++++ 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/scripts/sort_yaml.py b/scripts/sort_yaml.py index b174e0aa4..d929eeb9a 100644 --- a/scripts/sort_yaml.py +++ b/scripts/sort_yaml.py @@ -17,34 +17,26 @@ import sys import argparse +from io import StringIO from pathlib import Path try: - import yaml + from ruamel.yaml import YAML + from ruamel.yaml.comments import CommentedMap, CommentedSeq except ImportError: - print("ERROR: pyyaml is not installed. Run: pip install pyyaml", file=sys.stderr) + print("ERROR: ruamel.yaml is not installed. Run: pip install ruamel.yaml", file=sys.stderr) sys.exit(1) # --------------------------------------------------------------------------- -# Custom YAML Dumper +# YAML round-trip instance (loader + dumper), configured once # --------------------------------------------------------------------------- -class _SortedDumper(yaml.Dumper): - """YAML Dumper that produces consistent, human-readable output.""" - pass - - -def _str_representer(dumper: yaml.Dumper, data: str): - """Represent strings: use literal block style for multi-line, plain otherwise. - Strings that look like YAML scalars (booleans, numbers) are quoted. - """ - if "\n" in data: - return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|") - return dumper.represent_scalar("tag:yaml.org,2002:str", data) - - -_SortedDumper.add_representer(str, _str_representer) +_yaml = YAML(typ="rt") +_yaml.preserve_quotes = True +_yaml.width = 100 +_yaml.indent(mapping=2, sequence=2, offset=0) +_yaml.allow_unicode = True # --------------------------------------------------------------------------- @@ -53,28 +45,36 @@ def _str_representer(dumper: yaml.Dumper, data: str): def sort_recursive(obj): """Recursively sort dict keys alphabetically. Lists are preserved as-is.""" - if isinstance(obj, dict): - return {k: sort_recursive(obj[k]) for k in sorted(obj.keys(), key=str)} - if isinstance(obj, list): - return [sort_recursive(item) for item in obj] + if isinstance(obj, CommentedMap): + sorted_map = CommentedMap() + for key in sorted(obj.keys(), key=str): + sorted_map[key] = sort_recursive(obj[key]) + sorted_map.ca.items.update(obj.ca.items) + if obj.ca.comment is not None: + sorted_map.ca.comment = obj.ca.comment + sorted_map.ca.end = obj.ca.end + return sorted_map + + if isinstance(obj, CommentedSeq): + new_seq = CommentedSeq(sort_recursive(item) for item in obj) + new_seq.ca.items.update(obj.ca.items) + if obj.ca.comment is not None: + new_seq.ca.comment = obj.ca.comment + new_seq.ca.end = obj.ca.end + return new_seq + return obj def canonical(content: str) -> str: """Return the canonical (sorted + formatted) representation of a YAML string.""" - data = yaml.safe_load(content) + data = _yaml.load(content) if data is None: return content sorted_data = sort_recursive(data) - return yaml.dump( - sorted_data, - Dumper=_SortedDumper, - default_flow_style=False, - allow_unicode=True, - indent=2, - sort_keys=False, # we already sorted manually - width=100, - ) + stream = StringIO() + _yaml.dump(sorted_data, stream) + return stream.getvalue() def find_rule_files(root: Path) -> list[Path]: @@ -172,5 +172,3 @@ def main(): if __name__ == "__main__": main() - - diff --git a/setup/bash_setup.sh b/setup/bash_setup.sh index 3b420ebc8..b3a0ef891 100644 --- a/setup/bash_setup.sh +++ b/setup/bash_setup.sh @@ -129,6 +129,9 @@ pip install --quiet -e engine/[dev] VENV_PYTHON=$(which python) +echo "Installing ruamel.yaml..." +pip install --quiet ruamel.yaml + echo "Installing pre-commit..." pip install pre-commit --index-url https://pypi.org/simple/ --quiet 2>/dev/null || \ pip install pre-commit --quiet 2>/dev/null || true diff --git a/setup/windows_setup.bat b/setup/windows_setup.bat index 4348441f9..582d6c285 100644 --- a/setup/windows_setup.bat +++ b/setup/windows_setup.bat @@ -155,6 +155,16 @@ if !errorlevel! neq 0 ( exit /b 1 ) +echo. +echo Installing ruamel.yaml... +python -m pip install ruamel.yaml --quiet +if !errorlevel! neq 0 ( + echo Failed to install ruamel.yaml + cd .. + pause + exit /b 1 +) + echo. echo Installing pre-commit... python -m pip install pre-commit --index-url https://pypi.org/simple/ --quiet 2>nul || python -m pip install pre-commit --quiet 2>nul