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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Environment variable ``TemplateFlowClient`` keyword Purpose
============================== ============================== ==============================================
``TEMPLATEFLOW_HOME`` ``root`` Cache directory for downloaded templates.
``TEMPLATEFLOW_USE_DATALAD`` ``use_datalad`` Opt-in to DataLad-backed cache management.
``TEMPLATEFLOW_AUTOUPDATE`` ``autoupdate`` Allow automatic cache updates on import/use.
``TEMPLATEFLOW_AUTOUPDATE`` ``autoupdate`` Accepted, but currently has no effect.
============================== ============================== ==============================================

Publishing resources in the *TemplateFlow* Archive
Expand Down
168 changes: 134 additions & 34 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,139 @@ You should see the version number.

Settings
--------
The *TemplateFlow Client* has two modes of operation: (a) based on
`DataLad <https://datalad.org>`__, or (b) direct downloads from Amazon S3.
Each :class:`~templateflow.client.TemplateFlowClient` takes its settings as
arguments, and three of them have an environment variable that sets their
default.
``templateflow.api``, the command-line interface and the helpers of
:mod:`templateflow.conf` share one default client, configured from these
variables only; :mod:`templateflow.conf` exposes its settings as the attributes
in the last column.

.. list-table:: ``TemplateFlowClient`` settings
:header-rows: 1

* - Argument
- Environment variable
- Default
- Default client's value
* - ``root``
- ``TEMPLATEFLOW_HOME``
- ``platformdirs.user_cache_dir('templateflow')`` (e.g., ``~/.cache/templateflow``)
- ``templateflow.conf.TF_HOME``
* - ``use_datalad``
- ``TEMPLATEFLOW_USE_DATALAD``
- ``False`` (automatically disabled if DataLad is not installed)
- ``templateflow.conf.TF_USE_DATALAD``
* - ``autoupdate``
- ``TEMPLATEFLOW_AUTOUPDATE``
- ``True`` (currently has no effect)
- ``templateflow.conf.TF_AUTOUPDATE``
* - ``timeout``
- *(none)*
- ``10`` seconds
- ``templateflow.conf.TF_GET_TIMEOUT``
* - ``origin`` (DataLad)
- *(none)*
- ``https://github.com/templateflow/templateflow.git``
- ``templateflow.conf.TF_GITHUB_SOURCE``
* - ``s3_root`` (direct download)
- *(none)*
- ``https://templateflow.s3.amazonaws.com``
- ``templateflow.conf.TF_S3_ROOT``

A client created with other arguments leaves these attributes unchanged:
read its own settings from ``client.cache.config``.

Cache location
~~~~~~~~~~~~~~
The client stores downloads in a writable folder, the TemplateFlow home, which
defaults to the platform's cache directory.
Point ``templateflow.api`` and the command-line interface to another folder by
exporting ``TEMPLATEFLOW_HOME`` before they start:

.. code-block:: console

$ export TEMPLATEFLOW_HOME=$DATA/.templateflow
$ templateflow config

.. code-block:: python

from templateflow.client import TemplateFlowClient

client = TemplateFlowClient(root="/data/templateflow")
print(client.cache.config.root)

DataLad mode
~~~~~~~~~~~~
Two backends are available: direct download from Amazon S3 (the default) and a
DataLad dataset.
Setting ``TEMPLATEFLOW_USE_DATALAD=on`` switches ``templateflow.api`` and the
command-line interface into DataLad mode (they fall back to direct download if
DataLad is not installed), and ``templateflow config`` shows the mode in use.

.. code-block:: console

$ export TEMPLATEFLOW_USE_DATALAD=on
$ templateflow config

.. code-block:: python

from templateflow.client import TemplateFlowClient

client = TemplateFlowClient(root="/data/tf-datalad", use_datalad=True)
client.cache.ensure()
print(client.cache.config.use_datalad)

The client installs the DataLad dataset only into an empty or missing home
folder.
To switch an existing home from direct download to DataLad, delete it first,
with ``templateflow wipe`` while still in direct-download mode (in DataLad mode
it deletes nothing) or with ``rm -r``.

Mirrors and DataLad sources
~~~~~~~~~~~~~~~~~~~~~~~~~~~
In direct-download mode, files are downloaded from ``s3_root``.
The default client's mirror is ``templateflow.conf.TF_S3_ROOT``:

.. code-block:: console

$ python -c "from templateflow.conf import TF_S3_ROOT; print(TF_S3_ROOT)"
https://templateflow.s3.amazonaws.com

.. code-block:: python

from templateflow.client import TemplateFlowClient

mirror = TemplateFlowClient(s3_root="https://my-mirror.s3.amazonaws.com")
print(mirror.cache.config.s3_root)

Skeletons (the Archive's lists of files) come from GitHub whatever ``s3_root``
is: ``TEMPLATEFLOW_SKEL_URL`` replaces their base URL (see below).

In DataLad mode, ``origin`` is the dataset a new home is installed from.
An existing home keeps the source it was installed from, and updates from it.

Updates, timeouts, and the index of the home
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``autoupdate`` (``TEMPLATEFLOW_AUTOUPDATE``) is accepted, but currently has no
effect.
A new home is set up from the skeleton that comes with the client, without
network access, and existing homes are not updated automatically: run
``templateflow update`` (or :func:`templateflow.conf.update`) to follow the
Archive.

Network operations time out after 10 seconds by default.
Pass another ``timeout`` to ``TemplateFlowClient``; the default client's value
is ``templateflow.conf.TF_GET_TIMEOUT``.

Each client indexes its home folder the first time a query needs it
(``templateflow.conf.TF_LAYOUT`` for the default client), and indexes it again
after an update that changed the home.
If the home changes by other means while a program runs (for example, a
``datalad update`` run by hand), restart the program to see the changes.

By default, the client will operate in direct download mode (b) which is
more lightweight and comes with some limitations, as all the advanced
version control management afforded by DataLad will not be available.

For the most part, and considering that templates/atlases do not substantially
change over time, the direct download mode should be sufficient to anyone
developing new pipelines and tools, as it will provided the latest version
of any available template set.

**TemplateFlow "home" folder**.
The lazy-loading implementation of the client requires some folder on the host
where template resources can be stored (therefore, write permissions are
required). By default, the home folder will be ``$HOME/.cache/templateflow``.
This setting can be overridden by defining the environment variable ``TEMPLATEFLOW_HOME``
before running the client, for example::

$ export TEMPLATEFLOW_HOME=$DATA/.templateflow

**Configuring the operation mode**.
By default, the client will operate without DataLad (and hence, without version control).
To set up the DataLad mode, make sure DataLad is installed and functioning on your host,
and then::

$ export TEMPLATEFLOW_USE_DATALAD=on

It is recommended that the ``$TEMPLATEFLOW_HOME`` folder is wiped out before running the
client again, in case the tool has already been operated in direct download mode::

$ rm -r ${TEMPLATEFLOW_HOME:-$HOME/.cache/templateflow}

**TemplateFlow 2.0 file names**.
TemplateFlow 2.0 file names
~~~~~~~~~~~~~~~~~~~~~~~~~~~
TemplateFlow 2.0 renames files to follow BIDS 1.11 (for example, ``desc-CSF_probseg``
becomes ``label-CSF_probseg``), and records each rename in ``renames.tsv``.
Since templateflow 26.0, new home folders hold the current names only.
Expand All @@ -73,7 +172,8 @@ files without warnings.
``TEMPLATEFLOW_SKEL_URL`` replaces the base URL the client downloads skeletons from
(the list of file names of the Archive), for mirrors and tests.

**Naming conventions**.
Naming conventions
~~~~~~~~~~~~~~~~~~
Naming conventions for templates and atlases are available within the
`Contributing section of the TemplateFlow website
<https://www.templateflow.org/contributing/naming/>`__.
Expand Down
7 changes: 4 additions & 3 deletions templateflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ class TemplateFlowClient:
the value of the ``TEMPLATEFLOW_USE_DATALAD`` environment variable
(1/True/on/yes to enable, 0/False/off/no to disable).
autoupdate: :class:`bool`, optional
Whether to automatically update the cache on first load.
Defaults to ``True`` or the value of the ``TEMPLATEFLOW_AUTOUPDATE``
environment variable (1/True/on/yes to enable, 0/False/off/no to disable).
Currently has no effect: a new home is set up from the skeleton bundled with
the client, and homes are only updated by ``update()``. Defaults to ``True``
or the value of the ``TEMPLATEFLOW_AUTOUPDATE`` environment variable
(1/True/on/yes to enable, 0/False/off/no to disable).
timeout: :class:`float`, optional
Timeout in seconds for network operations. Default is ``10.0`` seconds.
origin: :class:`str`, optional
Expand Down
Loading