diff --git a/templateflow/conf/cache.py b/templateflow/conf/cache.py index 62e6ea1b..a4622aca 100644 --- a/templateflow/conf/cache.py +++ b/templateflow/conf/cache.py @@ -104,7 +104,10 @@ def update(self, path: Path, local: bool, overwrite: bool, silent: bool, timeout print('Updating TEMPLATEFLOW_HOME using DataLad ...') try: - update(dataset=path, recursive=True, merge=True) + # Fetch from origin only, which the update merges from: without a sibling, + # DataLad also fetches from every other remote, such as GIN (gin-src), + # and fails when one of them does + update(dataset=path, sibling='origin', recursive=True, merge=True) except Exception as e: # noqa: BLE001 warn( f"Error updating TemplateFlow's home directory (using DataLad): {e}", diff --git a/templateflow/tests/test_conf.py b/templateflow/tests/test_conf.py index 59aeb86c..93c78941 100644 --- a/templateflow/tests/test_conf.py +++ b/templateflow/tests/test_conf.py @@ -163,3 +163,21 @@ def mock_import(name, globals=None, locals=None, fromlist=(), level=0): # noqa: m.setattr(builtins, '__import__', mock_import) with pytest.raises(ImportError): myfunc() + + +def test_datalad_update_fetches_origin(monkeypatch, tmp_path): + """DataLad homes fetch from origin only: other siblings, such as GIN, may refuse.""" + import sys + from types import ModuleType + + from templateflow.conf.cache import DataladManager + + calls = [] + api = ModuleType('datalad.api') + api.update = lambda **kwargs: calls.append(kwargs) + monkeypatch.setitem(sys.modules, 'datalad', ModuleType('datalad')) + monkeypatch.setitem(sys.modules, 'datalad.api', api) + + manager = DataladManager(source='https://github.com/templateflow/templateflow.git') + assert manager.update(tmp_path, local=False, overwrite=True, silent=True, timeout=10) + assert calls == [{'dataset': tmp_path, 'sibling': 'origin', 'recursive': True, 'merge': True}]