fix: use explicit utf-8 encoding and LF newlines for file I/O - #2308
fix: use explicit utf-8 encoding and LF newlines for file I/O#2308sravankumarkunadi wants to merge 1 commit into
Conversation
Path.read_text()/write_text() default to the platform's preferred encoding and newline translation. On Windows this means cp1252 and CRLF, which breaks reading the report template and JSON output (UnicodeDecodeError) and rewrites the message test fixtures with CRLF line endings when running with OVERRIDE=true. Pass encoding="utf-8" explicitly on all reads and writes, and newline="\n" on the fixture writes so generated expected files stay LF regardless of platform.
|
👋 @sravankumarkunadi |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughReport generation and message fixture helpers now use explicit UTF-8 encoding. Fixture writes also normalize newlines while preserving trailing newline behavior for expected text. ChangesEncoding Consistency
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing this — opened in error, unrelated to the work I'm actually doing on this repo. Sorry for the noise. |
What
Pass
encoding="utf-8"explicitly to everyPath.read_text()/Path.write_text()call inscripts/generate_report_from_json.pyandtests/unit/messages/utils.py, andnewline="\n"to the fixture writes.Why
read_text()/write_text()fall back tolocale.getpreferredencoding()and platform newline translation when no encoding is given. That's UTF-8/LF on Linux and macOS, but cp1252/CRLF on Windows.Before
scripts/generate_report_from_json.pyraisesUnicodeDecodeErroron Windows when the report template (elementary/monitor/data_monitoring/report/index.html) or the JSON output contains any non-cp1252 character.tests/unit/messages/utils.pyrun withOVERRIDE=trueon Windows rewrites the expected JSON/text fixtures with CRLF line endings, producing a diff on every fixture file that touches the repo.After
Notes
No behavior change on Linux/macOS — this only makes the already-assumed defaults explicit.
Path.write_text(newline=...)requires Python 3.10, which matches this project'spython = ">=3.10,<3.14".Summary by CodeRabbit