Skip to content

Commit 1de3c71

Browse files
authored
Merge pull request #59 from mgxd/fix/layout-reindex
FIX: Ensure templateflow Layout is re-indexed when updating
2 parents 1c473df + 72811b8 commit 1de3c71

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
source /tmp/venv/bin/activate
4646
pip install -U pip
4747
pip install -r /tmp/src/templateflow/requirements.txt
48-
pip install "datalad ~= 0.11.8" doi2bib
48+
pip install "datalad ~= 0.11.8" "doi2bib < 0.4"
4949
pip install "setuptools>=42.0" "setuptools_scm[toml] >= 3.4" twine codecov
5050
5151
- run:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ exclude =
4949

5050
[options.extras_require]
5151
citations =
52-
doi2bib
52+
doi2bib < 0.4.0
5353
datalad =
5454
datalad ~= 0.12.0
5555
doc =

templateflow/conf/__init__.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@
4545
def update(local=False, overwrite=True, silent=False):
4646
"""Update an existing DataLad or S3 home."""
4747
if TF_USE_DATALAD and _update_datalad():
48-
return True
49-
50-
from ._s3 import update as _update_s3
48+
success = True
49+
else:
50+
from ._s3 import update as _update_s3
51+
success = _update_s3(TF_HOME, local=local, overwrite=overwrite, silent=silent)
5152

52-
return _update_s3(TF_HOME, local=local, overwrite=overwrite, silent=silent)
53+
# update Layout only if necessary
54+
if success and TF_LAYOUT is not None:
55+
init_layout()
56+
# ensure the api uses the updated layout
57+
import importlib
58+
from .. import api
59+
importlib.reload(api)
60+
return success
5361

5462

5563
def setup_home(force=False):
@@ -76,9 +84,12 @@ def _update_datalad():
7684

7785

7886
TF_LAYOUT = None
79-
try:
87+
88+
89+
def init_layout():
8090
from .bids import Layout
8191

92+
global TF_LAYOUT
8293
TF_LAYOUT = Layout(
8394
TF_HOME,
8495
validate=False,
@@ -92,5 +103,9 @@ def _update_datalad():
92103
"scripts",
93104
],
94105
)
106+
107+
108+
try:
109+
init_layout()
95110
except ImportError:
96111
pass

templateflow/conf/_s3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ def _get_skeleton_file():
2727
import requests
2828

2929
try:
30-
r = requests.get(TF_SKEL_URL(release="master", ext="md5", allow_redirects=True))
30+
r = requests.get(TF_SKEL_URL(release="master", ext="md5"), allow_redirects=True)
3131
except requests.exceptions.ConnectionError:
3232
return
3333

3434
if not r.ok:
3535
return
3636

3737
if r.content.decode().split()[0] != TF_SKEL_MD5:
38-
r = requests.get(TF_SKEL_URL(release="master", ext="zip", allow_redirects=True))
38+
r = requests.get(TF_SKEL_URL(release="master", ext="zip"), allow_redirects=True)
3939
if r.ok:
4040
from os import close
4141

templateflow/tests/test_conf.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
import pytest
3+
from .. import conf, api
4+
5+
6+
@pytest.mark.skipif(conf.TF_USE_DATALAD, reason="S3 only")
7+
def test_update_s3(tmp_path):
8+
conf.TF_HOME = tmp_path / 'templateflow'
9+
conf.TF_HOME.mkdir(exist_ok=True)
10+
11+
# replace TF_SKEL_URL with the path of a legacy skeleton
12+
_skel_url = conf._s3.TF_SKEL_URL
13+
conf._s3.TF_SKEL_URL = (
14+
"https://github.com/templateflow/python-client/raw/0.5.0/"
15+
"templateflow/conf/templateflow-skel.{ext}".format
16+
)
17+
# initialize templateflow home, making sure to pull the legacy skeleton
18+
conf.update(local=False)
19+
# ensure we can grab a file
20+
assert Path(api.get('MNI152NLin2009cAsym', resolution=2, desc='brain', suffix='mask')).exists()
21+
# and ensure we can't fetch one that doesn't yet exist
22+
assert not api.get('Fischer344', hemi='L', desc='brain', suffix='mask')
23+
24+
# refresh the skeleton using the most recent skeleton
25+
conf._s3.TF_SKEL_URL = _skel_url
26+
conf.update(local=True, overwrite=True)
27+
assert Path(api.get('Fischer344', hemi='L', desc='brain', suffix='mask')).exists()

0 commit comments

Comments
 (0)