From 2fe1bd88437ad3a4972c43ed34114f1a415c930f Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 07:05:21 +0000 Subject: [PATCH] Initial upload: ConfigConvert CLI with full test suite and CI/CD --- config_convert/converters/yaml_converter.py | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 config_convert/converters/yaml_converter.py diff --git a/config_convert/converters/yaml_converter.py b/config_convert/converters/yaml_converter.py new file mode 100644 index 0000000..0ea1863 --- /dev/null +++ b/config_convert/converters/yaml_converter.py @@ -0,0 +1,32 @@ +"""YAML format converter using PyYAML.""" + +import yaml +from pathlib import Path +from typing import Any, Dict, Optional + +from config_convert.converters.base import Converter + + +class YAMLConverter(Converter): + """Converter for YAML format.""" + + @property + def name(self) -> str: + return "yaml" + + def loads(self, data: str) -> Dict[str, Any]: + return yaml.safe_load(data) + + def dumps(self, data: Dict[str, Any], indent: Optional[int] = None) -> str: + if indent is None: + indent = 2 + return yaml.safe_dump(data, indent=indent, allow_unicode=True) + + def load(self, file_path: str) -> Dict[str, Any]: + with open(file_path, "r", encoding="utf-8") as f: + return yaml.safe_load(f) + + def dump(self, data: Dict[str, Any], file_path: str, indent: Optional[int] = None) -> None: + Path(file_path).parent.mkdir(parents=True, exist_ok=True) + with open(file_path, "w", encoding="utf-8") as f: + yaml.safe_dump(data, f, indent=indent, allow_unicode=True)