Skip to content

Commit c558860

Browse files
committed
fix: Add UTF-8 encoding to documentation generation for Windows
Specify encoding explicitly in file operations to prevent UnicodeEncodeError when building docs on Windows systems that default to cp1252 encoding. Fixes #24360 Signed-off-by: alekramelaheehridoy <alekramelaheehridoy@gmail.com> Signed-off-by: alekramelaheehridoy <aliqramalaheehridoy@gmail.com>
1 parent fde9ae9 commit c558860

File tree

4 files changed

+3
-315
lines changed

4 files changed

+3
-315
lines changed

docs/contributing/windows_development.md

Lines changed: 0 additions & 158 deletions
This file was deleted.

docs/mkdocs/hooks/generate_argparse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def on_startup(command: Literal["build", "gh-deploy", "serve"], dirty: bool):
165165
# Generate documentation for each parser
166166
for stem, parser in parsers.items():
167167
doc_path = ARGPARSE_DOC_DIR / f"{stem}.md"
168+
# Specify encoding for building on Windows
168169
with open(doc_path, "w", encoding="utf-8") as f:
169170
f.write(parser.format_help())
170171
logger.info("Argparse generated: %s", doc_path.relative_to(ROOT_DIR))

docs/mkdocs/hooks/generate_examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def determine_other_files(self) -> list[Path]:
106106

107107
def determine_title(self) -> str:
108108
if not self.is_code:
109+
# Specify encoding for building on Windows
109110
with open(self.main_file, encoding="utf-8") as f:
110111
first_line = f.readline().strip()
111112
match = re.match(r'^#\s+(?P<title>.+)$', first_line)
@@ -174,6 +175,7 @@ def on_startup(command: Literal["build", "gh-deploy", "serve"], dirty: bool):
174175
doc_path = EXAMPLE_DOC_DIR / example.category / example_name
175176
if not doc_path.parent.exists():
176177
doc_path.parent.mkdir(parents=True)
178+
# Specify encoding for building on Windows
177179
with open(doc_path, "w+", encoding="utf-8") as f:
178180
f.write(example.generate())
179181
logger.debug("Example generated: %s", doc_path.relative_to(ROOT_DIR))

tests/docs/test_encoding_fix.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)