Skip to content

Commit ea080bb

Browse files
committed
enh(reports): isolate reports into a new module
The initialization of the 'figures' config for BIDSLayout is made robuster too.
1 parent 18564cc commit ea080bb

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed

niworkflows/reports/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
4+
from .core import generate_reports
5+
6+
__all__ = ['generate_reports']

niworkflows/viz/reports.py renamed to niworkflows/reports/core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from nipype.utils.filemanip import copyfile
2121

2222

23-
add_config_paths(figures=pkgrf('niworkflows', 'viz/figures.json'))
2423
PLURAL_SUFFIX = defaultdict(str('s').format, [('echo', 'es')])
2524
SVG_SNIPPET = """\
2625
<object class="svg-reportlet" type="image/svg+xml" data="./{0}">
@@ -197,7 +196,7 @@ class Report(object):
197196
>>> robj.generate_report()
198197
0
199198
>>> len((testdir / 'out' / 'niworkflows' / 'sub-01.html').read_text())
200-
16988
199+
17582
201200
202201
"""
203202

@@ -207,6 +206,11 @@ def __init__(self, reportlets_dir, out_dir, run_uuid, config=None,
207206
self.root = reportlets_dir
208207

209208
# Initialize a BIDS layout
209+
try:
210+
add_config_paths(figures=pkgrf('niworkflows', 'reports/figures.json'))
211+
except ValueError as e:
212+
if "Configuration 'figures' already exists" != str(e):
213+
raise
210214
self.layout = BIDSLayout(self.root, config='figures', validate=False)
211215

212216
# Initialize structuring elements
@@ -225,7 +229,7 @@ def __init__(self, reportlets_dir, out_dir, run_uuid, config=None,
225229
self.out_filename = 'sub-{}.html'.format(self.subject_id)
226230

227231
if config is None:
228-
config = pkgrf('niworkflows', 'viz/defaultconfig.json')
232+
config = pkgrf('niworkflows', 'reports/defaultconfig.json')
229233
self._load_config(Path(config))
230234

231235
def _load_config(self, config):
File renamed without changes.
File renamed without changes.

niworkflows/viz/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55

66
from .plots import plot_carpet
77
from .utils import SVGNS
8+
9+
__all__ = ['plot_carpet', 'SVGNS']

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ def main():
3333
'niworkflows': [
3434
'data/t1-mni_registration*.json',
3535
'data/bold-mni_registration*.json',
36-
'viz/*.json',
37-
'viz/report.tpl',
36+
'reports/defaultconfig.json',
37+
'reports/figures.json',
38+
'reports/report.tpl',
3839
]}
3940

4041
root_dir = op.dirname(op.abspath(getfile(currentframe())))

0 commit comments

Comments
 (0)