Skip to content

Commit eeea82e

Browse files
authored
Merge branch 'main' into dependabot/pip/numpy-lte-2.1.3
2 parents c9d137b + 9c705b0 commit eeea82e

File tree

9 files changed

+350
-94
lines changed

9 files changed

+350
-94
lines changed

.circleci/config.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2.1
22
orbs:
3-
codecov: codecov/codecov@1.0.5
3+
codecov: codecov/codecov@3.2.4
44

55
jobs:
66
run_pytests:
@@ -31,10 +31,8 @@ jobs:
3131
source activate cubids
3232
conda install -c conda-forge -y datalad
3333
34-
# Add nodejs and the validator
35-
conda install nodejs
36-
npm install -g yarn && \
37-
npm install -g [email protected]
34+
# Add deno to run the schema validator
35+
conda install deno
3836
3937
# Install CuBIDS
4038
pip install -e .[tests]
@@ -64,7 +62,8 @@ jobs:
6462
6563
# We need curl for the codecov upload
6664
apt-get update
67-
apt-get install -yqq curl
65+
apt-get install -y -qq curl
66+
apt-get install -y gnupg
6867
6968
cd /home/circleci/src/coverage/
7069
echo "Merge coverage files"

cubids/cli.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _parse_validate():
4343
type=PathExists,
4444
action="store",
4545
help=(
46-
"the root of a BIDS dataset. It should contain "
46+
"The root of a BIDS dataset. It should contain "
4747
"sub-X directories and dataset_description.json"
4848
),
4949
)
@@ -107,6 +107,41 @@ def _enter_validate(argv=None):
107107
workflows.validate(**args)
108108

109109

110+
def _parse_bids_version():
111+
parser = argparse.ArgumentParser(
112+
description="cubids bids-version: Get BIDS Validator and Schema version",
113+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
114+
)
115+
PathExists = partial(_path_exists, parser=parser)
116+
117+
parser.add_argument(
118+
"bids_dir",
119+
type=PathExists,
120+
action="store",
121+
help=(
122+
"The root of a BIDS dataset. It should contain "
123+
"sub-X directories and dataset_description.json"
124+
),
125+
)
126+
parser.add_argument(
127+
"--write",
128+
action="store_true",
129+
default=False,
130+
help=(
131+
"Save the validator and schema version to 'dataset_description.json' "
132+
"when using `cubids bids-version /bids/path --write`. "
133+
"By default, `cubids bids-version /bids/path` prints to the terminal."
134+
),
135+
)
136+
return parser
137+
138+
139+
def _enter_bids_version(argv=None):
140+
options = _parse_bids_version().parse_args(argv)
141+
args = vars(options).copy()
142+
workflows.bids_version(**args)
143+
144+
110145
def _parse_bids_sidecar_merge():
111146
parser = argparse.ArgumentParser(
112147
description=("bids-sidecar-merge: merge critical keys from one sidecar to another"),
@@ -153,7 +188,7 @@ def _parse_group():
153188
type=PathExists,
154189
action="store",
155190
help=(
156-
"the root of a BIDS dataset. It should contain "
191+
"The root of a BIDS dataset. It should contain "
157192
"sub-X directories and dataset_description.json"
158193
),
159194
)
@@ -220,7 +255,7 @@ def _parse_apply():
220255
type=PathExists,
221256
action="store",
222257
help=(
223-
"the root of a BIDS dataset. It should contain "
258+
"The root of a BIDS dataset. It should contain "
224259
"sub-X directories and dataset_description.json"
225260
),
226261
)
@@ -316,7 +351,7 @@ def _parse_datalad_save():
316351
type=PathExists,
317352
action="store",
318353
help=(
319-
"the root of a BIDS dataset. It should contain "
354+
"The root of a BIDS dataset. It should contain "
320355
"sub-X directories and dataset_description.json"
321356
),
322357
)
@@ -358,7 +393,7 @@ def _parse_undo():
358393
type=PathExists,
359394
action="store",
360395
help=(
361-
"the root of a BIDS dataset. It should contain "
396+
"The root of a BIDS dataset. It should contain "
362397
"sub-X directories and dataset_description.json"
363398
),
364399
)
@@ -582,7 +617,7 @@ def _parse_remove_metadata_fields():
582617
type=PathExists,
583618
action="store",
584619
help=(
585-
"the root of a BIDS dataset. It should contain "
620+
"The root of a BIDS dataset. It should contain "
586621
"sub-X directories and dataset_description.json"
587622
),
588623
)
@@ -628,7 +663,7 @@ def _parse_print_metadata_fields():
628663
type=PathExists,
629664
action="store",
630665
help=(
631-
"the root of a BIDS dataset. It should contain "
666+
"The root of a BIDS dataset. It should contain "
632667
"sub-X directories and dataset_description.json"
633668
),
634669
)
@@ -655,6 +690,7 @@ def _enter_print_metadata_fields(argv=None):
655690

656691
COMMANDS = [
657692
("validate", _parse_validate, workflows.validate),
693+
("bids-version", _parse_bids_version, workflows.bids_version),
658694
("sidecar-merge", _parse_bids_sidecar_merge, workflows.bids_sidecar_merge),
659695
("group", _parse_group, workflows.group),
660696
("apply", _parse_apply, workflows.apply),

cubids/cubids.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,20 @@ def get_all_metadata_fields(self):
13361336
found_fields = set()
13371337
for json_file in Path(self.path).rglob("*.json"):
13381338
if ".git" not in str(json_file):
1339-
with open(json_file, "r") as jsonr:
1340-
metadata = json.load(jsonr)
1341-
found_fields.update(metadata.keys())
1339+
# add this in case `print-metadata-fields` is run before validate
1340+
try:
1341+
with open(json_file, "r", encoding="utf-8") as jsonr:
1342+
content = jsonr.read().strip()
1343+
if not content:
1344+
print(f"Empty file: {json_file}")
1345+
continue
1346+
metadata = json.loads(content)
1347+
found_fields.update(metadata.keys())
1348+
except json.JSONDecodeError as e:
1349+
warnings.warn(f"Error decoding JSON in {json_file}: {e}")
1350+
except Exception as e:
1351+
warnings.warn(f"Unexpected error with file {json_file}: {e}")
1352+
13421353
return sorted(found_fields)
13431354

13441355
def remove_metadata_fields(self, fields_to_remove):

cubids/tests/test_bond.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import numpy as np
1010
import pandas as pd
1111
import pytest
12+
from packaging.version import Version
1213

1314
from cubids.cubids import CuBIDS
1415
from cubids.metadata_merge import merge_json_into_json, merge_without_overwrite
@@ -22,7 +23,15 @@
2223
file_hash,
2324
get_data,
2425
)
25-
from cubids.validator import build_validator_call, parse_validator_output, run_validator
26+
from cubids.validator import (
27+
build_validator_call,
28+
parse_validator_output,
29+
run_validator,
30+
get_bids_validator_version,
31+
extract_summary_info,
32+
update_dataset_description,
33+
bids_validator_version,
34+
)
2635

2736
COMPLETE_KEY_GROUPS = [
2837
"acquisition-HASC55AP_datatype-dwi_suffix-dwi",
@@ -1028,6 +1037,39 @@ def test_validator(tmp_path):
10281037
assert isinstance(parsed, pd.DataFrame)
10291038

10301039

1040+
def test_bids_version(tmp_path):
1041+
"""Test workflows.bids_version."""
1042+
data_root = get_data(tmp_path)
1043+
bids_dir = Path(data_root) / "complete"
1044+
1045+
# Ensure the test directory exists
1046+
assert bids_dir.exists()
1047+
1048+
# test the validator in valid dataset
1049+
call = build_validator_call(bids_dir)
1050+
ret = run_validator(call)
1051+
1052+
assert ret.returncode == 0
1053+
1054+
decoded = ret.stdout.decode("UTF-8")
1055+
1056+
# Get the BIDS validator version
1057+
validator_version = Version(get_bids_validator_version()["ValidatorVersion"])
1058+
# Extract schemaVersion
1059+
schema_version = Version(extract_summary_info(decoded)["SchemaVersion"])
1060+
1061+
# Set baseline versions to compare against
1062+
min_validator_version = Version("2.0.0")
1063+
min_schema_version = Version("0.11.3")
1064+
1065+
assert (
1066+
validator_version >= min_validator_version
1067+
), f"Validator version {validator_version} is less than minimum {min_validator_version}"
1068+
assert (
1069+
schema_version >= min_schema_version
1070+
), f"Schema version {schema_version} is less than minimum {min_schema_version}"
1071+
1072+
10311073
def test_docker():
10321074
"""Verify that docker is installed and the user has permission to run docker images.
10331075

cubids/tests/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
"""
1515

1616
import argparse
17+
1718
import pytest
1819

19-
from cubids.cli import _path_exists, _is_file, _get_parser, _main
20+
from cubids.cli import _get_parser, _is_file, _main, _path_exists
2021

2122

2223
def _test_path_exists():

0 commit comments

Comments
 (0)