@@ -49,6 +49,10 @@ from os.path import join as pjoin
49
49
50
50
from random import sample
51
51
52
+ # Minimal versions of external dependencies
53
+ MIN_VERSIONS = {
54
+ 'datalad' : '0.7'
55
+ }
52
56
PY3 = sys .version_info [0 ] >= 3
53
57
54
58
import logging
@@ -1548,6 +1552,9 @@ def create_file_if_missing(filename, content):
1548
1552
"""Create file if missing, so we do not override any possibly introduced changes"""
1549
1553
if exists (filename ):
1550
1554
return False
1555
+ dirname = os .path .dirname (filename )
1556
+ if not os .path .exists (dirname ):
1557
+ os .makedirs (dirname )
1551
1558
with open (filename , 'w' ) as f :
1552
1559
f .write (content )
1553
1560
return True
@@ -1684,7 +1691,7 @@ def mark_sensitive(ds, path_glob=None):
1684
1691
if not paths :
1685
1692
return
1686
1693
sens_kwargs ['path' ] = paths
1687
- ds .metadata (** sens_kwargs )
1694
+ ds .metadata (recursive = True , ** sens_kwargs )
1688
1695
1689
1696
1690
1697
def add_to_datalad (topdir , studydir , msg = None , bids = False ):
@@ -1695,7 +1702,8 @@ def add_to_datalad(topdir, studydir, msg=None, bids=False):
1695
1702
from datalad .support .annexrepo import AnnexRepo
1696
1703
1697
1704
from datalad .support .external_versions import external_versions
1698
- assert external_versions ['datalad' ] >= '0.5.1' , "Need datalad >= 0.5.1"
1705
+ # 0.7 added .metadata
1706
+ assert external_versions ['datalad' ] >= MIN_VERSIONS ['datalad' ], "Need datalad >= 0.7"
1699
1707
1700
1708
studyrelpath = os .path .relpath (studydir , topdir )
1701
1709
assert not studyrelpath .startswith (os .path .pardir ) # so we are under
@@ -1740,21 +1748,37 @@ def add_to_datalad(topdir, studydir, msg=None, bids=False):
1740
1748
ds = Dataset (studydir )
1741
1749
# Add doesn't have all the options of save such as msg and supers
1742
1750
ds .add ('.gitattributes' , to_git = True , save = False )
1743
- dsh = None
1751
+ dsh = dsh_path = None
1744
1752
if os .path .lexists (os .path .join (ds .path , '.heudiconv' )):
1745
- dsh = Dataset (opj (ds .path , '.heudiconv' ))
1753
+ dsh_path = opj (ds .path , '.heudiconv' )
1754
+ dsh = Dataset (dsh_path )
1746
1755
if not dsh .is_installed ():
1747
- # we need to create it first
1748
- dsh = ds .create (path = '.heudiconv' ,
1749
- force = True ,
1750
- shared_access = 'all' )
1756
+ # Previously we did not have it as a submodule, and since no
1757
+ # automagic migration is implemented, we just need to check first
1758
+ # if any path under .heudiconv is already under git control
1759
+ if any (x [0 ].startswith ('.heudiconv/' ) for x in
1760
+ ds .repo .repo .index .entries .keys ()):
1761
+ lgr .warning (
1762
+ '%s has .heudiconv not as a submodule from previous versions '
1763
+ 'of heudiconv. No automagic migration is yet provided' , ds
1764
+ )
1765
+ else :
1766
+ # use/create a submodule dataset for .heudiconv
1767
+ dsh = ds .create (path = '.heudiconv' ,
1768
+ force = True ,
1769
+ shared_access = 'all' )
1751
1770
# Since .heudiconv could contain sensitive information
1752
1771
# we place all files under annex and then add
1753
1772
if create_file_if_missing (
1754
- opj (dsh . path , '.gitattributes' ),
1773
+ opj (dsh_path , '.gitattributes' ),
1755
1774
"""* annex.largefiles=anything
1756
1775
""" ):
1757
- dsh .add ('.gitattributes' , message = "Added gitattributes to place all content under annex" )
1776
+ # should work properly if .heudiconv is a submodule or not
1777
+ ds .add (
1778
+ '.heudiconv/.gitattributes' ,
1779
+ to_git = True ,
1780
+ message = "Added gitattributes to place all .heudiconv content under annex"
1781
+ )
1758
1782
ds .add ('.' , recursive = True , save = False ,
1759
1783
# not in effect! ?
1760
1784
#annex_add_opts=['--include-dotfiles']
@@ -1768,9 +1792,10 @@ def add_to_datalad(topdir, studydir, msg=None, bids=False):
1768
1792
mark_sensitive (ds , '*/*/*_scans.tsv' ) # within sess/subj
1769
1793
mark_sensitive (ds , '*/anat' ) # within subj
1770
1794
mark_sensitive (ds , '*/*/anat' ) # within ses/subj
1771
- if dsh :
1772
- mark_sensitive (dsh ) # entire .heudiconv!
1773
- dsh .save (message = msg )
1795
+ if dsh_path :
1796
+ mark_sensitive (ds , '.heudiconv' ) # entire .heudiconv!
1797
+ # if dsh and dsh.is_installed():
1798
+ # dsh.save(message=msg)
1774
1799
ds .save (message = msg , recursive = True , super_datasets = True )
1775
1800
1776
1801
assert not ds .repo .dirty
0 commit comments