← 输入框|github.com|刷新
Skip to content

feat: TemplateFlow 2.0 rule set and tfmgr validate - #13

Merged
oesteban merged 3 commits into
masterfrom
feat/validate
Dec 2, 2026
Merged

oesteban merged 3 commits into
masterfrom
feat/validate

Conversation

@oesteban

@oesteban oesteban commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

A machine-readable rule set for TemplateFlow 2.0, and tfmgr validate to enforce it.

tfmanager/
├── schema/
│   ├── bids-1.11.0.json        # vendored BIDS schema: entity order, suffixes
│   ├── entities.yaml           # allowed entities, value formats, client regexes
│   ├── suffixes.yaml           # suffixes by kind, with their extensions
│   ├── files.yaml              # layout of tpl-<label>/
│   ├── rules.yaml              # 69 rules: TF### code, slug, severity, legacy severity, fix
│   └── template_description.schema.json
├── naming.py                   # parse / serialize names in BIDS order
├── tree.py                     # directory (never follows symlinks), skeleton zip, in-memory
├── licenses.py                 # SPDX expressions, LICENSE header line
├── generate.py                 # atlas descriptions, cohorts.tsv, templates.tsv
└── validate/                   # TF1xx names ... TF8xx Archive; human/json/github/markdown
tfmgr validate PATH... [--mode auto|strict|legacy] [--level names|metadata|content]
                       [--format human|json|github|markdown]
  auto: legacy for templates older than TemplateFlowVersion 2.0.0
  exit 0 = no errors, 1 = errors, 2 = could not run
  • Licenses are SPDX expressions (LicenseRef-<Name> for custom terms). LICENSE starts with SPDX-License-Identifier: <License>, and licenses of parts of a template keep their text in docs/licenses/. GPL-family licenses are rejected for data (TF508).
  • Atlases are described in tpl-<label>_atlases.tsv (bids-specification#2286 columns, plus readme and derived_from_atlas), which generates the BIDS 1.11 atlas-<label>_description.json.
  • The core no longer installs DataLad or nibabel: tfmanager[add] and tfmanager[content] do.

Evidence

  • Before: no validator. CI builds the package and runs no tests.
  • After: 130 tests (one case per rule, plus content checks on synthetic images, CLI, symlink safety, and rule-set integrity against bidsschematools), on Python 3.10 and 3.12. The legacy snapshot of the Archive (skeleton at python-client@597b047) reproduces the audit:
$ tfmgr validate --mode legacy templateflow-skel.zip --format markdown
**Validation passed**: 0 errors, 2674 warnings (rule set 2.0.0, legacy mode).
TF103 entity-order 1153 | TF108 missing-suffix 831 | TF111 missing-entity 163 | ...

The whole Archive validates in under a second.

Merge Danger

Door: two-way

Nothing calls tfmgr validate yet: wiring it into intake previews, actions-intake and the Archive's CI comes next.

Blast Radius: packaging

pip install tfmanager no longer brings DataLad: anyone running tfmgr add needs tfmanager[add]. The actions-intake image installs DataLad itself, and will switch to tfmanager[add].

oesteban and others added 3 commits December 2, 2026 15:30
The validator only needs click, jsonschema, license-expression and PyYAML.
`tfmanager[add]` brings DataLad, nibabel and the client for `tfmgr add`;
`tfmanager[content]` brings nibabel for image checks. Ruff is configured
for the new modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule set (tfmanager/schema) describes names, layout, metadata, lookup
tables, licenses and atlases as YAML and JSON Schema. The entity order is
derived from a vendored copy of the BIDS 1.11.0 schema. Each of the 69 rules
has a code (TF101...), a slug, a severity and a legacy severity.

`tfmgr validate` checks template directories, Archive checkouts and skeleton
zips without annexed content; `--level content` opens images. Templates
older than TemplateFlowVersion 2.0.0 are checked in legacy mode, where naming
problems are warnings: the current Archive passes with 0 errors and the 1153
entity-order deviations found by the audit.

Licenses are SPDX expressions (license-expression), and LICENSE files start
with an `SPDX-License-Identifier:` line. Atlases are described in
tpl-<label>_atlases.tsv (bids-specification#2286), which generates the BIDS
atlas descriptions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oesteban
oesteban marked this pull request as ready for review December 2, 2026 15:49
@oesteban
oesteban marked this pull request as ready for review December 2, 2026 15:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T15:56:00.593148Z 05c3853 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@oesteban
oesteban merged commit 74efd92 into master Dec 2, 2026
6 checks passed
@oesteban
oesteban deleted the feat/validate branch December 2, 2026 15:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05c38533e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +33 to +35
local = ctx.tree.local_path(path)
if local is None:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report images skipped during content validation

When --level content is used on a normal DataLad checkout without --trusted, or on a skeleton zip, local_path() returns None for annexed images. This branch skips them without reporting that their content was not checked, so validation can exit successfully even though none of the image checks ran. Report unavailable image data instead of silently continuing.

Useful? React with 👍 / 👎.

Comment on lines +47 to +49
desc = ctx.description
if desc is None:
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject non-object template descriptions before aggregation

When template_description.json contains valid JSON with a non-object top-level value, such as [], ctx.description is None and this return suppresses the schema error. During Archive validation, check_archive still aggregates that value and templates_table() later calls .get() on it, aborting the run instead of reporting the invalid description. Report the top-level type error and exclude invalid values from aggregation.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05c38533e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

f'Identifier {desc.get("Identifier")!r} does not match {ctx.tree.name}.',
)

for ref in desc.get('ReferencesAndLinks') or []:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard references before iterating

When ReferencesAndLinks has a non-list value, such as a JSON number, schema validation records an issue but this loop still iterates the value; an integer raises TypeError, so tfmgr validate exits through the internal-error path instead of returning its validation findings. Only process DOI entries when the field is a list.

Useful? React with 👍 / 👎.

Comment thread tfmanager/generate.py
if value in ('', NA, None):
continue
if column in ATLAS_ARRAYS or column == 'species':
value = json_cell(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep malformed atlas arrays from aborting validation

When an atlas TSV array cell starts with [ but is not valid JSON, the earlier check reports TF604, but json_cell raises ValueError while generating the expected description. The CLI then exits with an internal error rather than returning the validation findings; avoid generating from invalid cells or handle the parse failure here.

Useful? React with 👍 / 👎.

Comment on lines +116 to +117
if (root / template).is_dir() and any((root / template).iterdir()):
if (root / old).is_symlink() or (root / old).exists():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check that renamed destinations exist

For an installed, nonempty template, this branch only checks whether old still exists. A misspelled or removed new_path therefore passes TF804, even though clients resolving the old path will be directed to a nonexistent file. Check the destination in this branch as well.

Useful? React with 👍 / 👎.

return ZipTree.templates(path)
if path.name.startswith('tpl-'):
return [DirectoryTree(path, trusted=trusted)]
found = sorted(p for p in path.iterdir() if p.is_dir() and p.name.startswith('tpl-'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject symlinked template roots during Archive discovery

When an Archive contains a tpl-* symlink to a directory outside the checkout, Path.is_dir() follows it and passes it to DirectoryTree; scanning that root then reads files outside the template even without --trusted. Exclude symlinks or verify that each discovered template root is a real directory before constructing its tree.

Useful? React with 👍 / 👎.

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