Skip to content

Commit 28fbb21

Browse files
authored
Merge pull request #305 from oesteban/fix/250-getters
[MNT] Deprecate getters module
2 parents be587bb + 235787f commit 28fbb21

File tree

6 files changed

+77
-31
lines changed

6 files changed

+77
-31
lines changed

.circleci/config.yml

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,61 @@ jobs:
6666
# paths:
6767
# - cache/docker.tar.gz
6868

69+
get_data:
70+
machine:
71+
# Ubuntu 14.04 with Docker 17.10.0-ce
72+
image: circleci/classic:201711-01
73+
working_directory: /home/circleci/data
74+
steps:
75+
- restore_cache:
76+
keys:
77+
- data-v1-{{ epoch }}
78+
- data-v1-
79+
- run:
80+
name: Get test data from ds000003
81+
command: |
82+
mkdir -p /tmp/data
83+
if [[ ! -d /tmp/data/ds003_downsampled ]]; then
84+
wget --retry-connrefused --waitretry=5 --read-timeout=20 --timeout=15 -t 0 -q \
85+
-O ds003_downsampled.tar.gz "https://files.osf.io/v1/resources/fvuh8/providers/osfstorage/57f328f6b83f6901ef94cf70"
86+
tar xvzf ds003_downsampled.tar.gz -C /tmp/data/
87+
else
88+
echo "Dataset ds000003 was cached"
89+
fi
90+
- run:
91+
name: Get BIDS test data stub
92+
command: |
93+
mkdir -p /tmp/data
94+
if [[ ! -d /tmp/data/BIDS-examples-1-enh-ds054 ]]; then
95+
wget --retry-connrefused --waitretry=5 --read-timeout=20 --timeout=15 -t 0 -q \
96+
-O BIDS-examples-1-enh-ds054.zip "http://github.com/chrisfilo/BIDS-examples-1/archive/enh/ds054.zip"
97+
unzip BIDS-examples-1-enh-ds054.zip -d /tmp/data/
98+
else
99+
echo "BIDS stub was cached"
100+
fi
101+
- run:
102+
name: Store FreeSurfer license file
103+
command: |
104+
mkdir -p /tmp/fslicense
105+
printf "$FS_LICENSE_CONTENT" | base64 -d >> /tmp/fslicense/license.txt
106+
- persist_to_workspace:
107+
root: /tmp
108+
paths:
109+
- data
110+
- fslicense
111+
- save_cache:
112+
key: data-v1-{{ epoch }}
113+
paths:
114+
- /tmp/data
115+
116+
69117
test_pytest:
70118
machine:
71119
image: circleci/classic:201711-01
72120
working_directory: /tmp/tests
73121
steps:
74-
# - attach_workspace:
75-
# at: /tmp
122+
- attach_workspace:
123+
at: /tmp
76124
- restore_cache:
77125
keys:
78126
- docker-v1-{{ .Branch }}-{{ epoch }}
@@ -92,11 +140,6 @@ jobs:
92140
pigz -d --stdout /tmp/cache/docker.tar.gz | docker load
93141
docker images
94142
fi
95-
- run:
96-
name: Store FreeSurfer license file
97-
command: |
98-
mkdir -p /tmp/fslicense
99-
printf "$FS_LICENSE_CONTENT" | base64 -d >> /tmp/fslicense/license.txt
100143
- run:
101144
name: Set PR number
102145
command: |
@@ -113,6 +156,7 @@ jobs:
113156
sudo setfacl -d -m group:ubuntu:rwx $PWD
114157
sudo setfacl -m group:ubuntu:rwx $PWD
115158
docker run -it --rm=false \
159+
-e TEST_DATA_HOME=/data -v /tmp/data:/data \
116160
-v ${PWD}:/tmp niworkflows:py3 \
117161
pytest --junit-xml=/tmp/pytest.xml \
118162
--cov niworkflows --cov-report xml:/tmp/unittests.xml \
@@ -132,6 +176,7 @@ jobs:
132176
command: |
133177
docker run -it --rm=false \
134178
-e SAVE_CIRCLE_ARTIFACTS="/tmp" \
179+
-e TEST_DATA_HOME=/data -v /tmp/data:/data \
135180
-v /tmp/fslicense/license.txt:/opt/freesurfer/license.txt:ro \
136181
-v ${PWD}:/tmp niworkflows:py3 \
137182
pytest -n auto --junit-xml=/tmp/reportlets.xml \
@@ -174,18 +219,22 @@ workflows:
174219
filters:
175220
tags:
176221
only: /.*/
222+
- get_data:
223+
filters:
224+
tags:
225+
only: /.*/
177226

178227
- test_pytest:
179228
requires:
180229
- build
230+
- get_data
181231
filters:
182232
branches:
183233
ignore: /docs?\/.*/
184234
tags:
185235
only: /.*/
186236
- deploy:
187237
requires:
188-
- build
189238
- test_pytest
190239
filters:
191240
branches:

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ RUN echo "${VERSION}" > /src/niworkflows/niworkflows/VERSION && \
169169
pip install .[all] && \
170170
rm -rf ~/.cache/pip
171171

172-
# Pre-install data
173-
RUN python -c 'from niworkflows.data.getters import get_ds003_downsampled; get_ds003_downsampled()'
174-
172+
# Final settings
175173
WORKDIR /tmp
176174
ARG BUILD_DATE
177175
ARG VCS_REF

niworkflows/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import numpy
55
import pytest
66

7-
from . import data
87
from .utils.bids import collect_data
98

10-
data_dir = data.get_bids_examples(variant='BIDS-examples-1-enh-ds054')
9+
test_data_env = os.getenv('TEST_DATA_HOME',
10+
str(Path.home() / '.cache' / 'stanford-crn'))
11+
data_dir = Path(test_data_env) / 'BIDS-examples-1-enh-ds054'
1112

1213

1314
@pytest.fixture(autouse=True)
1415
def add_np(doctest_namespace):
1516
doctest_namespace['np'] = numpy
1617
doctest_namespace['os'] = os
1718
doctest_namespace['Path'] = Path
18-
doctest_namespace['datadir'] = Path(data_dir)
19+
doctest_namespace['datadir'] = data_dir
1920
doctest_namespace['bids_collect_data'] = collect_data

niworkflows/data/__init__.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +0,0 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
4-
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
""" Data fetchers module """
6-
from __future__ import absolute_import, division, print_function, unicode_literals
7-
8-
from .getters import (
9-
get_brainweb_1mm_normal,
10-
get_ds003_downsampled,
11-
get_dataset,
12-
get_template,
13-
get_bids_examples,
14-
TEMPLATE_ALIASES,
15-
)

niworkflows/data/getters.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
"""
88
from __future__ import print_function, division, absolute_import, unicode_literals
99

10+
from warnings import warn
1011
from ..data.utils import fetch_file
1112

13+
DEPRECATION_MSG = """\
14+
Module ``niworkflows.data.getters`` has been deprecated in 0.7.1, \
15+
and will be removed in 0.8."""
1216

1317
OSF_PROJECT_URL = ('https://files.osf.io/v1/resources/fvuh8/providers/osfstorage/')
1418
OSF_RESOURCES = {
@@ -54,6 +58,7 @@ def get_dataset(dataset_name, dataset_prefix=None, data_dir=None,
5458
:param str url: download URL of the dataset. Overwrite the default URL.
5559
5660
"""
61+
warn(DEPRECATION_MSG)
5762
file_id, md5 = OSF_RESOURCES[dataset_name]
5863
if url is None:
5964
url = '{}/{}'.format(OSF_PROJECT_URL, file_id)
@@ -63,6 +68,7 @@ def get_dataset(dataset_name, dataset_prefix=None, data_dir=None,
6368

6469
def get_template(template_name, data_dir=None, url=None, resume=True, verbose=1):
6570
"""Download and load a template"""
71+
warn(DEPRECATION_MSG)
6672
if template_name.startswith('tpl-'):
6773
template_name = template_name[4:]
6874

@@ -80,6 +86,7 @@ def get_brainweb_1mm_normal(data_dir=None, url=None, resume=True, verbose=1):
8086
:param str url: download URL of the dataset. Overwrite the default URL.
8187
8288
"""
89+
warn(DEPRECATION_MSG)
8390
return get_dataset('brainweb', data_dir=data_dir, url=url,
8491
resume=resume, verbose=verbose)
8592

@@ -92,13 +99,15 @@ def get_ds003_downsampled(data_dir=None, url=None, resume=True, verbose=1):
9299
:param str url: download URL of the dataset. Overwrite the default URL.
93100
94101
"""
102+
warn(DEPRECATION_MSG)
95103
return get_dataset('ds003_downsampled', data_dir=data_dir, url=url,
96104
resume=resume, verbose=verbose)
97105

98106

99107
def get_bids_examples(data_dir=None, url=None, resume=True, verbose=1,
100108
variant='BIDS-examples-1-1.0.0-rc3u5'):
101109
"""Download BIDS-examples-1"""
110+
warn(DEPRECATION_MSG)
102111
variant = 'BIDS-examples-1-1.0.0-rc3u5' if variant not in BIDS_EXAMPLES else variant
103112
if url is None:
104113
url = BIDS_EXAMPLES[variant][0]

niworkflows/tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
""" py.test configuration file """
55
import os
6+
from pathlib import Path
67
from tempfile import mkdtemp
78
from datetime import datetime as dt
89
import pytest
910
from templateflow.api import get as get_template
10-
from niworkflows.data.getters import get_ds003_downsampled
1111

1212
filepath = os.path.dirname(os.path.realpath(__file__))
1313
datadir = os.path.realpath(os.path.join(filepath, 'data'))
1414

15+
test_data_env = os.getenv('TEST_DATA_HOME',
16+
str(Path.home() / '.cache' / 'stanford-crn'))
17+
data_dir = Path(test_data_env) / 'ds003_downsampled'
18+
1519

1620
def _run_interface_mock(objekt, runtime):
1721
runtime.returncode = 0
@@ -40,7 +44,7 @@ def reference_mask():
4044

4145
@pytest.fixture
4246
def moving():
43-
return os.path.join(get_ds003_downsampled(), 'sub-01/anat/sub-01_T1w.nii.gz')
47+
return str(data_dir / 'sub-01/anat/sub-01_T1w.nii.gz')
4448

4549

4650
@pytest.fixture

0 commit comments

Comments
 (0)