Skip to content

fix: improve file naming logic in get_next_available_path #529

Open
fdrgsp wants to merge 3 commits into
pymmcore-plus:mainfrom
fdrgsp:fix-save-naming
Open

fix: improve file naming logic in get_next_available_path #529
fdrgsp wants to merge 3 commits into
pymmcore-plus:mainfrom
fdrgsp:fix-save-naming

Conversation

@fdrgsp
Copy link
Copy Markdown
Collaborator

@fdrgsp fdrgsp commented Mar 26, 2026

Update the get_next_available_path function...I found it weird that when requesting test.ome.tiff in a folder that had no test*.ome.tiff files (but contained other unrelated .ome.tiff files (e.g., other_009.ome.tiff)) the result was test_010.ome.tiff instead of the expected test.ome.tiff.

The issue was that the glob pattern *.ome.tiff matched all .ome.tiff files in the directory, not just those sharing the same stem. This caused unrelated files' counters to influence the result. Fixed by scoping the glob to {stem}*.ome.tiff.


New behavior:

Basic: no existing files in directory

Requested path Result Why
test.ome.tiff test.ome.tiff Doesn't exist, no conflicts
test_001.ome.tiff test_001.ome.tiff Doesn't exist, no conflicts
test_02.ome.tiff test_02.ome.tiff Doesn't exist, no conflicts

test.ome.tiff exists in directory

Requested path Result Why
test.ome.tiff test_001.ome.tiff Next available counter

test.ome.tiff and test_004.ome.tiff exist

Requested path Result Why
test.ome.tiff test_005.ome.tiff Next after highest counter
test_003.ome.tiff test_005.ome.tiff Requested counter < max, uses max+1
test_010.ome.tiff test_010.ome.tiff Requested counter > max, keeps it
test_02.ome.tiff test_02.ome.tiff _02 is not a counter (< 3 digits), treated as distinct stem, no test_02* files exist

Bug fix: other_009.ome.tiff exists (unrelated file)

Requested path Old (broken) result New (fixed) result Why
test.ome.tiff test_010.ome.tiff test.ome.tiff Old glob *.ome.tiff matched unrelated files; new glob test*.ome.tiff scopes to same stem
test.ome.tiff (after creating it) test_010.ome.tiff test_001.ome.tiff Counter now based only on test_* files

test_999.ome.tiff exists (digit overflow)

Requested path Result Why
test.ome.tiff test_1000.ome.tiff Grows beyond 3 digits when needed

test_12345.ome.tiff exists (high counter)

Requested path Result Why
test_12345.ome.tiff test_12346.ome.tiff Preserves digit count from existing files

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.87%. Comparing base (12508e3) to head (c0da02f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #529   +/-   ##
=======================================
  Coverage   86.87%   86.87%           
=======================================
  Files         115      115           
  Lines       14093    14097    +4     
=======================================
+ Hits        12243    12247    +4     
  Misses       1850     1850           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fdrgsp fdrgsp changed the title fix: improve file naming logic in get_next_available_path [WIP] fix: improve file naming logic in get_next_available_path Mar 26, 2026
@fdrgsp fdrgsp changed the title [WIP] fix: improve file naming logic in get_next_available_path fix: improve file naming logic in get_next_available_path Mar 27, 2026
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.

1 participant