From a82b8a966a7dbe218cb788548683a83ec404e468 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 22 Jul 2025 11:54:47 -0600 Subject: [PATCH] Use UTF-8 for config doc generation (#18580) --- changelog.d/18580.misc | 1 + scripts-dev/gen_config_documentation.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog.d/18580.misc diff --git a/changelog.d/18580.misc b/changelog.d/18580.misc new file mode 100644 index 000000000..8a36cd5e5 --- /dev/null +++ b/changelog.d/18580.misc @@ -0,0 +1 @@ +Fix config documentation generation script on Windows by enforcing UTF-8. \ No newline at end of file diff --git a/scripts-dev/gen_config_documentation.py b/scripts-dev/gen_config_documentation.py index 8e9d402c6..9a49c07a3 100755 --- a/scripts-dev/gen_config_documentation.py +++ b/scripts-dev/gen_config_documentation.py @@ -473,6 +473,10 @@ def section(prop: str, values: dict) -> str: def main() -> None: + # For Windows: reconfigure the terminal to be UTF-8 for `print()` calls. + if sys.platform == "win32": + sys.stdout.reconfigure(encoding="utf-8") + def usage(err_msg: str) -> int: script_name = (sys.argv[:1] or ["__main__.py"])[0] print(err_msg, file=sys.stderr) @@ -485,7 +489,10 @@ def main() -> None: exit(usage("Too many arguments.")) if not (filepath := (sys.argv[1:] or [""])[0]): exit(usage("No schema file provided.")) - with open(filepath) as f: + with open(filepath, "r", encoding="utf-8") as f: + # Note: Windows requires that we specify the encoding otherwise it uses + # things like CP-1251, which can cause explosions. + # See https://github.com/yaml/pyyaml/issues/123 for more info. return yaml.safe_load(f) schema = read_json_file_arg()