Skip to content

FileSet.map_nested and the staged_out_dir extras wrapper - #165

Merged
tclose merged 3 commits into
mainfrom
map-nested
Oct 16, 2026
Merged

tclose merged 3 commits into
mainfrom
map-nested

Conversation

@tclose

@tclose tclose commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

General-purpose pieces for building modified copies of filesets that contain others, factored out of the deidentification work in fileformats-medimage and fileformats-biosig. Nothing here is specific to deidentification.

Changes

  • FileSet.nested_filesets(recursive=True) now also finds filesets inside dicts and lists returned by validated properties (previously skipped). recursive=False returns only the direct children.
  • New FileSet.map_nested(out_dir, func):
    • Writes a copy of the fileset, calling func(nested, dest_dir) to write each directly nested fileset in its mirrored position; returning None copies it unchanged. All other files are copied, keeping their layout relative to the common parent.
    • Nested filesets that point entirely outside the fileset are skipped, consistent with copy(). One that's partly inside and partly outside raises ValueError.
    • Recreating the type at the end checks that the layout survived.
  • New staged_out_dir wrapper (exported from fileformats.core) for extras that write to an out_dir argument, used as @extra(wrapper=staged_out_dir):
    • Implementations write into a hidden sibling staging directory, which is moved into out_dir only once they return, so only complete output appears there.
    • Raises FileExistsError before moving anything if the output would overwrite existing files.
    • Checks that the implementation wrote into the directory it was given.

Tests

  • New core/tests/test_map_nested.py covering:
    • nested filesets inside dicts and lists, and recursive=False;
    • mapping, copying unchanged, skipping external filesets, and the layout check;
    • staging: success, failure leaves nothing behind, and refusal to overwrite.

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fileformats/core/fileset.py 80.95% 5 Missing and 3 partials ⚠️
fileformats/core/extras.py 90.90% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tclose
tclose merged commit 1d66b45 into main Oct 16, 2026
19 checks passed
@tclose
tclose deleted the map-nested branch October 19, 2026 07:41
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