From 805b5194d96a4252a6dc9fd5492a65c335fca377 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Fri, 4 Dec 2026 10:14:30 +0100 Subject: [PATCH 1/3] feat: template snapshots and image header facts for tfmgr migrate tfmanager.migrate.snapshot reads a template, without image data, into a Snapshot: the size and md5 of each visible file (from the annex key of annexed files), the content of files in git, and the rows of .renames.tsv. It reads from the v2 skeleton zip of the client (manifest and root renames.tsv) or from any commit of a checkout (GitTree). Both give the same fingerprint (tfm1: sha256 of path, size and md5, plus the rows), and hidden files do not count. On the Archive, the two agree for all 30 templates. `tfmgr migrate headers ARCHIVE [--needs] [-o TSV]` lists the files whose headers the migration needs (volumes without an index res, every volume of templates without res blocks, probseg without label, GIFTI files whose suffix does not allow their extension) and reads them with nibabel: shape, zooms and origin as images.grid gives them, dtype, intent and the number of GIFTI arrays. Files are read through their link in the template, because nibabel tells formats apart by the file name. The table is keyed by path and md5, so a changed file has a stale row. GitTree gains mode() and link_target(). The tests get a pinned() download helper and the v2 skeleton fixture (python-client 45755e5, md5 checked). Co-Authored-By: Claude Opus 5.5 --- CHANGES.rst | 6 + tfmanager/cli.py | 73 +++++ tfmanager/migrate/__init__.py | 8 + tfmanager/migrate/headers.py | 208 +++++++++++++++ tfmanager/migrate/snapshot.py | 178 +++++++++++++ tfmanager/tests/conftest.py | 33 +++ tfmanager/tests/test_archive.py | 12 +- tfmanager/tests/test_migrate_snapshot.py | 322 +++++++++++++++++++++++ tfmanager/tree.py | 12 + 9 files changed, 842 insertions(+), 10 deletions(-) create mode 100644 tfmanager/migrate/__init__.py create mode 100644 tfmanager/migrate/headers.py create mode 100644 tfmanager/migrate/snapshot.py create mode 100644 tfmanager/tests/test_migrate_snapshot.py diff --git a/CHANGES.rst b/CHANGES.rst index 3ae6154..43fc9f6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,12 @@ Unreleased becomes 2.0.0 once every template is at 2.0.0. ``--check`` changes nothing and exits with 1 when there are files to write. * ``tfmgr add`` writes the generated files of the template before validating it. +* New command ``tfmgr migrate headers ARCHIVE [--needs] [-o TSV]`` reads, with nibabel, the + facts of image headers that the migration to TemplateFlow 2.0 needs (grids of volumes + without ``res``, volumes of 4D probabilistic segmentations, GIFTI intents), from an + Archive checkout whose image data are present (``--needs`` lists the files to fetch). + The table is keyed by md5, so migration plans need no image data. Snapshots of + templates, from the v2 skeleton zip or from a checkout, have the same fingerprint. * New internals for ``tfmgr generate`` and ``tfmgr migrate``: ``GitTree`` reads a template from a git commit without checking it out, ``collect_archive`` gathers what the Archive's files and checks need from its templates, and ``renames_problems`` checks a diff --git a/tfmanager/cli.py b/tfmanager/cli.py index 4ca1d50..a8902c3 100644 --- a/tfmanager/cli.py +++ b/tfmanager/cli.py @@ -234,6 +234,79 @@ def generate(kind, path, check): raise SystemExit(1 if check and found else 0) +@cli.group() +def migrate(): + """Move the Archive's templates to TemplateFlow 2.0 (names and metadata).""" + + +@migrate.command() +@click.argument('archive', type=click.Path(exists=True, file_okay=False), default='.') +@click.option( + '-t', '--template', 'templates', multiple=True, help='Only this template (tpl-