From 48f763a4ecaa95444135739b83e077d9dbeba0ea Mon Sep 17 00:00:00 2001 From: Seyed Yahya Shirazi Date: Fri, 12 Sep 2025 11:37:47 -0700 Subject: [PATCH 1/4] feat: Add generic root-level template macro for non-datatype directories - Create make_root_filename_template macro for root-level directories like /stimuli - Update bidsschematools to skip path-based rules (without datatypes) in entity table and filename templates - Remove stimuli from entity-table.md as it doesn't follow subject-scoped entity ordering - Dynamically look up entity definitions from schema instead of hardcoding mappings --- src/appendices/entity-table.md | 4 --- tools/mkdocs_macros_bids/macros.py | 35 ++++++++++++++----- .../src/bidsschematools/render/tables.py | 4 +++ .../src/bidsschematools/render/text.py | 3 ++ 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/appendices/entity-table.md b/src/appendices/entity-table.md index 549b0685fb..bf69bdc863 100644 --- a/src/appendices/entity-table.md +++ b/src/appendices/entity-table.md @@ -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"]) }} diff --git a/tools/mkdocs_macros_bids/macros.py b/tools/mkdocs_macros_bids/macros.py index 03d0ddc57b..09f9f3ecb5 100644 --- a/tools/mkdocs_macros_bids/macros.py +++ b/tools/mkdocs_macros_bids/macros.py @@ -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 @@ -147,17 +158,25 @@ def make_root_filename_template( template_lines.append(f" {rule.stem}{ext}") elif hasattr(rule, "suffixes"): - # Handle entity-based files (like stim-