bids-specification
bids-specification copied to clipboard
[BUG] Template generation macro doesn't work for derivatives
Trying to use the template macro with derivatives fails with:
WARNING - [macros] - ERROR # _Macro Rendering Error_
_File_: `derivatives/imaging.md`
_AttributeError_: 'Namespace' object has no attribute 'datatypes'
```
Traceback (most recent call last):
File "/data/home/oesteban/workspace/bids-specification/tools/schemacode/src/bidsschematools/types/namespace.py", line 220, in
__getattribute__
return self[key]
~~~~^^^^^
File "/data/home/oesteban/workspace/bids-specification/tools/schemacode/src/bidsschematools/types/namespace.py", line 236, in
__getitem__
val = mapping[subkey]
~~~~~~~^^^^^^^^
KeyError: 'datatypes'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/oesteban/.miniconda/envs/bids-spec/lib/python3.11/site-packages/mkdocs_macros/plugin.py", line 688, in render
return md_template.render(**page_variables)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/oesteban/.miniconda/envs/bids-spec/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/home/oesteban/.miniconda/envs/bids-spec/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 8, in top-level template code
File "/data/home/oesteban/workspace/bids-specification/tools/mkdocs_macros_bids/macros.py", line 94, in make_filename_template
codeblock = render.make_filename_template(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/home/oesteban/workspace/bids-specification/tools/schemacode/src/bidsschematools/render/text.py", line 323, in
make_filename_template
for datatype in rule.datatypes:
^^^^^^^^^^^^^^
File "/data/home/oesteban/workspace/bids-specification/tools/schemacode/src/bidsschematools/types/namespace.py", line 222, in
__getattribute__
raise err
File "/data/home/oesteban/workspace/bids-specification/tools/schemacode/src/bidsschematools/types/namespace.py", line 214, in
__getattribute__
return super().__getattribute__(key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Namespace' object has no attribute 'datatypes'
```
Originally posted by @oesteban in https://github.com/bids-standard/bids-specification/issues/1781#issuecomment-2686101512
This problem blocks a list of templates compiled by @effigies from being updated:
https://github.com/bids-standard/bids-specification/blob/0142056a79a292292697cf2bf086618ce12a9a51/src/derivatives/imaging.md?plain=1#L10-L15
https://github.com/bids-standard/bids-specification/blob/0142056a79a292292697cf2bf086618ce12a9a51/src/derivatives/imaging.md?plain=1#L147-L152
https://github.com/bids-standard/bids-specification/blob/0142056a79a292292697cf2bf086618ce12a9a51/src/derivatives/imaging.md?plain=1#L264-L269
https://github.com/bids-standard/bids-specification/blob/0142056a79a292292697cf2bf086618ce12a9a51/src/derivatives/imaging.md?plain=1#L328-L333
https://github.com/bids-standard/bids-specification/blob/0142056a79a292292697cf2bf086618ce12a9a51/src/derivatives/imaging.md?plain=1#L402-L407
https://github.com/bids-standard/bids-specification/blob/0142056a79a292292697cf2bf086618ce12a9a51/src/derivatives/common-data-types.md?plain=1#L180-L185