Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/appendices/entity-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,3 @@ while entity definitions are in the [Entities Appendix](entities.md).
## Motion

{{ MACROS___make_entity_table(datatypes=["motion"]) }}

## Stimulus Files

{{ MACROS___make_entity_table(datatypes=["stimuli"]) }}
66 changes: 56 additions & 10 deletions tools/mkdocs_macros_bids/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ def make_root_filename_template(
if src_path is None:
src_path = _get_source_path()

schema_obj = schema.load_schema()
# Load schema with explicit path to avoid caching issues
import os

schema_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
"src",
"schema.json",
)
if os.path.exists(schema_path):
schema_obj = schema.load_schema(schema_path)
else:
schema_obj = schema.load_schema()

# Look for rules that have a specific path (root-level organization)
target_path = kwargs.get("path", "stimuli") # Default to stimuli
Expand Down Expand Up @@ -147,17 +158,30 @@ def make_root_filename_template(
template_lines.append(f" {rule.stem}{ext}")

elif hasattr(rule, "suffixes"):
# Handle entity-based files (like stim-<label>_audio.wav)
# Handle entity-based files generically using entity definitions from schema
entities_part = ""
if hasattr(rule, "entities"):
entity_parts = []
for entity_name, requirement in rule.entities.items():
if entity_name == "stimulus":
entity_parts.append("stim-<label>")
elif entity_name == "part":
entity_parts.append("[_part-<label>]")
elif entity_name == "annotation":
entity_parts.append("_annot-<label>")
# Look up the entity in the schema to get its prefix and format
if entity_name in schema_obj.objects.entities:
entity_def = schema_obj.objects.entities[entity_name]
entity_prefix = entity_def.get("name", entity_name)
entity_format = entity_def.get("format", "label")

# Format based on requirement (required vs optional)
if requirement == "optional":
entity_parts.append(f"[_{entity_prefix}-<{entity_format}>]")
else:
# First entity doesn't need underscore prefix
if not entity_parts:
entity_parts.append(
f"{entity_prefix}-<{entity_format}>"
)
else:
entity_parts.append(
f"_{entity_prefix}-<{entity_format}>"
)
entities_part = "".join(entity_parts)

for suffix in rule.suffixes:
Expand Down Expand Up @@ -353,7 +377,18 @@ def make_sidecar_table(table_name, src_path=None):
if src_path is None:
src_path = _get_source_path()

schema_obj = schema.load_schema()
# Load schema with explicit path to avoid caching issues
import os

schema_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
"src",
"schema.json",
)
if os.path.exists(schema_path):
schema_obj = schema.load_schema(schema_path)
else:
schema_obj = schema.load_schema()
table = render.make_sidecar_table(schema_obj, table_name, src_path=src_path)
return table

Expand Down Expand Up @@ -412,7 +447,18 @@ def make_columns_table(table_name, src_path=None):
if src_path is None:
src_path = _get_source_path()

schema_obj = schema.load_schema()
# Load schema with explicit path to avoid caching issues
import os

schema_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
"src",
"schema.json",
)
if os.path.exists(schema_path):
schema_obj = schema.load_schema(schema_path)
else:
schema_obj = schema.load_schema()
table = render.make_columns_table(schema_obj, table_name, src_path=src_path)
return table

Expand Down
4 changes: 4 additions & 0 deletions tools/schemacode/src/bidsschematools/render/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ def make_entity_table(schema, tablefmt="github", src_path=None, **kwargs):
if not suffixes:
continue

# Skip rules that don't have datatypes (e.g., stimuli rules with path-based organization)
if not hasattr(rule, "datatypes"):
continue

entities = []
for ent in schema.rules.entities:
val = rule.entities.get(ent, "")
Expand Down
3 changes: 3 additions & 0 deletions tools/schemacode/src/bidsschematools/render/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ def make_filename_template(
file_rules = schema.rules.files[dstype]
file_groups = {}
for rule in file_rules.values(level=2):
# Skip rules that don't have datatypes (e.g., stimuli rules with path-based organization)
if not hasattr(rule, "datatypes"):
continue
for datatype in rule.datatypes:
file_groups.setdefault(datatype, []).append(rule)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_make_filename_template(schema_obj, schema_dir, placeholders):
datatypes = {
datatype
for rule in schema_obj.rules.files.raw.values(level=2)
if hasattr(rule, "datatypes") # Skip rules without datatypes (e.g., stimuli)
for datatype in rule.datatypes
}

Expand Down
Loading