Skip to content

feat: tfmgr generate writes the files generated from metadata - #19

Merged
oesteban merged 2 commits into
masterfrom
feat/generate
Dec 4, 2026
Merged

oesteban merged 2 commits into
masterfrom
feat/generate

Conversation

@oesteban

@oesteban oesteban commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Second of seven PRs for WP4 of Archive 2.0. Stacked on #18 (base refactor/archive-collector; it retargets to master when that one merges).

tfmgr generate KIND [PATH] [--check]
  PATH = tpl-<label>/                 KIND atlases | cohorts | all
    atlases   atlas-<label>_description.json  for each row of tpl-<label>_atlases.tsv
    cohorts   tpl-<label>_cohorts.tsv (+ .json) from template_description.json "cohort"
  PATH = Archive root                 KIND templates | dataset | all  (atlases/cohorts: every template)
    templates templates.tsv
    dataset   dataset_description.json
  files no longer generated are deleted
  --check: change nothing; exit 1 when there are files to write; errors exit 2
 tfmgr add
   copy: mirror the source, write template_description.json, LICENSE, CHANGES
+        write the generated files (as `tfmgr generate all`)
   validate (strict)

The files are the strings the validator already compares against (TF410, TF607, TF801), written atomically; an annex link at a generated path is replaced by a regular file.

For your approval: the Archive's dataset_description.json (what tfmgr generate dataset writes on today's Archive):

{
  "Name": "TemplateFlow",
  "BIDSVersion": "1.11.0",
  "DatasetType": "derivative",
  "TemplateFlowVersion": "1.0.0",
  "License": "LicenseRef-TemplateFlow-PerTemplate",
  "GeneratedBy": [{"Name": "tfmanager", "CodeURL": "https://github.com/templateflow/python-manager"}],
  "ReferencesAndLinks": ["https://doi.org/10.1038/s41592-022-01681-2"]
}
  • TemplateFlowVersion becomes 2.0.0 only when every registered template is installed and at 2.0.0; otherwise it keeps its current value. This value switches the Archive's checks (TF8xx) to strict mode, so it flips with the last migrated template.
  • No tfmanager version in GeneratedBy, so --check does not fail after every tfmanager release.
  • The root has no LICENSE today; LicenseRef-TemplateFlow-PerTemplate needs one that points to each template's LICENSE. It belongs with the superdataset workflow that will run this command (after rc5).

Evidence

  • tfmgr generate all ~/tmp/templateflow --check on today's Archive: would update dataset_description.json, would create templates.tsv, exit 1. tfmgr generate all tpl-MNIInfant --check: would create tpl-MNIInfant_cohorts.json and .tsv, exit 1. tpl-MNI152NLin2009cSym: Up to date., exit 0. tfmgr generate templates tpl-MNIInfant: exit 2. Nothing was written.
  • New test_generate.py (21 tests):
    • the strict-valid test template is up to date;
    • generating removes TF607 and TF410, and deletes orphan descriptions and cohorts tables;
    • an annexed output is replaced by a regular file;
    • generating at the root removes TF801;
    • the version flips only with the last template (a description that is not JSON blocks it);
    • uninstalled templates are refused;
    • the CLI's exit codes and output.
  • test_add.py::test_generated_files_are_written: a submission without its atlas description passes strict validation. Without the add.py change the test fails.
  • Generated files are deleted only when readable metadata says they are not generated. A description that is missing, annexed, not JSON or not an object, a cohort that is not an object, an atlases table that cannot be read or has no atlas_id column, and a row that cannot become a description (malformed JSON cell, or an atlas_id that is not a label) stop the command with exit 2 and touch nothing (test_unreadable_metadata, test_malformed_atlas_row; all fail without 71bd7b6).
  • tfmgr generate atlases ~/tmp/templateflow --check: Up to date. for all 30 templates. tfmgr generate cohorts stops at tpl-dhcpAsym, whose cohort ages are numbers rather than [min, max] (as before 71bd7b6).
  • CI only runs for pull requests into master, so this stacked PR has no checks. The CI job, run locally on a clean worktree of 71bd7b6:
    • Python 3.13.7: ruff check . clean; pytest -o addopts="" --doctest-modules tfmanager: 208 passed.
    • Python 3.15.0rc2: ruff check . clean; 208 passed.
    • sdist and wheel build; twine check passed.

Merge Danger

Door: two-way

Blast Radius: CLI

A new command. tfmgr add now writes atlas descriptions and cohorts tables into the dataset it builds, replacing stale copies from the submission. Nothing runs tfmgr generate on the Archive yet.

Base automatically changed from refactor/archive-collector to master December 4, 2026 09:08
@oesteban
oesteban marked this pull request as ready for review December 4, 2026 09:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 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-04T09:13:49.641950Z 1ce8184 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.

`tfmgr generate atlases|cohorts|templates|dataset|all [--check] [PATH]`:

- in a template, the atlas descriptions (one per row of the atlases table)
  and the cohorts table with its sidecar (from the cohort block of
  template_description.json); descriptions and tables no longer generated
  are deleted;
- at the root of the Archive, templates.tsv and dataset_description.json
  (BIDS 1.11, DatasetType derivative, License
  LicenseRef-TemplateFlow-PerTemplate). Its TemplateFlowVersion becomes 2.0.0
  only once every template is at 2.0.0, since that switches the Archive's
  checks to strict mode; no tfmanager version is recorded, so the file does
  not change when tfmanager does. Every registered template must be
  installed, or templates.tsv would leave it out.

The files are the strings the validator compares against (TF410, TF607,
TF801), written atomically (an annex link is replaced by a regular file).
`--check` changes nothing and exits with 1 when there are files to write;
errors exit with 2. `tfmgr add` writes the generated files before its strict
validation, so contributors only write the atlases table and
template_description.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: 1ce81840f0

ℹ️ 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 thread tfmanager/generate.py Resolved
template_outputs deleted the cohorts table when template_description.json
was valid JSON but not an object (such as `[]`), and every atlas description
when the atlases table was annexed, too large or had no atlas_id column. It
now raises GenerateError (exit 2) when:

- template_description.json is missing, annexed, too large, not JSON or not
  an object, or its "cohort" is neither absent, null nor an object;
- the atlases table exists but cannot be read, or has no atlas_id column;
- a row cannot become a description: a malformed JSON cell (this crashed
  with a traceback) or an atlas_id that is not a label (it could name a path
  outside the template).

Files are deleted only when readable metadata says they are not generated:
no atlases table, no row for a description, or no cohort block (absent,
null or empty).

Reported by the Codex review of #19.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oesteban
oesteban merged commit bd8fae3 into master Dec 4, 2026
6 checks passed
@oesteban
oesteban deleted the feat/generate branch December 4, 2026 12:17
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