Repository navigation
feat: TemplateFlow 2.0 rule set and tfmgr validate - #13
Conversation
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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| local = ctx.tree.local_path(path) | ||
| if local is None: | ||
| continue |
There was a problem hiding this comment.
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 👍 / 👎.
| desc = ctx.description | ||
| if desc is None: | ||
| return |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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 []: |
There was a problem hiding this comment.
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 👍 / 👎.
| if value in ('', NA, None): | ||
| continue | ||
| if column in ATLAS_ARRAYS or column == 'species': | ||
| value = json_cell(value) |
There was a problem hiding this comment.
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 👍 / 👎.
| if (root / template).is_dir() and any((root / template).iterdir()): | ||
| if (root / old).is_symlink() or (root / old).exists(): |
There was a problem hiding this comment.
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-')) |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
A machine-readable rule set for TemplateFlow 2.0, and
tfmgr validateto enforce it.LicenseRef-<Name>for custom terms). LICENSE starts withSPDX-License-Identifier: <License>, and licenses of parts of a template keep their text indocs/licenses/. GPL-family licenses are rejected for data (TF508).tpl-<label>_atlases.tsv(bids-specification#2286 columns, plusreadmeandderived_from_atlas), which generates the BIDS 1.11atlas-<label>_description.json.tfmanager[add]andtfmanager[content]do.Evidence
bidsschematools), on Python 3.10 and 3.12. The legacy snapshot of the Archive (skeleton at python-client@597b047) reproduces the audit:The whole Archive validates in under a second.
Merge Danger
Door: two-way
Nothing calls
tfmgr validateyet: wiring it into intake previews, actions-intake and the Archive's CI comes next.Blast Radius: packaging
pip install tfmanagerno longer brings DataLad: anyone runningtfmgr addneedstfmanager[add]. The actions-intake image installs DataLad itself, and will switch totfmanager[add].