Skip to content

Commit d6beebb

Browse files
author
Benedikt Ehinger
committed
added new test, modified structure to allow disabling of push to dataverse
1 parent 7dfc969 commit d6beebb

File tree

19 files changed

+290
-40
lines changed

19 files changed

+290
-40
lines changed

lslautobids/config_globals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self):
1313
"redo_bids_conversion": False,
1414
"reupload": False,
1515
"redo_other_pc": False,
16+
"push_to_dataverse": True,
1617
}
1718

1819
def init(self, args):

lslautobids/convert_to_bids_and_upload.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def convert_to_bids(self, xdf_path,subject_id,session_id, run_id, task_id,other,
364364
# Validate BIDS data
365365
logger.info("Validating BIDS data...")
366366
# Validate the BIDS data
367-
val = self.validate_bids(bids_root+project_name,subject_id,session_id, logger)
367+
val = self.validate_bids(os.path.join(bids_root,project_name),subject_id,session_id, logger)
368368
return val
369369

370370
def validate_bids(self,bids_path,subject_id,session_id, logger):
@@ -482,26 +482,29 @@ def bids_process_and_upload(processed_files,logger):
482482
bids.populate_dataset_description_json(project_name, logger)
483483
logger.info('Generating metadatafiles........')
484484
generate_json_file(project_name, logger)
485-
logger.info('Generating dataverse dataset........')
486485

487-
doi, status = create_dataverse(project_name)
488486

489-
logger.info("Creating and adding files to Dataverse dataset...")
490-
create_and_add_files_to_datalad_dataset(bids_root+project_name,status, logger)
487+
logger.info("Creating and adding files to Datalad dataset...")
488+
create_and_add_files_to_datalad_dataset(os.path.join(bids_root,project_name),logger)
491489

492-
if status == 0:
493-
logger.info('Linking dataverse dataset with datalad')
494-
add_sibling_dataverse_in_folder(doi, logger)
495-
496-
if cli_args.yes:
497-
logger.info('Pushing files to dataverse........')
498-
push_files_to_dataverse(project_name, logger)
499-
else:
500-
user_input = get_user_input("Do you want to push the files to Dataverse? ",logger)
490+
if cli_args.push_to_dataverse:
491+
logger.info('Generating dataverse dataset........')
492+
doi, status = create_dataverse(project_name, logger)
493+
if status == 0: # run only if a new dataverse was created
494+
logger.info('Linking dataverse dataset with datalad')
495+
add_sibling_dataverse_in_folder(doi, logger)
496+
497+
if cli_args.yes:
498+
user_input = "y"
499+
else:
500+
user_input = get_user_input("Do you want to push the files to Dataverse? ",logger)
501+
501502
if user_input == "y":
502503
logger.info('Pushing files to dataverse........')
503504
push_files_to_dataverse(project_name, logger)
504505
elif user_input == "n":
505506
logger.info("Program aborted.")
506507
else:
507508
logger.error("Invalid Input.")
509+
else:
510+
logger.info('cli.push_to_dataverse was false, not pushing.')

lslautobids/datalad_create.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@
22
import os
33

44

5-
def create_and_add_files_to_datalad_dataset(dataset_path,flag, logger):
5+
def create_and_add_files_to_datalad_dataset(dataset_path,logger):
66
message = "LSL Auto BIDS: new files found and added"
7-
if flag==0:
7+
#if flag==0:
8+
9+
try:
10+
dl.Dataset(dataset_path)
11+
except:
812
message ="LSL Auto BIDS: new datalad dataset created"
913
# Create a new dataset
1014
logger.info('Creating a new datalad dataset........')
1115
try:
1216
dl.create(dataset_path, force=True) # files already exist, so we eforce it
17+
18+
# make sure only large files are saved
19+
with open(os.path.join(dataset_path,".gitattributes"), "a") as f:
20+
f.write("* annex.largefiles=largerthan=100kb")
21+
f.write("\n*.csv annex.largefiles=nothing")
22+
f.write("\n*.log annex.largefiles=nothing")
23+
f.write("\n*.tsv annex.largefiles=nothing")
24+
f.write("\n*.md annex.largefiles=nothing")
25+
f.write("\n*.json annex.largefiles=nothing")
26+
1327
except:
1428
logger.info("Could not create a new dataset, maybe it exists already?")
1529

16-
# Commit changes
17-
# Change to dataset path
18-
os.chdir(dataset_path)
19-
if flag==0:
20-
# needed to modify participants.tsv etc. later
21-
with open(os.path.join(dataset_path,".gitattributes"), "a") as f:
22-
f.write("* annex.largefiles=largerthan=100kb")
23-
f.write("\n*.csv annex.largefiles=nothing")
24-
f.write("\n*.log annex.largefiles=nothing")
25-
f.write("\n*.tsv annex.largefiles=nothing")
26-
f.write("\n*.md annex.largefiles=nothing")
27-
f.write("\n*.json annex.largefiles=nothing")
30+
31+
# commit current files
2832
logger.info('Committing current changes........')
29-
dl.save(path = '.', message=message)
33+
dl.save(path = dataset_path, message=message)
3034

lslautobids/dataverse_dataset_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
logger = logging.getLogger(__name__)
1313
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
1414

15-
def create_dataverse(project_name):
15+
def create_dataverse(project_name, logger):
1616
"""
1717
Creates a Dataverse dataset and returns the PID and dataset ID.
1818

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ build-backend = "setuptools.build_meta"
66
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
77
skip = '.git*,*.svg,*.bib'
88
check-hidden = true
9+
10+
[dependency-groups]
11+
dev = [
12+
"git-annex>=10.20251114",
13+
"pytest>=9.0.1",
14+
]
915
# ignore-regex = ''
1016
# ignore-words-list = ''
File renamed without changes.

tests/test_utils/path_config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ def get_root_paths(test_file: str):
1818
}
1919

2020

21+
22+
23+
# Dummy CLI argument simulation
24+
class DummyCLIArgs:
25+
def __init__(self):
26+
self.project_name = "test-project"
27+
self.yes = True
28+
self.redo_bids_conversion = False
29+
self.redo_other_pc = False
30+
self.push_to_dataverse = False
31+
def init(self, args):
32+
# you can store the args or ignore
33+
pass

tests/testcases/test_main_functionality/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
time event what
2+
00:00 cap size selection
3+
00:00 camera working y/n
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
id age gender handedness dom_eye no_preex_conditions visual_acuity_test remarks

0 commit comments

Comments
 (0)