From 02f07f957394ad33650375d89064901917d7d506 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Fri, 16 Feb 2024 15:08:06 -0500 Subject: [PATCH] add nidataops config to setup gitattrs --- docker/datalad-apptainer/Dockerfile | 1 + docker/datalad-apptainer/cfg_nidataops.py | 45 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 docker/datalad-apptainer/cfg_nidataops.py diff --git a/docker/datalad-apptainer/Dockerfile b/docker/datalad-apptainer/Dockerfile index fe14f7d..5b5b923 100644 --- a/docker/datalad-apptainer/Dockerfile +++ b/docker/datalad-apptainer/Dockerfile @@ -38,5 +38,6 @@ RUN apk add --no-cache py3-pytest ca-certificates libseccomp squashfs-tools tzda && rm -rf /tmp/* /var/cache/apk/* RUN pip install --break-system-packages --no-cache-dir datalad datalad-container ssh_agent_setup python-gitlab +ADD cfg_nidataops.py /usr/lib/python3.11/site-packages/datalad/resources/procedures/ WORKDIR /work diff --git a/docker/datalad-apptainer/cfg_nidataops.py b/docker/datalad-apptainer/cfg_nidataops.py new file mode 100644 index 0000000..c979011 --- /dev/null +++ b/docker/datalad-apptainer/cfg_nidataops.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +"""Procedure to configure Git annex to add text files directly to Git""" + +import sys +import os.path as op + +from datalad.distribution.dataset import require_dataset + +ds = require_dataset( + sys.argv[1], + check_installed=True, + purpose='configuration') + +nthg = {'annex.largefiles': 'nothing'} +anthg = {'annex.largefiles': 'anything'} +annex_largefiles = '((mimeencoding=binary)and(largerthan=0))' +attrs = ds.repo.get_gitattributes('*') +if not attrs.get('*', {}).get( + 'annex.largefiles', None) == annex_largefiles: + ds.repo.set_gitattributes([ + ('*', {'annex.largefiles': annex_largefiles}), + ('.gitignore', nthg), + ('.gitmodules', nthg), + ('.gitlab-ci.yml', nthg), + ('.all-contributorsrc', nthg), + ('.bidsignore', nthg), + ('*.json', nthg), + ('*.txt', nthg), + ('*.tsv', nthg), + ('*.nii.gz', anthg), + ('*.tgz', anthg), + ('*_scans.tsv', anthg), + # annex event files as they contain subjects behavioral responses + ('sub-*/**/*_events.tsv', anthg), + ('*.bk2', anthg), + ('*.html', anthg), + ('*.svg', anthg), + ]) + +git_attributes_file = op.join(ds.path, '.gitattributes') +ds.save( + git_attributes_file, + message="Setup gitattributes for ni-dataops", + result_renderer='disabled' +)