Repository navigation
fix: read and write standard streams and text files as UTF-8 - #505
Merged
Merged
Conversation
Redirected stdio on Windows uses cp1252, so `reqstool validate > file` crashed with UnicodeEncodeError on the status symbols it prints, and `reqstool enrich` could not decode UTF-8 on stdin. Only `report` had a per-command workaround (#502). - Reconfigure stdin/stdout/stderr to UTF-8 once at the start of main() and drop the report-specific reconfigure. - Pass encoding="utf-8" to the remaining open()/read_text() calls on text files: LSP schema, definition and root discovery reads, the .reqstool-ai.yaml config, the bundled JSON schemas, and the LSP log file handler. A UTF-8 requirements.yml was silently skipped by LSP root discovery under a legacy default encoding. Signed-off-by: Jimisola Laursen <jimisola@jimisola.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mt2FAXZTXnbKG2Ho6GYy1z
1 task
jimisola
marked this pull request as ready for review
November 22, 2026 08:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Jimisola · project thread
Follow-up to #502, which fixed the same class of bug for
reportonly.What & why
On Windows, redirected stdio and
open()withoutencoding=use cp1252. Found by an encoding audit across the reqstool repos:reqstool validatecrashed on redirected stdout (UnicodeEncodeErroron⚠/✓), exit 1. Reproduced withPYTHONIOENCODING=cp1252.reqstool enrichcould not decode UTF-8 on stdin.lsp/yaml_schema.py,lsp/features/definition.py,lsp/root_discovery.py,common/reqstool_ai_config.py) decoded UTF-8 files with the locale codec. Mostly that gives mojibake in non-ID text, but a file containing bytes cp1252 leaves undefined raisesUnicodeDecodeError;root_discovery._quick_parseswallows it, so such arequirements.ymlwas silently not discovered.Changes
main()reconfigures stdin/stdout/stderr to UTF-8 once (_use_utf8_standard_streams); the report-specific reconfigure is removed. Streams that cannot be reconfigured are left alone.encoding="utf-8"on the remaining text-file reads: LSP schema/definition/root discovery,.reqstool-ai.yaml, the bundled JSON schemas (syntax_validator), and the LSP logFileHandler(extracted as_log_handlers).Not changed: YAML datasets are read via
requests+FileAdapterandresponse.text, which guesses the charset when no HTTP header is present. It is not locale-dependent and detected UTF-8 correctly on a Swedish sample, so I left it out; decodingresponse.contentas UTF-8 would be a separate change.Test plan
mainfor the right reasons: validate (UnicodeEncodeError), enrich stdin (UnicodeDecodeError), stream helper (ImportError), and 8 file-read tests (UnicodeDecodeError,Nonefrom_quick_parse,ImportErrorfor_log_handlers).status/report/exportstdout guard tests pass on both.PYTHONUTF8=0 PYTHONIOENCODING=cp1252(stdio) and a strict-ASCIIopen()default (file reads). Not run on a real Windows runner; that is what the smoke jobs in ci: smoke-test the built wheel on macOS and Windows #500 are for.hatch run dev:pytest tests/unit: 933 passed, black and flake8 clean; changed lines covered.main:status,report --format asciidocandvalidatebyte-identical ontest_standard/ms-001,test_basic/ms-101andreqstool-demo.Rerun:
python -m pytest tests/unit/reqstool/test_command.py tests/unit/reqstool/test_default_encoding.py -k "cp1252 or utf8 or encoding"🤖 Generated with Claude Code
https://claude.ai/code/session_01Mt2FAXZTXnbKG2Ho6GYy1z