Skip to content

Commit 2695ecf

Browse files
authored
Merge pull request #529 from dbic/enh-version
ENH: add HeudiconvVersion to sidecar .json files
2 parents c4956b3 + ee0dcb0 commit 2695ecf

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

heudiconv/bids.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
is_readonly,
2424
get_datetime,
2525
)
26+
from . import __version__
2627

2728
lgr = logging.getLogger(__name__)
2829

@@ -40,6 +41,10 @@
4041
("Description", "md5 hash of UIDs")])),
4142
])
4243

44+
#: JSON Key where we will embed our version in the newly produced .json files
45+
HEUDICONV_VERSION_JSON_KEY = 'HeudiconvVersion'
46+
47+
4348
class BIDSError(Exception):
4449
pass
4550

@@ -244,6 +249,10 @@ def tuneup_bids_json_files(json_files):
244249
# Let's hope no word 'Date' comes within a study name or smth like
245250
# that
246251
raise ValueError("There must be no dates in .json sidecar")
252+
# Those files should not have our version field already - should have been
253+
# freshly produced
254+
assert HEUDICONV_VERSION_JSON_KEY not in json_
255+
json_[HEUDICONV_VERSION_JSON_KEY] = str(__version__)
247256
save_json(jsonfile, json_)
248257

249258
# Load the beast

heudiconv/tests/test_heuristics.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
from glob import glob
99
from os.path import join as pjoin, dirname
10+
from pathlib import Path
1011
import csv
1112
import re
1213

14+
from .. import __version__
15+
from ..bids import HEUDICONV_VERSION_JSON_KEY
16+
from ..utils import load_json
17+
1318
import pytest
1419
from .utils import TESTS_DATA_PATH
1520

@@ -140,16 +145,22 @@ def test_scout_conversion(tmpdir):
140145
).split(' ') + ['-o', tmppath]
141146
runner(args)
142147

143-
assert not op.exists(pjoin(
144-
tmppath,
145-
'Halchenko/Yarik/950_bids_test4/sub-phantom1sid1/ses-localizer/anat'))
146-
147-
assert op.exists(pjoin(
148-
tmppath,
149-
'Halchenko/Yarik/950_bids_test4/sourcedata/sub-phantom1sid1/'
150-
'ses-localizer/anat/sub-phantom1sid1_ses-localizer_scout.dicom.tgz'
151-
)
152-
)
148+
dspath = Path(tmppath) / 'Halchenko/Yarik/950_bids_test4'
149+
sespath = dspath / 'sub-phantom1sid1/ses-localizer'
150+
151+
assert not (sespath / 'anat').exists()
152+
assert (
153+
dspath /
154+
'sourcedata/sub-phantom1sid1/ses-localizer/'
155+
'anat/sub-phantom1sid1_ses-localizer_scout.dicom.tgz'
156+
).exists()
157+
158+
# Let's do some basic checks on produced files
159+
j = load_json(sespath / 'fmap/sub-phantom1sid1_ses-localizer_acq-3mm_phasediff.json')
160+
# We store HeuDiConv version in each produced .json file
161+
# TODO: test that we are not somehow overwritting that version in existing
162+
# files which we have not produced in a particular run.
163+
assert j[HEUDICONV_VERSION_JSON_KEY] == __version__
153164

154165

155166
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)