Skip to content

extract: write output files as UTF-8 - #216

Closed
ryanduguid wants to merge 2 commits into
beancount:masterfrom
ryanduguid:fix/utf8-extract-output
Closed

ryanduguid wants to merge 2 commits into
beancount:masterfrom
ryanduguid:fix/utf8-extract-output

Conversation

@ryanduguid

@ryanduguid ryanduguid commented Sep 21, 2026 •

Copy link
Copy Markdown

Saving extracted transactions with -o FILE uses the platform's default encoding. On Windows CP1252, a narration such as Payment from 管財人 raises UnicodeEncodeError. Set the existing Click file type to UTF-8 so the output can represent the transaction text.

The regression test runs the extraction command through the existing identity importer, simulates CP1252 for Click's file opens and parses the result to verify the narration. It covers named files, default stdout and explicit -o -.

Fixes #206.

Validation:

  • The new test fails in all three modes before the fix, each with UnicodeEncodeError under the simulated CP1252 default, and passes afterwards.
  • The native Windows reproduction with Python 3.12 and UTF-8 mode disabled now succeeds in all three modes.
  • python -m pytest beangulp: 144 passed, 3 skipped, 16 failed. An unchanged checkout at d5672c9 has 143 passed, 3 skipped and the same 16 failures, involving Windows paths, temporary files, MIME detection and related doctests.
  • ruff check beangulp/ examples/ passes with Ruff 0.12.12. Formatting and whitespace checks pass for the changed files.

Output files now consistently use UTF-8, including on systems with a different default encoding. The Linux test matrix and example importer checks remain for CI; they were not run locally.

Run the CLI with a cp1252 charset so the standard-output cases fail without
the fix, as the file case already did.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract -o FILE crashes on Windows with Unicode output, while stdout redirection works

1 participant