Skip to content

Commit

Permalink
ENH: Determine dataset type from bundled dataset_description.json
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Feb 29, 2024
1 parent 8798e5b commit 7c05f08
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tools/schemacode/bidsschematools/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json

Check warning on line 1 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L1

Added line #L1 was not covered by tests
import logging
import os
import re
Expand Down Expand Up @@ -69,14 +70,30 @@ def pre_receive_hook(schema, input_, output):
lines = fobj.readlines()

Check warning on line 70 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L69-L70

Added lines #L69 - L70 were not covered by tests

split = lines.index("0001\n")
ignore = [line.rstrip() for line in lines[:split]]
preamble = [line.rstrip() for line in lines[:split]]
filenames = [line.rstrip() for line in lines[split + 1 :]]
try:
split = preamble.index("0000")
except ValueError:
description = {}
ignore = preamble

Check warning on line 79 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L72-L79

Added lines #L72 - L79 were not covered by tests
else:
description = json.loads("".join(preamble[:split]))
ignore = preamble[split + 1 :]

Check warning on line 82 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L81-L82

Added lines #L81 - L82 were not covered by tests

dataset_type = description.get("DatasetType", "raw")

Check warning on line 84 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L84

Added line #L84 was not covered by tests

schema = load_schema(schema)
all_rules = chain.from_iterable(

Check warning on line 87 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L86-L87

Added lines #L86 - L87 were not covered by tests
regexify_filename_rules(group, schema, level=2)
for group in (schema.rules.files.common, schema.rules.files.raw)
)
if dataset_type == "derivative":
all_rules = chain(

Check warning on line 92 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L91-L92

Added lines #L91 - L92 were not covered by tests
all_rules,
regexify_filename_rules(schema.rules.files.derivatives, schema, level=2),
)

regexes = [rule["regex"] for rule in all_rules]

Check warning on line 97 in tools/schemacode/bidsschematools/__main__.py

View check run for this annotation

Codecov / codecov/patch

tools/schemacode/bidsschematools/__main__.py#L97

Added line #L97 was not covered by tests
# XXX Hack for phenotype files - this can be removed once we
# have a schema definition for them
Expand Down

0 comments on commit 7c05f08

Please sign in to comment.