From 6c7afbb859a9b3557268802ac2fcea2450260b5c Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 16 Feb 2022 10:53:35 +1100 Subject: [PATCH] Migrate XAP docs generator into CLI now that most logic is in Jinja2 files. --- lib/python/qmk/cli/xap/generate_docs.py | 32 ++++++++++++++++++-- lib/python/qmk/xap/gen_docs/__init__.py | 0 lib/python/qmk/xap/gen_docs/generator.py | 37 ------------------------ 3 files changed, 30 insertions(+), 39 deletions(-) delete mode 100644 lib/python/qmk/xap/gen_docs/__init__.py delete mode 100755 lib/python/qmk/xap/gen_docs/generator.py diff --git a/lib/python/qmk/cli/xap/generate_docs.py b/lib/python/qmk/cli/xap/generate_docs.py index bf2fdb86bbb..d77a418bf7e 100755 --- a/lib/python/qmk/cli/xap/generate_docs.py +++ b/lib/python/qmk/cli/xap/generate_docs.py @@ -1,11 +1,39 @@ """This script generates the XAP protocol documentation. """ +import hjson +from qmk.constants import QMK_FIRMWARE +from qmk.xap.common import get_xap_definition_files, update_xap_definitions, render_xap_output from milc import cli -from qmk.xap.gen_docs.generator import generate_docs @cli.subcommand('Generates the XAP protocol documentation.', hidden=False if cli.config.user.developer else True) def xap_generate_docs(cli): """Generates the XAP protocol documentation by merging the definitions files, and producing the corresponding Markdown document under `/docs/`. """ - generate_docs() \ No newline at end of file + docs_list = [] + + overall = None + for file in get_xap_definition_files(): + overall = update_xap_definitions(overall, hjson.load(file.open(encoding='utf-8'))) + + # Inject dummy bits for unspecified response flags + for n in range(0, 8): + if str(n) not in overall['response_flags']['bits']: + overall['response_flags']['bits'][str(n)] = {'name': '', 'description': '', 'define': '-'} + + output_doc = QMK_FIRMWARE / "docs" / f"{file.stem}.md" + docs_list.append(output_doc) + output = render_xap_output('docs', 'docs.md.j2', overall) + with open(output_doc, "w", encoding='utf-8') as out_file: + out_file.write(output) + + output_doc = QMK_FIRMWARE / "docs" / f"xap_protocol.md" + with open(output_doc, "w", encoding='utf-8') as out_file: + out_file.write('''\ +# XAP Protocol Reference + +''') + + for file in reversed(sorted(docs_list)): + ver = file.stem[4:] + out_file.write(f'* [XAP Version {ver}]({file.name})\n') diff --git a/lib/python/qmk/xap/gen_docs/__init__.py b/lib/python/qmk/xap/gen_docs/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/lib/python/qmk/xap/gen_docs/generator.py b/lib/python/qmk/xap/gen_docs/generator.py deleted file mode 100755 index bcb90351e99..00000000000 --- a/lib/python/qmk/xap/gen_docs/generator.py +++ /dev/null @@ -1,37 +0,0 @@ -"""This script generates the XAP protocol documentation. -""" -import hjson -from qmk.constants import QMK_FIRMWARE -from qmk.xap.common import get_xap_definition_files, update_xap_definitions, render_xap_output - - -def generate_docs(): - """Generates the XAP protocol documentation by merging the definitions files, and producing the corresponding Markdown document under `/docs/`. - """ - docs_list = [] - - overall = None - for file in get_xap_definition_files(): - overall = update_xap_definitions(overall, hjson.load(file.open(encoding='utf-8'))) - - # Inject dummy bits for unspecified response flags - for n in range(0, 8): - if str(n) not in overall['response_flags']['bits']: - overall['response_flags']['bits'][str(n)] = {'name': '', 'description': '', 'define': '-'} - - output_doc = QMK_FIRMWARE / "docs" / f"{file.stem}.md" - docs_list.append(output_doc) - output = render_xap_output('docs', 'docs.md.j2', overall) - with open(output_doc, "w", encoding='utf-8') as out_file: - out_file.write(output) - - output_doc = QMK_FIRMWARE / "docs" / f"xap_protocol.md" - with open(output_doc, "w", encoding='utf-8') as out_file: - out_file.write('''\ -# XAP Protocol Reference - -''') - - for file in reversed(sorted(docs_list)): - ver = file.stem[4:] - out_file.write(f'* [XAP Version {ver}]({file.name})\n')