#!/usr/bin/env python """Converts the YAML files of Snake Quest to Python literals read by the omegaconf.py stand-in. yaml-to-pylit.py ... (run with a Python that has omegaconf 2.4.0) Each .yaml in the directories (not recursive) becomes .pylit, with the same content as the real OmegaConf reads it (OmegaConf.to_container), and the YAML is removed. Keys keep their types (integers stay integers). """ import pprint import sys from pathlib import Path from omegaconf import OmegaConf for directory in sys.argv[1:]: for yaml in sorted(Path(directory).glob("*.yaml")): data = OmegaConf.to_container(OmegaConf.load(yaml), resolve=True) text = pprint.pformat(data, width=140, sort_dicts=False) assert eval(text) == data # round trip yaml.with_suffix(".pylit").write_text(text + "\n", encoding="utf-8") yaml.unlink()