py: file-writing API that bypasses newline translation - #265
Open
samtalki wants to merge 2 commits into
Open
Conversation
Network.write_file(path, to) / DistNetwork.write_file(path, to) and a convert_file(..., out=...) output path write the serialized case to disk exactly as produced, in Rust. Writing to_format text through open(path, "w") corrupts a CRLF source echo on Windows: text mode turns each \r\n into \r\r\n, which breaks the fixed line count records of a PSS/E raw file (PowerWorld rejects the case). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Conversion MatrixLegendCells show
Transmission7 cases.
Distribution7 cases.
Full warning details: download |
There was a problem hiding this comment.
Pull request overview
Adds Python-facing file-writing APIs that write serialized case text to disk from Rust to avoid Windows text-mode newline translation corrupting CRLF-retained source echoes (notably PSS/E v33 multi-line transformer records).
Changes:
- Add
Network.write_file(path, to)andDistNetwork.write_file(path, to)to write serialized output byte-exact via Rust. - Extend
convert_file(..., out=...)to optionally write the converted text to an output path byte-exact. - Add pytest coverage to assert byte-for-byte disk output for both transmission (PSS/E) and dist (DSS) cases, plus changelog/docs updates warning about
open(path, "w")on Windows.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/tests/test_powerio.py | Adds tests ensuring CRLF-retained PSS/E echoes are written byte-exact via write_file and convert_file(out=...). |
| python/tests/test_dist.py | Adds a dist-network echo test verifying byte-exact disk output via DistNetwork.write_file. |
| python/powerio/dist.py | Adds DistNetwork.write_file Python wrapper method delegating to Rust for byte-exact writes. |
| python/powerio/_powerio.pyi | Extends the PyO3 stub surface with write_file and convert_file(..., out=...). |
| python/powerio/init.pyi | Updates public Python stubs for Network.write_file and convert_file(..., out=...). |
| python/powerio/init.py | Adds Network.write_file wrapper and documents convert_file(..., out=...) newline-translation trap on Windows. |
| powerio-py/src/lib.rs | Implements Rust-backed PyNetwork.write_file, PyDistNetwork.write_file, and convert_file(..., out=...) file writes via std::fs::write. |
| CHANGELOG.md | Documents the new Python APIs and the Windows CRLF corruption pitfall. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The wrappers annotated the fidelity-warning return as bare list while the stubs say list[str]; both files use from __future__ import annotations, so the subscripted form is safe on 3.9. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPB7LVTeMcdBYnzA9QdpPe
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.
Adds
Network.write_file(path, to),DistNetwork.write_file(path, to), and anout=path onconvert_file, all writing the serialized case to disk from Rust, byte exact.Motivation: a user wrote a v33
.rawsame-format echo throughopen(path, "w")on Windows. Python's text mode translates every\nto\r\n, so the echoed CRLF source landed on disk as\r\r\n. Single-line records survive that, but the four-line v33 transformer records lose their alignment, and PowerWorld rejects the case ("Reading Error in Transformer Data Object"). The library output was byte identical to the source; the corruption happened at the write. The new paths make the correct write the obvious one, and theto_format/convert_filedocs now name the trap.Covered by pytest: the CRLF echo reaches disk byte exact through both
write_fileandconvert_file(out=...), plus the dist sibling.🤖 Generated with Claude Code