-
Notifications
You must be signed in to change notification settings - Fork 13
/
cfg_bids.py
57 lines (50 loc) · 1.53 KB
/
cfg_bids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""Procedure to apply a sensible BIDS default setup to a dataset
"""
import sys
from datalad.distribution.dataset import require_dataset
from datalad.support import path as op
ds = require_dataset(
sys.argv[1],
check_installed=True,
purpose='BIDS dataset configuration')
# unless taken care of by the template already, each item in here
# will get its own .gitattributes entry to keep it out of the annex
# give relative path to dataset root (use platform notation)
force_in_git = [
'README*',
'CHANGES',
'LICENSE',
'dataset_description.json',
'.bids-validator-config.json',
'.bidsignore',
'code/**',
# to not put participants or scan info into Git, might contain sensitive
# information
#'*.tsv',
]
# make an attempt to discover the prospective change in .gitattributes
# to decide what needs to be done, and make this procedure idempotent
# (for simple cases)
attr_fpath = op.join(ds.path, '.gitattributes')
if op.lexists(attr_fpath):
with open(attr_fpath, 'rb') as f:
attrs = f.read().decode()
else:
attrs = ''
# amend gitattributes, if needed
ds.repo.set_gitattributes([
(path, {'annex.largefiles': 'nothing'})
for path in force_in_git
if '{} annex.largefiles=nothing'.format(path) not in attrs
])
# leave clean
ds.save(
path=['.gitattributes'],
message="Apply default BIDS dataset setup",
to_git=True,
)
# run metadata type config last, will do another another commit
ds.run_procedure(
spec=['cfg_metadatatypes', 'bids', 'nifti1'],
)