Skip to content
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

[SCHEMA] Render schema elements in text #610

Merged
merged 55 commits into from
Feb 2, 2021

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Sep 16, 2020

References #544 and closes #591. Uses the mkdocs-macros plugin to generate certain markdown elements (e.g., the filename patterns) from the schema. This should easily extend to tables and json examples, as well.

Changes proposed:

  • Replace manual Entity Table and Entity description file creation scripts with functions that are called by the mkdocs-macros plugin within the markdown files.
  • Move all auxdatatypes into new groups under the associated data types. This is primarily because I had so much trouble getting a generic filtering function working with the original structure.
  • Add standard Python stuff to the gitignore.
  • Reorganize Python code into a mini package.
  • Add several Python libraries and macros as dependencies.
  • Replace entities in datatypes files with the actual names instead of their shorthand versions.
  • Split the iEEG/EEG/MEG entity table into a Biopotential Amplification (iEEG/EEG) table and an MEG table.

TODO:

  • Reorganize Python code. Even though the macros documentation says that the define_env function can be in a module, I can't seem to get that working, so it's in its own file at the top level for now.
  • Generic filtering function. We need to be able to filter the schema down to specific classes or elements within classes.
    • Something on the order of pybids is probably overkill, but I imagine the pybids devs would have some insights on this.
    • I added something in 9ce6d7f that is fairly flexible. We should improve it at some point though.
  • Updated entity tables. Currently, because of the lack of a filtering function, only the full entity table is generated.
  • Combine .nii and .nii.gz as .nii[.gz] in file formats.
  • Consider dropping .json from the list of extensions in the schema. JSON files are not alternatives to the other extensions. They are required (at some level).
    • I've decided to ignore this nuance for now. Will just treat json like any other extension and show it in the format snippets.
  • Deal with remark. TravisCI is failing because remark flags the code snippets like {{ make_filename_template(datatypes=["anat"]) }} as bad.
  • Update contributing information. Fewer steps are needed when updating the schema now, since rendering happens automatically.
  • Fix PDF rendering. Currently, it just shows the inline code without the text produced by the code.
  • Remove old outputs (currently retained for comparison).

More To Dos (added by @sappelhoff here for better visibility, but can be done by anybody)

@tsalo
Copy link
Member Author

tsalo commented Sep 17, 2020

@yarikoptic check this out! Here is an example filename format example snippet. The first one is autogenerated from the specification, while the second one is the preexisting one. It's far from perfect, but I think it's pretty promising!

@tsalo tsalo changed the title [INFRA] Render filename patterns in specification [INFRA] Render specification elements in text Sep 17, 2020
@tsalo tsalo changed the title [INFRA] Render specification elements in text [INFRA] Render schema elements in text Sep 18, 2020
@tsalo tsalo mentioned this pull request Sep 28, 2020
@tsalo tsalo marked this pull request as ready for review October 2, 2020 18:29
@tsalo
Copy link
Member Author

tsalo commented Oct 2, 2020

I'm marking this ready for review, with a couple of caveats:

  1. I still need to update the remark settings so that it will play nicely with macros.
  2. Some of the filename format snippets for data types with many suffixes look.... not the best. Unfortunately, cleanly combining them without also combining out the json files will require either (1) hacky hardcoding or (2) conditional logic implemented in the schema (see Mutual exclusion and conditional relationships in the schema #620).
  3. What are MEG _markers files? They're in the schema but I don't know where they came from.
  4. I've kept the original versions of the rendered elements in the specification for now to make comparison easier.

@tsalo tsalo requested a review from yarikoptic October 2, 2020 18:33
@sappelhoff
Copy link
Member

What are MEG _markers files? They're in the schema but I don't know where they came from.

😲 did you find a spot in the spec that yields more information?

I just found this in https://bids-specification.readthedocs.io/en/latest/99-appendices/06-meg-file-formats.html#kityokogawaricoh

Seems like a badly defined suffix ... reminiscent of the part -> split situation we had a while ago, where an MEG suffix was only defined in an appendix.

@tsalo
Copy link
Member Author

tsalo commented Oct 2, 2020

It looks like _markers has been in the appendix for a couple of years (first mention I could find is #28), but I can't find uses outside of the appendix. I'm not sure where to go from here, except maybe to open a separate issue and tag some MEG folks?

@sappelhoff
Copy link
Member

I'm not sure where to go from here, except maybe to open a separate issue and tag some MEG folks?

yes please 👍

.remarkrc Outdated Show resolved Hide resolved
@tsalo tsalo added this to the 1.5.0 milestone Jan 21, 2021
Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from one comment, LGTM

tsalo and others added 2 commits January 27, 2021 11:43
Co-authored-by: Stefan Appelhoff <stefan.appelhoff@mailbox.org>
@sappelhoff
Copy link
Member

sappelhoff commented Jan 29, 2021

@effigies @emdupre @Remi-Gau @yarikoptic we would like to merge this PR but would feel more comfortable with at least one more review.

EDIT: To clarify: Perhaps the most valuable review would be to open the build artifact (pdf or HTML), and compare the new computer rendered template with the old, hand-written template. Currently both are left in this PR for comparison --> the upper one is the new one, the lower one the old one.

So you can basically go through the artifact, searching for "template" and then do a check if the entities, suffixes, etc. match and sound about right.

example:

image

Copy link
Collaborator

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have skimmed through it, saw some of my requested (forgot the medium we communicated through with @tsalo awhile back) changes reflected . This review includes some of my comments (e.g. eventually should be RFed so there is no sys.path) which I never submitted (will not remove them) but they can be ignored.
This is a HUGE work and progress, thank you @tsalo for leading it, and everyone who contributed. Let's get it merged and work on top of that ;)

CONTRIBUTING.md Outdated
```bash
python tools/bids_schema.py entity src/schema/ src/99-appendices/04-entity-table.md
```
As such, you need to ensure that the functions used throughout the specific to render these elements are appropriately referencing the schema; in essence, that, if your changes do impact how functions should be called, the function calls have been updated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reads odd, needs tune up and probably split into two sentences

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do


Run `mkdocs serve` and open `localhost:8000` to browse the rendered specification.
Make sure that all filename format templates, entity tables, and entity definitions are correct
and that the code that generates these elements is not broken by your changes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, pr would do that right?

For comparing pdf changes, pdfdiff could be handy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the CI will render the files, but the CI won't fail if the code fails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, how come is that? because it is too deep (invoked through remake etc) and something just swallows its failures? Ideally we should fail if anything fails in the code... if not possible "legitimately", could be done by wrapping __main__ invocation in try/except and then creating some sentinel file and then checking after invocation of the outside tool that there is no such file.

just a comment/idea: should not stop this PR from being merged!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a problem with the mkdocs-macros plugin.

main.py Outdated
specification and are run/rendered with the mkdocs plugin "macros".
"""
import sys
sys.path.append("tools/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do this, should take for of __file__ and construct full path so it wouldn't rely on being invoked from the specific directory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it isn't even a script - not yet sure but better ways could emerge through review

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, make it tools/Init. Py

from datetime import datetime

import numpy as np

sys.path.append("../tools/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like adding __init__.py broke things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsalo I suggest to revert for now. We can smooth and streamline later on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@yarikoptic
Copy link
Collaborator

Note that before merge the "Remove old outputs (currently retained for comparison)." should still be done (in entities table).

import os
import sys

schemacode_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @yarikoptic, but this is the current version of what you commented on in #610 (comment). Should I add __init__.py to this line?

Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in maintainers meeting: let's remove the "old template texts" and then merge

@tsalo tsalo merged commit 644ebd1 into bids-standard:master Feb 2, 2021
@tsalo tsalo added schema-code Updates or changes to the code used to parse, filter, and render the schema. schema-structure Changes to the fundamental organization/structure of the YAML schema. Minor version release. labels Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
schema Issues related to the YAML schema representation of the specification. Patch version release. schema-code Updates or changes to the code used to parse, filter, and render the schema. schema-structure Changes to the fundamental organization/structure of the YAML schema. Minor version release.
Projects
Development

Successfully merging this pull request may close these issues.

Standardize structure of entity tables
5 participants