diff --git a/CHANGES.rst b/CHANGES.rst index 68421a8..28495d9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,12 +11,27 @@ Unreleased 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 + facts of image headers that the migration to TemplateFlow 2.0 needs (the grid of every + volume, 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; the facts of the Archive are shipped with tfmanager (``migrate/data/headers-2.0.0.tsv``). Snapshots of templates, from the v2 skeleton zip or from a checkout, have the same fingerprint. +* The new names of the migration to TemplateFlow 2.0: ``tfmanager.migrate.names`` renames + the files of a template (rules R01 to R20, then R99) from its snapshot, the header facts + and the decisions of ``migrate/config/2.0.0.yaml`` (atlas labels, renames of single + templates, ``res`` keys). Every volume takes the ``res`` key of its grid: blocks that no + file matches are rebuilt from their files, and volumes off their block take a new key. + Findings M101 to M113 block a plan (uncovered names come with a decision to fill in), + and ``migrate.renames`` merges and checks a template's ``.renames.tsv`` as the template + action reads it. A test pins the renames of the Archive + (``tests/data/renames-2.0.0.tsv``). +* New warning TF118 redundant-entity: a ``desc``, ``seg`` or ``label`` that tells its file + apart from no other file of the template (``res``, ``den``, ``hemi`` and ``cohort`` + aside). Masks keep ``desc``, probabilistic segmentations keep ``label``, and + ``desc-brain`` and the ``desc-tissues`` of tissue maps are always kept. +* ``probseg`` and ``midthickness`` take ``.shape.gii`` (probabilities and vertex areas on + a surface). * 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/setup.cfg b/setup.cfg index c5befb1..eea0f89 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,8 @@ tfmanager = schema/*.json schema/*.yaml migrate/data/*.tsv + migrate/config/*.yaml + migrate/config/*.json [options.packages.find] exclude = diff --git a/tfmanager/migrate/config.py b/tfmanager/migrate/config.py new file mode 100644 index 0000000..88c2559 --- /dev/null +++ b/tfmanager/migrate/config.py @@ -0,0 +1,172 @@ +"""The decisions of a migration (``migrate/config/.yaml``), checked before use.""" + +from __future__ import annotations + +import hashlib +import json +import re +from dataclasses import dataclass, field +from importlib.resources import files +from pathlib import Path + +import jsonschema +import yaml + +from ..ruleset import load_ruleset +from ..validate.names import VERSION_LABEL + +CONFIG_DIR = files('tfmanager.migrate') / 'config' +NAME_KEYS = ('suffix', 'extension') + + +class ConfigError(ValueError): + """A config that breaks its schema or contradicts itself.""" + + +@dataclass(frozen=True) +class Rename: + """A decision about files of one template (``renames``).""" + + id: str + template: str + match: dict + count: int + why: str + set: dict = field(default_factory=dict) + remove: bool = False + + def matches(self, entities: dict, suffix: str | None, extension: str) -> bool: + have = {**entities, 'suffix': suffix, 'extension': extension} + for key, want in self.match.items(): + value = have.get(key) + if want is None and value is not None: + return False + if isinstance(want, str) and value != want: + return False + if isinstance(want, list) and value not in want: + return False + return True + + +@dataclass(frozen=True) +class Config: + version: str + policies: dict + atlas_labels: tuple[dict, ...] = () + renames: tuple[Rename, ...] = () + res_assign: dict = field(default_factory=dict) + """``tpl-