Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 106 additions & 4 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,109 @@ Examples
--------
Listing all the compressed NIfTI files in ``fsaverage``::

$ templateflow ls fsaverage -x .nii.gz
~/.cache/templateflow/tpl-fsaverage/tpl-fsaverage_res-01_den-41k_T1w.nii.gz
~/.cache/templateflow/tpl-fsaverage/tpl-fsaverage_res-01_desc-brain_mask.nii.gz
~/.cache/templateflow/tpl-fsaverage/tpl-fsaverage_res-01_T1w.nii.gz
$ templateflow ls fsaverage -x .nii.gz
~/.cache/templateflow/tpl-fsaverage/tpl-fsaverage_res-01_den-41k_T1w.nii.gz
~/.cache/templateflow/tpl-fsaverage/tpl-fsaverage_res-01_desc-brain_mask.nii.gz
~/.cache/templateflow/tpl-fsaverage/tpl-fsaverage_res-01_T1w.nii.gz

Showing the configuration
-------------------------
``templateflow config`` prints the settings the client runs with::

$ templateflow config
Current TemplateFlow settings:

TEMPLATEFLOW_HOME=/home/user/.cache/templateflow
TEMPLATEFLOW_USE_DATALAD=off
TEMPLATEFLOW_AUTOUPDATE=on

Home layout: v2

The home layout is ``v2`` for home folders created by templateflow 26.0 or
migrated to the TemplateFlow 2.0 names, ``legacy`` for those created by older
clients, and ``DataLad`` in DataLad mode.

The command only reports these values.
They come from environment variables, read each time the client starts,
so a change applies to the commands run after it::

$ export TEMPLATEFLOW_HOME=$HOME/data/templateflow

:doc:`installation` describes each variable.
In Python, :class:`~templateflow.client.TemplateFlowClient` also takes these
settings as arguments, for example ``TemplateFlowClient(use_datalad=True)``.

Updating the Archive
--------------------
``templateflow update`` brings the home folder up to date with the Archive.
In the default mode (direct download), the home follows the Archive's skeleton:
every file of every template, with the text files complete and empty
placeholders for images and surfaces.
Data are downloaded later, when ``templateflow get`` or the Python client
asks for them.

In ``v2`` homes, the command makes the home match the skeleton: it adds missing
files, refreshes text files, prunes placeholders of names the Archive no longer
uses, and turns downloads the Archive changed back into placeholders, so that
they are downloaded again when needed.
Other downloads are kept.
It prints what changed, or that nothing did::

$ templateflow update
Updating TEMPLATEFLOW_HOME using S3. Changes: 13 added.
Successfully updated local TemplateFlow Archive: /home/user/.cache/templateflow.

$ templateflow update
TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.
TemplateFlow Archive not updated.

``legacy`` homes keep the names older clients use, so that those clients can
still share them.
There, the command adds the files the home is missing and keeps those it
already has::

$ templateflow update
Updating TEMPLATEFLOW_HOME using S3. Adding:
tpl-Fischer344/
tpl-Fischer344/template_description.json
...
Successfully updated local TemplateFlow Archive: /home/user/.cache/templateflow.

The list shows every file of the skeleton, including those the home already has.
With ``--no-overwrite`` it shows only the files added, and the command prints
``TemplateFlow Archive not updated.`` when there are none.
``--no-overwrite`` has no effect in ``v2`` homes.

``--migrate`` moves a ``legacy`` home to the TemplateFlow 2.0 names, making it a
``v2`` home: placeholders of old names are removed, and files downloaded under an
old name move to the new one when their checksum matches.
Older clients sharing the home lose the old names until they update it::

$ templateflow update --migrate
Updating TEMPLATEFLOW_HOME using S3. Changes: 1 added.
Successfully updated local TemplateFlow Archive: /home/user/.cache/templateflow.

``--local`` does not download the latest skeleton: a ``v2`` home applies the
skeleton it already follows, and a ``legacy`` home the one that comes with the
installed client.

In DataLad mode, the command runs ``datalad update --merge`` recursively from
``origin``, which brings in the new commits of the superdataset and of every
template.
``--migrate`` has no effect there.

Wiping the home folder
----------------------
``templateflow wipe`` deletes the home folder and everything downloaded into it.
It asks twice first: once to confirm, and once to type the folder's path::

$ templateflow wipe
This will wipe out all data downloaded into /home/user/.cache/templateflow.
Do you want to continue? [y/N]: y
Please write the path of your local archive (/home/user/.cache/templateflow): /home/user/.cache/templateflow
/home/user/.cache/templateflow was wiped out.

The next ``templateflow`` command sets the home folder up again, with the
skeleton and no data.
In DataLad mode nothing is deleted: the command prints
``TemplateFlow is configured in DataLad mode, wipe() has no effect``.
16 changes: 16 additions & 0 deletions docs/datalad.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ Therefore, it is possible (and recommended for those who want to
leverage the power of DataLad) to access the Archive using just
DataLad.

.. tip:: Prefer the Python client for routine access

The high-level :class:`templateflow.client.TemplateFlowClient` can be
configured with ``use_datalad=True`` (or with the environment variable
``TEMPLATEFLOW_USE_DATALAD=on``) to transparently manage the cache with
DataLad. This is a good default when you want TemplateFlow to perform
``datalad get`` and ``datalad update`` commands automatically while still
interacting with the archive through the familiar client API.

.. note:: Drop down to raw DataLad when you need full control

Advanced workflows, such as pinning remotes, creating custom siblings or
operating entirely offline, are better served by running DataLad commands
directly. In those scenarios leave ``use_datalad`` disabled in the client
and use the instructions below to operate on the repository yourself.

Installing the Archive
----------------------
The archive is indexed by a superdataset, which can be installed with::
Expand Down
2 changes: 2 additions & 0 deletions templateflow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"""TemplateFlow's Python Client.

``templateflow.api`` provides a global, high-level interface to query the TemplateFlow archive.
Its functions keep the signatures of the original module-level helpers, and delegate to
one shared :class:`~templateflow.client.TemplateFlowClient`.

There are two methods to initialize a client:

Expand Down
8 changes: 7 additions & 1 deletion templateflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
#
# https://www.nipreps.org/community/licensing/
#
"""TemplateFlow's Python Client."""
"""TemplateFlow's Python Client.

:class:`TemplateFlowClient` is the object-oriented interface to the TemplateFlow archive.
Each client has its own cache configuration (home folder, S3 or DataLad), while
:mod:`templateflow.api` shares one client set up from environment variables. Code written
for the module-level functions can move to a client without changing its queries.
"""

from __future__ import annotations

Expand Down
9 changes: 8 additions & 1 deletion templateflow/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
"""Configuration and settings."""
"""Configuration and settings.

``templateflow.conf`` holds the global cache that :mod:`templateflow.api` uses, and the
module-level helpers that act on it: :func:`setup_home`, ``update()`` and ``wipe()``.
The cache itself is a :class:`~templateflow.conf.cache.TemplateFlowCache`, configured by a
:class:`~templateflow.conf.cache.CacheConfig`; create one of these to manage another home
folder, and keep the module-level helpers for the global cache.
"""

from functools import wraps
from warnings import warn
Expand Down
7 changes: 7 additions & 0 deletions templateflow/conf/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#
# https://www.nipreps.org/community/licensing/
#
"""The cache of a TemplateFlow home folder.

:class:`CacheConfig` says where the home folder is and how it is filled;
:class:`TemplateFlowCache` installs, updates and wipes it, through :class:`S3Manager` or,
when DataLad is enabled, :class:`DataladManager`.
"""

from __future__ import annotations

import re
Expand Down
Loading