Skip to content

Ensure explicit UTF-8 encoding in prek scripts for Windows compatibility - #73679

Merged
potiuk merged 2 commits into
apache:mainfrom
Adityakk9031:windows-compat-prek-utf8
Oct 18, 2026
Merged

potiuk merged 2 commits into
apache:mainfrom
Adityakk9031:windows-compat-prek-utf8

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, Python's default encoding for open() and Path.read_text() is based on the system locale (locale.getpreferredencoding(False), typically cp1252), not UTF-8 (until PEP 686 in Python 3.15). When reading files containing non-ASCII characters without specifying an encoding, this leads to UnicodeDecodeError: 'charmap' codec can't decode byte 0x81....

This PR adds explicit encoding="utf-8" to read_text() calls in scripts/ci/prek/common_prek_utils.py to ensure deterministic behavior across platforms.

Split from #70946 per maintainer review.

@Eason09053360 Eason09053360 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch! One suggestion and feel free to resolve it.

Comment thread scripts/ci/prek/common_prek_utils.py Resolved
@Adityakk9031

Copy link
Copy Markdown
Contributor Author

Thanks @Eason09053360 — the write now uses encoding="utf-8" too (4c2a03c).

@potiuk
potiuk merged commit 515533c into apache:main Oct 18, 2026
68 checks passed
@boring-cyborg

boring-cyborg Bot commented Oct 18, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants