From 7d8844e6783f0e79768e635760a647f8b3ae9c5e Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 17 Dec 2023 09:43:00 -0500 Subject: [PATCH] FIX: Implement inheritance for all TSV/JSON files --- tools/schemacode/bidsschematools/rules.py | 40 ++++++++++------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/tools/schemacode/bidsschematools/rules.py b/tools/schemacode/bidsschematools/rules.py index d0d6f5dae9..22e1fce649 100644 --- a/tools/schemacode/bidsschematools/rules.py +++ b/tools/schemacode/bidsschematools/rules.py @@ -130,7 +130,7 @@ def _entity_rule(rule: Mapping, schema: bst.types.Namespace): } -def _split_inheritance_rules(rule: Mapping) -> ty.List[Mapping]: +def _split_inheritance_rules(rule: dict) -> ty.List[dict]: """Break composite rules into main and sidecar rules Implements the inheritance principle for file naming. @@ -139,32 +139,28 @@ def _split_inheritance_rules(rule: Mapping) -> ty.List[Mapping]: rule_exts = set(rule["extensions"]) main_exts = rule_exts - heritable_exts - # If a rule only has TSV or JSON files, entities can be - # made required - if not main_exts: - if ".tsv" in rule_exts: - main_exts = {".tsv"} - elif ".json" in rule_exts: - main_exts = {".json"} - sidecar_exts = rule_exts - main_exts if not sidecar_exts: return [rule] - sidecar_dtypes = [""] + rule.get("datatypes", []) - sidecar_entities = {ent: "optional" for ent in rule["entities"]} - - main_rule = {**rule, **{"extensions": list(main_exts)}} - sidecar_rule = { - **rule, - **{ - "extensions": list(sidecar_exts), - "datatypes": sidecar_dtypes, - "entities": sidecar_entities, - }, - } + rules = [] + + # Some rules only address metadata, such as events.tsv or coordsystem.json + if main_exts: + rules.append({**rule, **{"extensions": list(main_exts)}}) + + rules.append( + { + **rule, + **{ + "extensions": list(sidecar_exts), + "datatypes": [""] + rule.get("datatypes", []), + "entities": {ent: "optional" for ent in rule["entities"]}, + }, + } + ) - return [main_rule, sidecar_rule] + return rules def _sanitize_extension(ext: str) -> str: