Skip to content

[BUG] Template generation macro doesn't work for derivatives #2070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oesteban opened this issue Feb 27, 2025 · 1 comment
Open

[BUG] Template generation macro doesn't work for derivatives #2070

oesteban opened this issue Feb 27, 2025 · 1 comment

Comments

@oesteban
Copy link
Collaborator

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 #1781 (comment)

@oesteban
Copy link
Collaborator Author

oesteban commented Feb 27, 2025

This problem blocks a list of templates compiled by @effigies from being updated:

```Text
<pipeline_name>/
sub-<label>/
<datatype>/
<source_entities>[_space-<space>][_res-<label>][_den-<label>][_desc-<label>]_<suffix>.<extension>
```

```Text
<pipeline_name>/
sub-<label>/
anat|func|dwi/
<source_entities>[_space-<space>][_res-<label>][_den-<label>][_label-<label>][_desc-<label>]_mask.nii.gz
```

```Text
<pipeline_name>/
sub-<label>/
anat|func|dwi/
<source_entities>[_space-<space>][_seg-<label>][_res-<label>][_den-<label>]_dseg.nii.gz
```

```Text
<pipeline_name>/
sub-<label>/
func|anat|dwi/
<source_entities>[_space-<space>][_seg-<label>][_res-<label>][_den-<label>][_label-<label>]_probseg.nii.gz
```

```Text
<pipeline_name>/
sub-<label>/
anat/
<source_entities>[_hemi-{L|R}][_space-<space>][_seg-<label>][_res-<label>][_den-<label>]_dseg.{label.gii|dlabel.nii}
```

```Text
<pipeline_name>/
sub-<label>/
<datatype>/
<source_entities>[_space-<space>][_desc-<label>]_<suffix>.<extension>
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant