[Fixed][Windows] Layers cache written with \r\r\n row endings breaks cached diffs - #22
Open
mike-shevchenko wants to merge 1 commit into
Open
mike-shevchenko wants to merge 1 commit into
mike-shevchenko wants to merge 1 commit into
Conversation
csv.writer emits \r\n, and the stream was opened in text mode without newline='', so on Windows the \n was translated again and every row of layers.csv ended \r\r\n. Reading it back produced a blank row between each real one, so load_cached_layers() raised IndexError on r[0] and the second diff of any board failed. Adds newline='' to both open() calls, as the csv module documents, and skips blank rows on read so caches already written by earlier versions keep working instead of having to be deleted.
mike-shevchenko
force-pushed
the
fix-csv-newline-windows
branch
from
September 18, 2026 11:01
3a39d10 to
9bbcc1e
Compare
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.
Problem
On Windows, the second diff of any board fails:
The first diff of a given board always succeeds, because it is a cache miss and the layers
are read from the PCB. Every later diff that hits the cache fails, which in practice means
any persistent
--cache_diris unusable on Windows.Cause
csv.writeralways terminates rows with\r\n.save_layers_to_cache()opened the streamin text mode without
newline='', so on Windows the\nwas translated a second time andeach row landed as
\r\r\n:Reading that back yields a blank row between each real one, and
int(r[0])raisesIndexError. This is the case the csv docs call out -newline=''is required on both theread and the write side.
Fix
newline=''on bothopen()calls, so rows are written and read as\r\n.it every cache already written by an earlier version keeps crashing until the user finds
and deletes it. Two lines seemed better than a migration note.
No behaviour change on Linux or macOS, where
\nis not translated and the bug neverappeared.
Verification
Same two boards, same cache directory, KiCad 10.0.6 / Python 3.11 on Windows 10:
IndexErrorIndexErrorlayers.csvrow ending\r\r\n\r\nThe last row is the backward-compatibility case: I deliberately rewrote a good cache back to
\r\r\nand confirmed the patched script reads it while the unpatched one still raises.