diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 23bf26f..50a53ed 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -10,6 +10,24 @@ on: branches: [ master ] jobs: + test: + runs-on: ubuntu-26.04 + strategy: + matrix: + python-version: ['3.10', '3.12'] + steps: + - uses: actions/checkout@v7 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v7 + with: + python-version: ${{ matrix.python-version }} + - name: Install with test dependencies + run: python -m pip install ".[test]" ruff + - name: Lint + run: ruff check . + - name: Test + run: python -m pytest -o addopts="" --doctest-modules tfmanager + build: runs-on: ubuntu-26.04 diff --git a/CHANGES.rst b/CHANGES.rst index caf7571..5ea6d03 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,5 +1,18 @@ Unreleased ========== +TemplateFlow 2.0 rule set and validator. + +* New ``tfmgr validate`` checks templates (directories, Archive checkouts or skeleton zips) + against the TemplateFlow 2.0 rule set: names in BIDS 1.11 order, layout, metadata, + lookup tables, SPDX licenses, atlases and, with ``--level content``, image headers and + values. Rules have stable codes (``TF101``...) and slugs; ``--mode legacy`` (the + default for templates older than TemplateFlowVersion 2.0.0) reports naming problems + as warnings. Output as text, JSON, GitHub annotations or Markdown. +* The rule set lives in ``tfmanager/schema/`` as YAML and JSON Schema, with a vendored + copy of the BIDS 1.11.0 schema; the website renders its documentation from them. +* The core package no longer needs DataLad, nibabel or the TemplateFlow client: install + ``tfmanager[add]`` to add templates, ``tfmanager[content]`` for image checks. + Farewell to OSF: OSF no longer accepts uploads, and the TemplateFlow submission pipeline now stores the data of new templates on GIN (https://gin.g-node.org). diff --git a/README.rst b/README.rst index f999bf9..23f9832 100644 --- a/README.rst +++ b/README.rst @@ -2,3 +2,21 @@ The TemplateFlow Archive manager ================================ This tool eases the processes of adding new templates and updating existing one in the `TemplateFlow Archive `__. + +Validating a template +--------------------- +``tfmgr validate`` checks templates against the TemplateFlow rule set +(``tfmanager/schema/``):: + + pip install tfmanager + tfmgr validate tpl-MyTemplate # a template directory + tfmgr validate path/to/templateflow # every template of an Archive checkout + tfmgr validate --format json -o report.json tpl-MyTemplate + +Templates older than TemplateFlowVersion 2.0.0 are checked in legacy mode, where naming +problems are warnings (``--mode strict`` or ``--mode legacy`` override it). Image headers +and values are only checked with ``--level content``, which needs ``tfmanager[content]`` +and the images' data. The command exits with 1 when there are errors, and 2 when it +could not run. + +Adding a template needs DataLad and the TemplateFlow client: ``pip install tfmanager[add]``. diff --git a/pyproject.toml b/pyproject.toml index accf07a..07cb122 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,3 +8,15 @@ write_to_template = """\ __version__ = "{version}" """ fallback_version = "0.0" + +[tool.ruff] +line-length = 99 +extend-exclude = ["docs", "tfmanager/_version.py"] + +[tool.ruff.format] +quote-style = "single" + +[tool.ruff.lint] +select = ["E", "F", "W", "I", "UP", "B"] +# cli.py, io.py and utils.py predate the linter +per-file-ignores = { "{setup.py,tfmanager/cli.py,tfmanager/io.py,tfmanager/utils.py}" = ["E", "W", "I", "UP", "B"] } diff --git a/setup.cfg b/setup.cfg index 4ce7304..10a5b69 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,17 +25,18 @@ setup_requires = setuptools_scm >= 8 toml install_requires = - click - datalad >= 0.16 - nibabel - numpy - templateflow >= 0.4.2 + click >= 8 + jsonschema >= 4.18 + license-expression >= 30.3 + pyyaml >= 6 toml packages = find: [options.package_data] tfmanager = data/*.LICENSE + schema/*.json + schema/*.yaml [options.packages.find] exclude = @@ -46,6 +47,19 @@ console_scripts = tfmgr=tfmanager.cli:cli [options.extras_require] +# Adding templates (tfmgr add, sanitize) and image checks (tfmgr validate --level content) +add = + datalad >= 0.16 + nibabel + numpy + templateflow >= 0.4.2 +content = + nibabel + numpy +test = + bidsschematools == 1.2.0 + pytest + %(content)s doc = nbsphinx packaging diff --git a/tfmanager/cli.py b/tfmanager/cli.py index 43b5f9f..feb17c8 100644 --- a/tfmanager/cli.py +++ b/tfmanager/cli.py @@ -359,6 +359,64 @@ def add( del os.environ["DATALAD_CREDENTIAL_GIN_TOKEN"] +@cli.command() +@click.argument("paths", nargs=-1, type=click.Path(exists=True)) +@click.option( + "--mode", + type=click.Choice(("auto", "strict", "legacy")), + default="auto", + show_default=True, + help="strict: TemplateFlow 2.0 rules; legacy: naming problems are warnings; " + "auto: legacy for templates older than TemplateFlowVersion 2.0.0.", +) +@click.option( + "--level", + type=click.Choice(("names", "metadata", "content")), + default="metadata", + show_default=True, + help="content opens images (needs their data and tfmanager[content]).", +) +@click.option( + "--format", + "fmt", + type=click.Choice(("human", "json", "github", "markdown")), + default="human", + show_default=True, +) +@click.option("--archive/--no-archive", default=None, help="Also check the Archive (TF8xx).") +@click.option("--show-info", is_flag=True, help="Also show informational issues.") +@click.option( + "--trusted", + is_flag=True, + help="Follow git-annex links to open image data (do not use on untrusted clones).", +) +@click.option("-o", "--output", type=click.Path(dir_okay=False, writable=True)) +def validate(paths, mode, level, fmt, archive, show_info, trusted, output): + """Validate templates against the TemplateFlow rule set. + + PATHS are template directories (tpl-