Commit ebb7cc83 authored by Sébastien Tourbier's avatar Sébastien Tourbier
Browse files

feat(handlers.dataset): call datalad create() and save() methods

parent 546adcb4
Loading
Loading
Loading
Loading
+30 −10
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ import json
import re
from sre_constants import SUCCESS

import datalad.api

# BIDS Manager Python package has to be accessible.
try:
    from bids_manager.ins_bids_class import (
@@ -36,12 +38,25 @@ class DatasetHandler:
            datasetdesc_dict[bids_key] = bids_value
        # Write the dataset_description.json file only if it does not exist
        dataset_name = self.make_safe_filename(input_data["dataset_dirname"])
        # Create the BIDS dataset directory if it does not exist
        ds_path = os.path.join(self.dataset_path, dataset_name)
        if not os.path.isdir(ds_path):
            os.makedirs(ds_path)
        # Initialize the BIDS dataset as a Datalad-managed dataset
        datalad.api.create(
            dataset=ds_path,
            cfg_proc=['text2git', 'bids']
        )
        datasetdesc_path = os.path.join(ds_path, "dataset_description.json")
        if not os.path.isfile(datasetdesc_path):
            # Write the dataset_description.json file
            datasetdesc_dict.write_file(jsonfilename=datasetdesc_path)
            # Save the state of the dataset with Datalad
            datalad.api.save(
                dataset=ds_path,
                message='Initial BIDS dataset state',
                recursive=True
            )
        # Load the created BIDS dataset in BIDS Manager (creates companion files)
        ds_obj = BidsDataset(ds_path)
        if ds_obj:
@@ -96,6 +111,11 @@ class DatasetHandler:
            BidsDataset.dirname = os.path.join(ds_obj.dirname)
            req_dict.save_as_json(req_path)
            ds_obj.get_requirements()
            # Save state of dataset with Datalad
            datalad.api.save(
                dataset=BidsDataset.dirname,
                message='Overwrite the converters in the BIDS Manager requirements.json file'
            )

    @staticmethod
    def get_run(root_dir: str, bids_entities: dict, bids_modality: str):