10
10
11
11
lgr = logging .getLogger (__name__ )
12
12
13
- MIN_VERSION = '0.7 '
13
+ MIN_VERSION = '0.12.2 '
14
14
15
15
16
16
def prepare_datalad (studydir , outdir , sid , session , seqinfo , dicoms , bids ):
@@ -34,36 +34,33 @@ def prepare_datalad(studydir, outdir, sid, session, seqinfo, dicoms, bids):
34
34
def add_to_datalad (topdir , studydir , msg , bids ):
35
35
"""Do all necessary preparations (if were not done before) and save
36
36
"""
37
- from datalad .api import create
37
+ import datalad .api as dl
38
38
from datalad .api import Dataset
39
39
from datalad .support .annexrepo import AnnexRepo
40
40
from datalad .support .external_versions import external_versions
41
41
assert external_versions ['datalad' ] >= MIN_VERSION , (
42
- "Need datalad >= {}" .format (MIN_VERSION )) # add to reqs
42
+ "Need datalad >= {}" .format (MIN_VERSION )) # add to reqs
43
43
44
- create_kwargs = {}
45
- if external_versions ['datalad' ] >= '0.10' :
46
- create_kwargs ['fake_dates' ] = True # fake dates by default
47
44
48
45
studyrelpath = op .relpath (studydir , topdir )
49
46
assert not studyrelpath .startswith (op .pardir ) # so we are under
50
47
# now we need to test and initiate a DataLad dataset all along the path
51
48
curdir_ = topdir
52
49
superds = None
53
- subdirs = ['' ] + studyrelpath .split (op .sep )
50
+ subdirs = ['' ] + [ d for d in studyrelpath .split (op .sep ) if d != os . curdir ]
54
51
for isubdir , subdir in enumerate (subdirs ):
55
52
curdir_ = op .join (curdir_ , subdir )
56
53
ds = Dataset (curdir_ )
57
54
if not ds .is_installed ():
58
55
lgr .info ("Initiating %s" , ds )
59
56
# would require annex > 20161018 for correct operation on annex v6
60
57
# need to add .gitattributes first anyways
61
- ds_ = create (curdir_ , dataset = superds ,
58
+ ds_ = dl . create (curdir_ , dataset = superds ,
62
59
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 ,
64
63
# shared_access='all',
65
- annex_version = 6 ,
66
- ** create_kwargs
67
64
)
68
65
assert ds == ds_
69
66
assert ds .is_installed ()
@@ -93,17 +90,13 @@ def add_to_datalad(topdir, studydir, msg, bids):
93
90
with open (gitattributes_path , 'wb' ) as f :
94
91
f .write ('\n ' .join (known_attrs ).encode ('utf-8' ))
95
92
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
+
101
94
# 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 )
105
98
# 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 )
107
100
dsh = dsh_path = None
108
101
if op .lexists (op .join (ds .path , '.heudiconv' )):
109
102
dsh_path = op .join (ds .path , '.heudiconv' )
@@ -120,7 +113,6 @@ def add_to_datalad(topdir, studydir, msg, bids):
120
113
else :
121
114
dsh = ds .create (path = '.heudiconv' ,
122
115
force = True ,
123
- ** create_kwargs
124
116
# shared_access='all'
125
117
)
126
118
# Since .heudiconv could contain sensitive information
@@ -146,7 +138,7 @@ def add_to_datalad(topdir, studydir, msg, bids):
146
138
mark_sensitive (ds , '*/*/anat' ) # within ses/subj
147
139
if dsh_path :
148
140
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 )
150
142
151
143
assert not ds .repo .dirty
152
144
# TODO: they are still appearing as native annex symlinked beasts
0 commit comments