diff --git a/CHANGES.rst b/CHANGES.rst index d879648f..4af529cf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,6 +28,10 @@ TemplateFlow 2.0 file names: the client reads the v2 skeleton and resolves old n * FIX: ``get()`` skipped files when DataLad fetched several at once, and failed for files without a stub in the home. * FIX: Network errors other than connection errors no longer break skeleton updates. +* FIX: DataLad homes update from ``origin`` (GitHub) only: a template's GIN remote + refusing a fetch no longer makes ``update()`` fail. +* FIX: In DataLad mode, ``templateflow wipe`` no longer asks for confirmation, nor + reports the home as wiped out: it deletes nothing there. * MAINT: A compatibility matrix (``tests/compat``, workflow *Compatibility*) runs the released clients and this one against an Archive before and after a renames table, in S3 and DataLad homes. It replays a proposed table before it is merged. diff --git a/templateflow/cli.py b/templateflow/cli.py index bb524068..5019b64e 100644 --- a/templateflow/cli.py +++ b/templateflow/cli.py @@ -103,6 +103,12 @@ def config(): @main.command() def wipe(): """Wipe out a local S3 (direct-download) TemplateFlow Archive.""" + from templateflow.conf import wipe as _wipe + + if CONFIG.use_datalad: + _wipe() # DataLad homes are never wiped out: this only says so + return + click.echo(f'This will wipe out all data downloaded into {CONFIG.root}.') if click.confirm('Do you want to continue?'): @@ -112,9 +118,7 @@ def wipe(): show_default=False, ) if value.strip() == str(CONFIG.root): - from templateflow.conf import wipe - - wipe() + _wipe() click.echo(f'{CONFIG.root} was wiped out.') return click.echo(f'Aborted! {CONFIG.root} WAS NOT wiped out.') diff --git a/templateflow/tests/test_cli.py b/templateflow/tests/test_cli.py index 95ddceb1..3fcf0fab 100644 --- a/templateflow/tests/test_cli.py +++ b/templateflow/tests/test_cli.py @@ -79,3 +79,37 @@ def test_update_options(runner): result = runner.invoke(cli.main, ['update', '--help']) assert result.exit_code == 0 assert '--migrate' in result.stdout + + +@pytest.mark.parametrize( + ('use_datalad', 'answers', 'wiped'), + [ + (False, ['y', '{root}'], True), + (False, ['y', 'elsewhere'], False), + (False, ['n'], False), + (True, ['y', '{root}'], False), + ], +) +def test_wipe(runner, monkeypatch, tmp_path, use_datalad, answers, wiped): + from types import SimpleNamespace + + import templateflow.conf + from templateflow.conf.cache import DataladManager, S3Manager + + root = tmp_path / 'templateflow' + (root / 'tpl-Test').mkdir(parents=True) + manager = DataladManager('origin') if use_datalad else S3Manager('s3') + monkeypatch.setattr(cli, 'CONFIG', SimpleNamespace(root=root, use_datalad=use_datalad)) + monkeypatch.setattr(templateflow.conf, 'wipe', lambda: manager.wipe(root)) + + answers = ''.join(f'{answer}\n' for answer in answers).format(root=root) + result = runner.invoke(cli.main, ['wipe'], input=answers) + + assert result.exit_code == 0 + assert root.exists() is not wiped + assert result.output.endswith(f'{root} was wiped out.\n') is wiped + if use_datalad: + # No prompts, and no claim that anything was deleted + assert ( + result.output == 'TemplateFlow is configured in DataLad mode, wipe() has no effect\n' + )