From 25daabd75c3937b3230f0b5a64897e69f311a2e8 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Mon, 20 Oct 2025 21:32:26 -0700 Subject: [PATCH 1/3] docs: reorganize settings guidance --- docs/installation.rst | 157 +++++++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 32 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index b2297fdd..5dd83c2b 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -18,38 +18,131 @@ You should see the version number. Settings -------- -The *TemplateFlow Client* has two modes of operation: (a) based on -`DataLad `__, or (b) direct downloads from Amazon S3. - -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} +``TemplateFlowClient`` is the central entry point for configuring how the +archive is cached and updated. Each constructor argument mirrors an +environment variable (when available) and exposes its live value through the +metadata descriptors defined in :mod:`templateflow.conf`. + +.. list-table:: ``TemplateFlowClient`` configuration + :header-rows: 1 + + * - Argument + - Environment variable + - Default + - Metadata descriptor + * - ``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`` + - ``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`` + +Cache location +~~~~~~~~~~~~~~ +The client stores downloads in a writable cache that defaults to the +platform-specific ``TEMPLATEFLOW_HOME`` directory. You can point the CLI to a +different location by exporting the environment variable before invoking any +command; the current value is always available through +``templateflow.conf.TF_HOME``. + +.. 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) + +If you switch between cache locations, wipe the previous cache (``templateflow +wipe`` or :func:`templateflow.conf.wipe`) to avoid mixing S3 and DataLad +layouts. + +DataLad mode +~~~~~~~~~~~~ +Two backends are available: a lightweight S3 mirror and a DataLad dataset. +Setting ``TEMPLATEFLOW_USE_DATALAD=on`` switches the CLI into DataLad mode +(automatically falling back to S3 if DataLad is missing). The active backend +can be inspected via ``templateflow.conf.TF_USE_DATALAD``. + +.. 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) + +When switching from the default S3 mode to DataLad, start with an empty cache +directory (for example by deleting ``$TEMPLATEFLOW_HOME``) so that git-annex can +initialise cleanly. + +S3 origins +~~~~~~~~~~ +S3-backed installations download assets from the ``s3_root`` mirror referenced +in the configuration. The CLI always reports the active mirror through the +``templateflow.conf.TF_S3_ROOT`` descriptor. + +.. code-block:: console + + $ python - <<'PY' + from templateflow.conf import TF_S3_ROOT + print(TF_S3_ROOT) + PY + +.. code-block:: python + + from templateflow.client import TemplateFlowClient + + mirror = TemplateFlowClient(s3_root="https://my-mirror.s3.amazonaws.com") + print(mirror.cache.config.s3_root) + +To use a custom DataLad remote, pass ``origin=...`` when constructing the +client and call :func:`templateflow.conf.update` to refresh the cache metadata. + +Autoupdates, timeouts, and cache metadata +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Automatic cache refreshes are controlled by ``autoupdate``. Disable them for +air-gapped deployments with ``TEMPLATEFLOW_AUTOUPDATE=off`` or by creating the +client with ``autoupdate=False``; the current flag is exported as +``templateflow.conf.TF_AUTOUPDATE``. + +Network operations time out after 10 seconds by default. Provide a different +``timeout`` when constructing ``TemplateFlowClient`` and inspect the value via +``templateflow.conf.TF_GET_TIMEOUT``. + +Whenever the cache contents change outside the client (for example, when +switching mirrors or pulling updates with DataLad), rebuild the BIDS layout by +calling :func:`templateflow.conf.update` or ``TemplateFlowClient.cache.update``. +The layout object is exposed as ``templateflow.conf.TF_LAYOUT`` and is +invalidated automatically whenever :func:`templateflow.conf.update` succeeds, +ensuring that new metadata descriptors are reflected in subsequent queries. **TemplateFlow 2.0 file names**. TemplateFlow 2.0 renames files to follow BIDS 1.11 (for example, ``desc-CSF_probseg`` From 6aa530410d2d19f5ea181246adb3525041620412 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Thu, 3 Dec 2026 20:12:27 +0100 Subject: [PATCH 2/3] docs: correct the settings section against the code - `autoupdate` has never had an effect (a new home is set up from the bundled skeleton; homes change only when updated): say so in the settings section, the README table and the TemplateFlowClient docstring, instead of offering it for air-gapped deployments. - The `templateflow.conf.TF_*` attributes show the default client's settings, not those of any TemplateFlowClient. - `templateflow config` does not report the S3 mirror; skeletons come from GitHub whatever `s3_root` is. - `origin` is only where a new DataLad home is installed from. - Switching a home to DataLad needs an empty folder; switching locations mixes nothing. - The index of a home is rebuilt after an update that changed it; other changes need a restart. - The 2.0 file names and naming conventions become subsections, instead of run-in headings that read as part of the last subsection. Co-Authored-By: Claude Opus 5.5 --- README.rst | 2 +- docs/installation.rst | 119 ++++++++++++++++++++++------------------- templateflow/client.py | 4 +- 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/README.rst b/README.rst index 98bc2b39..7da68b0c 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/docs/installation.rst b/docs/installation.rst index 5dd83c2b..b57a706e 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -18,18 +18,21 @@ You should see the version number. Settings -------- -``TemplateFlowClient`` is the central entry point for configuring how the -archive is cached and updated. Each constructor argument mirrors an -environment variable (when available) and exposes its live value through the -metadata descriptors defined in :mod:`templateflow.conf`. - -.. list-table:: ``TemplateFlowClient`` configuration +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 - - Metadata descriptor + - Default client's value * - ``root`` - ``TEMPLATEFLOW_HOME`` - ``platformdirs.user_cache_dir('templateflow')`` (e.g., ``~/.cache/templateflow``) @@ -40,7 +43,7 @@ metadata descriptors defined in :mod:`templateflow.conf`. - ``templateflow.conf.TF_USE_DATALAD`` * - ``autoupdate`` - ``TEMPLATEFLOW_AUTOUPDATE`` - - ``True`` + - ``True`` (currently has no effect) - ``templateflow.conf.TF_AUTOUPDATE`` * - ``timeout`` - *(none)* @@ -55,13 +58,15 @@ metadata descriptors defined in :mod:`templateflow.conf`. - ``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 cache that defaults to the -platform-specific ``TEMPLATEFLOW_HOME`` directory. You can point the CLI to a -different location by exporting the environment variable before invoking any -command; the current value is always available through -``templateflow.conf.TF_HOME``. +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 @@ -75,16 +80,13 @@ command; the current value is always available through client = TemplateFlowClient(root="/data/templateflow") print(client.cache.config.root) -If you switch between cache locations, wipe the previous cache (``templateflow -wipe`` or :func:`templateflow.conf.wipe`) to avoid mixing S3 and DataLad -layouts. - DataLad mode ~~~~~~~~~~~~ -Two backends are available: a lightweight S3 mirror and a DataLad dataset. -Setting ``TEMPLATEFLOW_USE_DATALAD=on`` switches the CLI into DataLad mode -(automatically falling back to S3 if DataLad is missing). The active backend -can be inspected via ``templateflow.conf.TF_USE_DATALAD``. +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 @@ -99,22 +101,21 @@ can be inspected via ``templateflow.conf.TF_USE_DATALAD``. client.cache.ensure() print(client.cache.config.use_datalad) -When switching from the default S3 mode to DataLad, start with an empty cache -directory (for example by deleting ``$TEMPLATEFLOW_HOME``) so that git-annex can -initialise cleanly. +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``. -S3 origins -~~~~~~~~~~ -S3-backed installations download assets from the ``s3_root`` mirror referenced -in the configuration. The CLI always reports the active mirror through the -``templateflow.conf.TF_S3_ROOT`` descriptor. +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 - <<'PY' - from templateflow.conf import TF_S3_ROOT - print(TF_S3_ROOT) - PY + $ python -c "from templateflow.conf import TF_S3_ROOT; print(TF_S3_ROOT)" + https://templateflow.s3.amazonaws.com .. code-block:: python @@ -123,28 +124,33 @@ in the configuration. The CLI always reports the active mirror through the mirror = TemplateFlowClient(s3_root="https://my-mirror.s3.amazonaws.com") print(mirror.cache.config.s3_root) -To use a custom DataLad remote, pass ``origin=...`` when constructing the -client and call :func:`templateflow.conf.update` to refresh the cache metadata. - -Autoupdates, timeouts, and cache metadata -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Automatic cache refreshes are controlled by ``autoupdate``. Disable them for -air-gapped deployments with ``TEMPLATEFLOW_AUTOUPDATE=off`` or by creating the -client with ``autoupdate=False``; the current flag is exported as -``templateflow.conf.TF_AUTOUPDATE``. - -Network operations time out after 10 seconds by default. Provide a different -``timeout`` when constructing ``TemplateFlowClient`` and inspect the value via -``templateflow.conf.TF_GET_TIMEOUT``. - -Whenever the cache contents change outside the client (for example, when -switching mirrors or pulling updates with DataLad), rebuild the BIDS layout by -calling :func:`templateflow.conf.update` or ``TemplateFlowClient.cache.update``. -The layout object is exposed as ``templateflow.conf.TF_LAYOUT`` and is -invalidated automatically whenever :func:`templateflow.conf.update` succeeds, -ensuring that new metadata descriptors are reflected in subsequent queries. - -**TemplateFlow 2.0 file names**. +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. + +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. @@ -166,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 `__. diff --git a/templateflow/client.py b/templateflow/client.py index d0aa8782..dff7fda8 100644 --- a/templateflow/client.py +++ b/templateflow/client.py @@ -71,8 +71,8 @@ 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`` + 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. From f9e5fd4cee6d3ef4377e6b9c3f12f19573d7bf2c Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Thu, 3 Dec 2026 20:24:23 +0100 Subject: [PATCH 3/3] docs: wrap the autoupdate docstring to the line limit Co-Authored-By: Claude Opus 5.5 --- templateflow/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templateflow/client.py b/templateflow/client.py index dff7fda8..812d41e8 100644 --- a/templateflow/client.py +++ b/templateflow/client.py @@ -72,8 +72,9 @@ class TemplateFlowClient: (1/True/on/yes to enable, 0/False/off/no to disable). autoupdate: :class:`bool`, optional 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). + 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