Skip to content

Commit a3e92ae

Browse files
authored
Merge pull request #354 from mgxd/bf/heur
BF: avoid cached heuristic discrepancies
2 parents 5357359 + 3bef2a5 commit a3e92ae

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

heudiconv/convert.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,21 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
122122
# detected
123123
# ref: https://github.com/nipy/heudiconv/issues/84#issuecomment-330048609
124124
# for more automagical wishes
125-
target_heuristic_filename = op.join(idir, op.basename(heuristic.filename))
125+
target_heuristic_filename = op.join(idir, 'heuristic.py')
126+
# faciliates change - TODO: remove in 1.0
127+
old_heuristic_filename = op.join(idir, op.basename(heuristic.filename))
128+
if op.exists(old_heuristic_filename):
129+
assure_no_file_exists(target_heuristic_filename)
130+
safe_copyfile(old_heuristic_filename, target_heuristic_filename)
131+
assure_no_file_exists(old_heuristic_filename)
126132
# TODO:
127133
# 1. add a test
128134
# 2. possibly extract into a dedicated function for easier logic flow here
129135
# and a dedicated unittest
130-
if (op.exists(target_heuristic_filename) and
131-
file_md5sum(target_heuristic_filename) != file_md5sum(heuristic.filename)):
136+
if (
137+
op.exists(target_heuristic_filename) and
138+
file_md5sum(target_heuristic_filename) != file_md5sum(heuristic.filename)
139+
):
132140
# remake conversion table
133141
reuse_conversion_table = False
134142
lgr.info(
@@ -151,7 +159,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
151159
# TODO -- might have been done outside already!
152160
# MG -- will have to try with both dicom template, files
153161
assure_no_file_exists(target_heuristic_filename)
154-
safe_copyfile(heuristic.filename, idir)
162+
safe_copyfile(heuristic.filename, target_heuristic_filename)
155163
if dicoms:
156164
seqinfo = group_dicoms_into_seqinfos(
157165
dicoms,

heudiconv/tests/test_main.py

+19
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,22 @@ def test_make_readonly(tmpdir):
250250
# and it should go back if we set it back to non-read_only
251251
assert set_readonly(pathname, read_only=False) == rw
252252
assert not is_readonly(pathname)
253+
254+
255+
def test_cache(tmpdir):
256+
tmppath = tmpdir.strpath
257+
args = (
258+
"-f convertall --files %s/axasc35.dcm -s S01"
259+
% (TESTS_DATA_PATH)
260+
).split(' ') + ['-o', tmppath]
261+
runner(args)
262+
263+
cachedir = (tmpdir / '.heudiconv' / 'S01' / 'info')
264+
assert cachedir.exists()
265+
266+
# check individual files
267+
assert (cachedir / 'heuristic.py').exists()
268+
assert (cachedir / 'filegroup.json').exists()
269+
assert (cachedir / 'dicominfo.tsv').exists()
270+
assert (cachedir / 'S01.auto.txt').exists()
271+
assert (cachedir / 'S01.edit.txt').exists()

0 commit comments

Comments
 (0)