Skip to content

Use UTF-8 for config doc generation #18580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18580.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix config documentation generation script on Windows by enforcing UTF-8.
9 changes: 8 additions & 1 deletion scripts-dev/gen_config_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ def post_description() -> 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')
Comment on lines +476 to +478
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to do this for all platforms, especially if we're reading utf-8 on all platforms below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checking says it doesn't exist. I was hoping to trick it with a windows check, but seems that's not enough.


def usage(err_msg: str) -> int:
script_name = (sys.argv[:1] or ["__main__.py"])[0]
print(err_msg, file=sys.stderr)
Expand All @@ -485,7 +489,10 @@ def read_json_file_arg() -> Any:
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='utf8') 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()
Expand Down
Loading