Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions babs/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
validate_processing_level,
)

# Analysis-dataset `.gitattributes`: annex a file if it is binary
# (`mimeencoding=binary`, which needs git-annex's MagicMime build flag) or
# larger than 40kb; the explicit lines force listed files into git regardless.
BIDS_GITATTRIBUTES = """\
* annex.backend=MD5E
* annex.largefiles=((mimeencoding=binary)or(largerthan=40kb))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* annex.largefiles=((mimeencoding=binary)or(largerthan=40kb))
* annex.largefiles=((* annex.largefiles=(((mimeencoding=binary)and(largerthan=0))or(largerthan=40kb))

add to your unittest that 0-sized files (which aren't text since can't be judged) are in git, not annex.

**/.git* annex.largefiles=nothing
.babs/** annex.largefiles=nothing
dataset_description.json annex.largefiles=nothing
.bidsignore annex.largefiles=nothing
README* annex.largefiles=nothing
CHANGES annex.largefiles=nothing
LICENSE annex.largefiles=nothing
"""


class BABSBootstrap(BABS):
"""A BABS subclass that implements the bootstrap process."""
Expand Down Expand Up @@ -121,6 +136,15 @@ def babs_bootstrap(
if self.shared_group is not None:
create_kwargs['initopts'] = ['--shared=group']
self._analysis_datalad_handle = dlapi.create(self.analysis_path, **create_kwargs)

# Overwrite the create-time `.gitattributes` before any content is
# saved, so the annex policy applies to every file (see
# BIDS_GITATTRIBUTES):
gitattributes_path = op.join(self.analysis_path, '.gitattributes')
with open(gitattributes_path, 'w') as f:
f.write(BIDS_GITATTRIBUTES)
self.datalad_save(path='.gitattributes', message='Use a BIDS-friendly .gitattributes')

self.input_datasets.update_abs_paths(Path(self.analysis_path))
self.input_datasets.set_inclusion_dataframe(initial_inclusion_df, processing_level)

Expand Down
8 changes: 7 additions & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

from babs import BABSCheckSetup
from babs.base import BABS, CONFIG_SECTIONS
from babs.bootstrap import BABSBootstrap
from babs.bootstrap import BIDS_GITATTRIBUTES, BABSBootstrap
from babs.utils import read_yaml


def test_bootstrap_writes_bids_gitattributes(babs_project_sessionlevel):
"""`babs init` installs the BIDS-friendly `.gitattributes` in `analysis/`."""
gitattributes = Path(babs_project_sessionlevel) / 'analysis' / '.gitattributes'
assert gitattributes.read_text() == BIDS_GITATTRIBUTES


def test_missing_config_parts(babs_project_sessionlevel):
"""Test that missing config parts raise an error."""

Expand Down
Loading