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: