fix: ignore stray files when resolving latest schema version#854
Open
ehennestad wants to merge 1 commit into
Open
fix: ignore stray files when resolving latest schema version#854ehennestad wants to merge 1 commit into
ehennestad wants to merge 1 commit into
Conversation
Stray entries in nwb-schema/ (e.g. .DS_Store created by macOS Finder) shifted the version-comparison matrix off by one, making findLatestSchemaVersion silently return an old version (2.1.0 instead of 2.10.0). Filter directory entries to exact major.minor.patch names before comparing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #854 +/- ##
=======================================
Coverage 95.45% 95.45%
=======================================
Files 228 228
Lines 8080 8082 +2
=======================================
+ Hits 7713 7715 +2
Misses 367 367 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Motivation
Problem — On macOS, Finder silently drops a
.DS_Storefile into MatNWB'snwb-schema/folder as soon as the folder is browsed. Any such stray entry makesgenerateCore()(called without a version argument, i.e. "use latest") silently resolve to an old schema version —2.1.0instead of2.10.0— so the user unknowingly generates classes for a years-old schema. No error or warning is raised.Solution — When determining the latest schema version, only folder entries whose name is an exact
major.minor.patchversion number are considered, so stray files can no longer influence the result.What changed
matnwb.common.findLatestSchemaVersion(used bygenerateCoreto resolve the default schema version) now ignores any entry innwb-schema/that is not named as an exact version number.nwb-schema/folder is unchanged.Implementation notes
Previously only
.and..were excluded from the directory listing. For any other non-version entry,sscanf(name, '%d.%d.%d')returned empty, silently dropping that entry from the version-comparison matrix while it remained in the name list — an off-by-one that made the max-version index point at the wrong name. Entries are now filtered with the anchored pattern^\d+\.\d+\.\d+$before parsing.Examples
With a stray (hidden) file present in
nwb-schema/:Before (silently wrong version):
After:
How to test
Run the snippet above on this branch — the result is
'2.10.0'regardless of stray files innwb-schema/. On macOS, simply browsingnwb-schema/in Finder (which creates.DS_Store) and then callinggenerateCore()also exercises the fix.Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Claude Code