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] Use mkdocs-gen-files to generate the glossary #1041

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ site/
.DS_Store
.idea
venvs
src/99-appendices/14-glossary.md
src/99-appendices/14-glossary.html
.vscode/

pdf_build_src/bids-spec.pdf
Expand Down
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ plugins:
- branch: /(?!^master$)/
+extra_css:
- css/watermark.css
- gen-files:
scripts:
- tools/generate_glossary.py
- macros:
module_name: tools/mkdocs_macros_bids/main
docs_dir: 'src'
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mkdocs>=1.1
mkdocs-material>=5.4
pymdown-extensions>=7.0.0
mkdocs-branchcustomization-plugin~=0.1.3
mkdocs-gen-files
mkdocs-macros-plugin
numpy
tools/schemacode/
11 changes: 0 additions & 11 deletions src/99-appendices/14-glossary.md

This file was deleted.

24 changes: 24 additions & 0 deletions tools/generate_glossary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Generate the Glossary appendix file."""
import os.path as op

import mkdocs_gen_files

from schemacode import render, schema, utils

out_file = op.abspath("src/99-appendices/14-glossary.md")

output = """# Appendix XIV: Glossary of schema objects

This section compiles the object definitions in the schema.

"""

schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
text = render.make_glossary(schema_obj)
output += text

with mkdocs_gen_files.open(out_file, "w") as fobj:
fobj.write(output)

mkdocs_gen_files.set_edit_path(out_file, "tools/generate_glossary.py")
1 change: 0 additions & 1 deletion tools/mkdocs_macros_bids/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def define_env(env):
macros.make_entity_definitions,
"MACROS___make_entity_definitions",
)
env.macro(macros.make_glossary, "MACROS___make_glossary")
env.macro(macros.make_suffix_table, "MACROS___make_suffix_table")
env.macro(macros.make_metadata_table, "MACROS___make_metadata_table")
env.macro(macros.make_subobject_table, "MACROS___make_subobject_table")
Expand Down
9 changes: 6 additions & 3 deletions tools/schemacode/bidsschematools/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ def make_glossary(schema, src_path=None):

text += f'\n<a name="{obj_marker}"></a>'
text += f"\n## {obj_key}\n\n"
text += f"name: {obj_name}\n\n"
text += f"description:\n>{obj_desc}\n\n"
text += f"**Name**: {obj_name}\n\n"
text += f"**Description**:\n\t{obj_desc}\n\n"

temp_obj_def = {k: v for k, v in obj_def.items() if k not in ("description", "name")}
text += f"schema information:\n```yaml\n{temp_obj_def}\n```"
if temp_obj_def:
from pprint import pformat
temp_obj_def_str = pformat(temp_obj_def)
text += f"**Additional schema information**:\n```yaml\n{temp_obj_def_str}\n```"

return text

Expand Down