Remove ruamel stuff

This commit is contained in:
Miguel Jacq 2025-11-26 15:40:38 +11:00
parent 11a5ac690f
commit ad7ec81078
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9

View file

@ -6,11 +6,6 @@ from pathlib import Path
from typing import Any, Iterable
import yaml
try:
from ruamel.yaml import YAML as RuamelYAML # for comment-preserving YAML
except ImportError: # pragma: no cover
RuamelYAML = None
try:
import tomllib # Python 3.11+
except ModuleNotFoundError: # pragma: no cover
@ -28,8 +23,8 @@ class QuotedString(str):
def _fallback_str_representer(dumper: yaml.SafeDumper, data: Any):
"""
Fallback for objects the dumper doesn't know about (e.g. ruamel.yaml
scalar types). Represent them as plain strings.
Fallback for objects the dumper doesn't know about. Represent them as
plain strings.
"""
return dumper.represent_scalar("tag:yaml.org,2002:str", str(data))
@ -86,15 +81,7 @@ def parse_config(path: Path, fmt: str | None = None) -> tuple[str, Any]:
if fmt == "yaml":
text = path.read_text(encoding="utf-8")
if RuamelYAML is not None:
# ruamel.yaml preserves comments; we'll reuse them in template gen
y = RuamelYAML()
y.preserve_quotes = True
data = y.load(text) or {}
else:
# Fallback: PyYAML (drops comments in parsed structure, but we still
# have the original text for comment-preserving template generation).
data = yaml.safe_load(text) or {}
data = yaml.safe_load(text) or {}
return fmt, data
if fmt == "json":