Skip to content

Commit f8ce7ec

Browse files
authored
Merge pull request #416 from mgxd/maint-deps
MAINT: Drop Python 2 support, update dcmstack + datalad
2 parents 4c13d68 + 6827c16 commit f8ce7ec

File tree

7 files changed

+24
-42
lines changed

7 files changed

+24
-42
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# vim ft=yaml
22
language: python
33
python:
4-
- 2.7
54
- 3.5
65
- 3.6
76
- 3.7
7+
- 3.8
88

99
cache:
1010
- apt

heudiconv/convert.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
7272
try:
7373
files = filegroup[item]
7474
except KeyError:
75-
PY3 = sys.version_info[0] >= 3
76-
files = filegroup[(str if PY3 else unicode)(item)]
75+
files = filegroup[str(item)]
7776
outprefix = template.format(**parameters)
7877
convert_info.append((op.join(outpath, outprefix),
7978
outtype, files))

heudiconv/external/dlad.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
lgr = logging.getLogger(__name__)
1212

13-
MIN_VERSION = '0.7'
13+
MIN_VERSION = '0.12.2'
1414

1515

1616
def prepare_datalad(studydir, outdir, sid, session, seqinfo, dicoms, bids):
@@ -34,36 +34,33 @@ def prepare_datalad(studydir, outdir, sid, session, seqinfo, dicoms, bids):
3434
def add_to_datalad(topdir, studydir, msg, bids):
3535
"""Do all necessary preparations (if were not done before) and save
3636
"""
37-
from datalad.api import create
37+
import datalad.api as dl
3838
from datalad.api import Dataset
3939
from datalad.support.annexrepo import AnnexRepo
4040
from datalad.support.external_versions import external_versions
4141
assert external_versions['datalad'] >= MIN_VERSION, (
42-
"Need datalad >= {}".format(MIN_VERSION)) # add to reqs
42+
"Need datalad >= {}".format(MIN_VERSION)) # add to reqs
4343

44-
create_kwargs = {}
45-
if external_versions['datalad'] >= '0.10':
46-
create_kwargs['fake_dates'] = True # fake dates by default
4744

4845
studyrelpath = op.relpath(studydir, topdir)
4946
assert not studyrelpath.startswith(op.pardir) # so we are under
5047
# now we need to test and initiate a DataLad dataset all along the path
5148
curdir_ = topdir
5249
superds = None
53-
subdirs = [''] + studyrelpath.split(op.sep)
50+
subdirs = [''] + [d for d in studyrelpath.split(op.sep) if d != os.curdir]
5451
for isubdir, subdir in enumerate(subdirs):
5552
curdir_ = op.join(curdir_, subdir)
5653
ds = Dataset(curdir_)
5754
if not ds.is_installed():
5855
lgr.info("Initiating %s", ds)
5956
# would require annex > 20161018 for correct operation on annex v6
6057
# need to add .gitattributes first anyways
61-
ds_ = create(curdir_, dataset=superds,
58+
ds_ = dl.create(curdir_, dataset=superds,
6259
force=True,
63-
no_annex=True,
60+
# initiate annex only at the bottom repository
61+
no_annex=isubdir<(len(subdirs)-1),
62+
fake_dates=True,
6463
# shared_access='all',
65-
annex_version=6,
66-
**create_kwargs
6764
)
6865
assert ds == ds_
6966
assert ds.is_installed()
@@ -93,17 +90,13 @@ def add_to_datalad(topdir, studydir, msg, bids):
9390
with open(gitattributes_path, 'wb') as f:
9491
f.write('\n'.join(known_attrs).encode('utf-8'))
9592

96-
# so for mortals it just looks like a regular directory!
97-
if not ds.config.get('annex.thin'):
98-
ds.config.add('annex.thin', 'true', where='local')
99-
# initialize annex there if not yet initialized
100-
AnnexRepo(ds.path, init=True)
93+
10194
# ds might have memories of having ds.repo GitRepo
102-
superds = None
103-
del ds
104-
ds = Dataset(studydir)
95+
superds = Dataset(topdir)
96+
assert op.realpath(ds.path) == op.realpath(studydir)
97+
assert isinstance(ds.repo, AnnexRepo)
10598
# Add doesn't have all the options of save such as msg and supers
106-
ds.add('.gitattributes', to_git=True, save=False)
99+
ds.save(path=['.gitattributes'], message="Custom .gitattributes", to_git=True)
107100
dsh = dsh_path = None
108101
if op.lexists(op.join(ds.path, '.heudiconv')):
109102
dsh_path = op.join(ds.path, '.heudiconv')
@@ -120,7 +113,6 @@ def add_to_datalad(topdir, studydir, msg, bids):
120113
else:
121114
dsh = ds.create(path='.heudiconv',
122115
force=True,
123-
**create_kwargs
124116
# shared_access='all'
125117
)
126118
# Since .heudiconv could contain sensitive information
@@ -146,7 +138,7 @@ def add_to_datalad(topdir, studydir, msg, bids):
146138
mark_sensitive(ds, '*/*/anat') # within ses/subj
147139
if dsh_path:
148140
mark_sensitive(ds, '.heudiconv') # entire .heudiconv!
149-
ds.save(message=msg, recursive=True, super_datasets=True)
141+
superds.save(path=ds.path, message=msg, recursive=True)
150142

151143
assert not ds.repo.dirty
152144
# TODO: they are still appearing as native annex symlinked beasts

heudiconv/info.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
'Environment :: Console',
1313
'Intended Audience :: Science/Research',
1414
'License :: OSI Approved :: Apache Software License',
15-
'Programming Language :: Python :: 2.7',
1615
'Programming Language :: Python :: 3.5',
1716
'Programming Language :: Python :: 3.6',
1817
'Programming Language :: Python :: 3.7',
1918
'Topic :: Scientific/Engineering'
2019
]
2120

22-
PYTHON_REQUIRES = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*"
21+
PYTHON_REQUIRES = ">=3.5"
2322

2423
REQUIRES = [
2524
'nibabel',
2625
'pydicom',
2726
'nipype >=1.0.0; python_version > "3.0"',
2827
'nipype >=1.0.0,!=1.2.1,!=1.2.2; python_version == "2.7"',
2928
'pathlib',
30-
'dcmstack>=0.7',
29+
'dcmstack>=0.8',
3130
'etelemetry',
3231
'filelock>=3.0.12',
3332
]
@@ -43,7 +42,7 @@
4342
EXTRA_REQUIRES = {
4443
'tests': TESTS_REQUIRES,
4544
'extras': [], # Requires patched version ATM ['dcmstack'],
46-
'datalad': ['datalad']
45+
'datalad': ['datalad >=0.12.2']
4746
}
4847

4948
# Flatten the lists

heudiconv/tests/test_main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def test_main_help(stdout):
3535
assert stdout.getvalue().startswith("usage: ")
3636

3737

38-
@patch('sys.stderr' if sys.version_info[:2] <= (3, 3) else
39-
'sys.stdout', new_callable=StringIO)
38+
@patch('sys.stdout', new_callable=StringIO)
4039
def test_main_version(std):
4140
with pytest.raises(SystemExit):
4241
runner(['--version'])

heudiconv/tests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def fetch_data(tmpdir, dataset, getpath=None):
5252
"""
5353
from datalad import api
5454
targetdir = op.join(tmpdir, op.basename(dataset))
55-
api.install(path=targetdir,
55+
ds = api.install(path=targetdir,
5656
source='http://datasets-tests.datalad.org/{}'.format(dataset))
5757

5858
getdir = targetdir + (op.sep + getpath if getpath is not None else '')
59-
api.get(getdir)
59+
ds.get(getdir)
6060
return targetdir

heudiconv/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import logging
2020
lgr = logging.getLogger(__name__)
2121

22-
if sys.version_info[0] > 2:
23-
from json.decoder import JSONDecodeError
24-
else:
25-
JSONDecodeError = ValueError
22+
from json.decoder import JSONDecodeError
2623

2724

2825
seqinfo_fields = [
@@ -115,9 +112,7 @@ def anonymize_sid(sid, anon_sid_cmd):
115112
cmd = [anon_sid_cmd, sid]
116113
shell_return = check_output(cmd)
117114

118-
if all([sys.version_info[0] > 2,
119-
isinstance(shell_return, bytes),
120-
isinstance(sid, str)]):
115+
if isinstance(shell_return, bytes) and isinstance(sid, str):
121116
anon_sid = shell_return.decode()
122117
else:
123118
anon_sid = shell_return
@@ -490,8 +485,6 @@ def create_tree(path, tree, archives_leading_dir=True):
490485
create_tree(full_name, load, archives_leading_dir=archives_leading_dir)
491486
else:
492487
with open(full_name, 'w') as f:
493-
if sys.version_info[0] == 2 and not isinstance(load, str):
494-
load = load.encode('utf-8')
495488
f.write(load)
496489
if executable:
497490
os.chmod(full_name, os.stat(full_name).st_mode | stat.S_IEXEC)

0 commit comments

Comments
 (0)