From 003c8896824163ceba8f92449e95c82971333019 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 17 Aug 2020 17:54:37 -0400 Subject: [PATCH 1/6] FIX: Ensure templateflow Layout is re-indexed when updating --- templateflow/conf/__init__.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/templateflow/conf/__init__.py b/templateflow/conf/__init__.py index f4b387b7..9d29cf2f 100644 --- a/templateflow/conf/__init__.py +++ b/templateflow/conf/__init__.py @@ -45,11 +45,19 @@ def update(local=False, overwrite=True, silent=False): """Update an existing DataLad or S3 home.""" if TF_USE_DATALAD and _update_datalad(): - return True - - from ._s3 import update as _update_s3 + success = True + else: + from ._s3 import update as _update_s3 + success = _update_s3(TF_HOME, local=local, overwrite=overwrite, silent=silent) - return _update_s3(TF_HOME, local=local, overwrite=overwrite, silent=silent) + # update Layout only if necessary + if success and TF_LAYOUT is not None: + init_layout() + # ensure the api uses the updated layout + import importlib + from .. import api + importlib.reload(api) + return success def setup_home(force=False): @@ -76,9 +84,12 @@ def _update_datalad(): TF_LAYOUT = None -try: + + +def init_layout(): from .bids import Layout + global TF_LAYOUT TF_LAYOUT = Layout( TF_HOME, validate=False, @@ -92,5 +103,9 @@ def _update_datalad(): "scripts", ], ) + + +try: + init_layout() except ImportError: pass From ab17865112b8d4364e7f907e358ca5594dcaf7e8 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 17 Aug 2020 22:45:51 -0400 Subject: [PATCH 2/6] FIX: Allow redirects in GET request --- templateflow/conf/_s3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templateflow/conf/_s3.py b/templateflow/conf/_s3.py index 9e20cbeb..4051ce86 100644 --- a/templateflow/conf/_s3.py +++ b/templateflow/conf/_s3.py @@ -27,7 +27,7 @@ def _get_skeleton_file(): import requests try: - r = requests.get(TF_SKEL_URL(release="master", ext="md5", allow_redirects=True)) + r = requests.get(TF_SKEL_URL(release="master", ext="md5"), allow_redirects=True) except requests.exceptions.ConnectionError: return @@ -35,7 +35,7 @@ def _get_skeleton_file(): return if r.content.decode().split()[0] != TF_SKEL_MD5: - r = requests.get(TF_SKEL_URL(release="master", ext="zip", allow_redirects=True)) + r = requests.get(TF_SKEL_URL(release="master", ext="zip"), allow_redirects=True) if r.ok: from os import close From c13b367e36faeaf4a5204626d863d54dfb15747c Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 17 Aug 2020 22:46:13 -0400 Subject: [PATCH 3/6] ENH: Add test for skeleton update --- templateflow/tests/test_conf.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 templateflow/tests/test_conf.py diff --git a/templateflow/tests/test_conf.py b/templateflow/tests/test_conf.py new file mode 100644 index 00000000..0c537943 --- /dev/null +++ b/templateflow/tests/test_conf.py @@ -0,0 +1,25 @@ +from pathlib import Path +from .. import conf, api + + +def test_update_s3(tmp_path): + conf.TF_HOME = tmp_path / 'templateflow' + conf.TF_HOME.mkdir(exist_ok=True) + + # replace TF_SKEL_URL with the path of a legacy skeleton + _skel_url = conf._s3.TF_SKEL_URL + conf._s3.TF_SKEL_URL = ( + "https://github.com/templateflow/python-client/raw/0.5.0/" + "templateflow/conf/templateflow-skel.{ext}".format + ) + # initialize templateflow home, making sure to pull the legacy skeleton + conf.update(local=False) + # ensure we can grab a file + assert Path(api.get('MNI152NLin2009cAsym', resolution=2, desc='brain', suffix='mask')).exists() + # and ensure we can't fetch one that doesn't yet exist + assert not api.get('Fischer344', hemi='L', desc='brain', suffix='mask') + + # refresh the skeleton using the most recent skeleton + conf._s3.TF_SKEL_URL = _skel_url + conf.update(local=True, overwrite=True) + assert Path(api.get('Fischer344', hemi='L', desc='brain', suffix='mask')).exists() From f8e38b473b1466612ed85b04dffa5a7cb5210acb Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 17 Aug 2020 22:54:27 -0400 Subject: [PATCH 4/6] FIX: failing doi test --- setup.cfg | 2 +- templateflow/tests/test_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 16b5cc95..ec60d3a5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,7 +49,7 @@ exclude = [options.extras_require] citations = - doi2bib + doi2bib >= 0.4.0 datalad = datalad ~= 0.12.0 doc = diff --git a/templateflow/tests/test_api.py b/templateflow/tests/test_api.py index ba98fc22..874c39b9 100644 --- a/templateflow/tests/test_api.py +++ b/templateflow/tests/test_api.py @@ -24,7 +24,7 @@ "\tauthor = {Vladimir Fonov and Alan C. Evans and Kelly Botteron and C. " "Robert Almli and Robert C. McKinstry and D. Louis Collins},\n" "\ttitle = {Unbiased average age-appropriate atlases for pediatric studies},\n" - "\tjournal = {{NeuroImage}}\n}" + "\tjournal = {NeuroImage}}\n}" ) mni2009_lbib = ( From c9fe6cd76413f9b5a31fbed0d0c74b5f95b3868f Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 17 Aug 2020 23:23:02 -0400 Subject: [PATCH 5/6] FIX: skip test if using datalad --- templateflow/tests/test_conf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templateflow/tests/test_conf.py b/templateflow/tests/test_conf.py index 0c537943..c2d95f22 100644 --- a/templateflow/tests/test_conf.py +++ b/templateflow/tests/test_conf.py @@ -1,7 +1,9 @@ from pathlib import Path +import pytest from .. import conf, api +@pytest.mark.skipif(conf.TF_USE_DATALAD, reason="S3 only") def test_update_s3(tmp_path): conf.TF_HOME = tmp_path / 'templateflow' conf.TF_HOME.mkdir(exist_ok=True) From 72811b802a1ef68d4fbe286d56dc9904ec748d17 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Sun, 13 Sep 2020 11:33:15 -0400 Subject: [PATCH 6/6] PIN: doi2bib to older versions until bibcure/doi2bib#6 is resolved --- .circleci/config.yml | 2 +- setup.cfg | 2 +- templateflow/tests/test_api.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 115902f4..f9399f75 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ jobs: source /tmp/venv/bin/activate pip install -U pip pip install -r /tmp/src/templateflow/requirements.txt - pip install "datalad ~= 0.11.8" doi2bib + pip install "datalad ~= 0.11.8" "doi2bib < 0.4" pip install "setuptools>=42.0" "setuptools_scm[toml] >= 3.4" twine codecov - run: diff --git a/setup.cfg b/setup.cfg index ec60d3a5..10123688 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,7 +49,7 @@ exclude = [options.extras_require] citations = - doi2bib >= 0.4.0 + doi2bib < 0.4.0 datalad = datalad ~= 0.12.0 doc = diff --git a/templateflow/tests/test_api.py b/templateflow/tests/test_api.py index 874c39b9..ba98fc22 100644 --- a/templateflow/tests/test_api.py +++ b/templateflow/tests/test_api.py @@ -24,7 +24,7 @@ "\tauthor = {Vladimir Fonov and Alan C. Evans and Kelly Botteron and C. " "Robert Almli and Robert C. McKinstry and D. Louis Collins},\n" "\ttitle = {Unbiased average age-appropriate atlases for pediatric studies},\n" - "\tjournal = {NeuroImage}}\n}" + "\tjournal = {{NeuroImage}}\n}" ) mni2009_lbib = (