Skip to content

Commit a82b8a9

Browse files
authored
Use UTF-8 for config doc generation (#18580)
1 parent f5f2c95 commit a82b8a9

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

changelog.d/18580.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix config documentation generation script on Windows by enforcing UTF-8.

scripts-dev/gen_config_documentation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ def post_description() -> str:
473473

474474

475475
def main() -> None:
476+
# For Windows: reconfigure the terminal to be UTF-8 for `print()` calls.
477+
if sys.platform == "win32":
478+
sys.stdout.reconfigure(encoding="utf-8")
479+
476480
def usage(err_msg: str) -> int:
477481
script_name = (sys.argv[:1] or ["__main__.py"])[0]
478482
print(err_msg, file=sys.stderr)
@@ -485,7 +489,10 @@ def read_json_file_arg() -> Any:
485489
exit(usage("Too many arguments."))
486490
if not (filepath := (sys.argv[1:] or [""])[0]):
487491
exit(usage("No schema file provided."))
488-
with open(filepath) as f:
492+
with open(filepath, "r", encoding="utf-8") as f:
493+
# Note: Windows requires that we specify the encoding otherwise it uses
494+
# things like CP-1251, which can cause explosions.
495+
# See https://github.com/yaml/pyyaml/issues/123 for more info.
489496
return yaml.safe_load(f)
490497

491498
schema = read_json_file_arg()

0 commit comments

Comments
 (0)