From 1ee7981c6e9243f2fc593588e1d0a1b33eab4d00 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Tue, 11 Feb 2025 19:42:03 +0000 Subject: [PATCH] Add YAML config to the module docs --- docs/scripts/scripts.py | 31 ++++++++++++++----- docs/source/conf.py | 1 + .../telethon_extractor/__manifest__.py | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/scripts/scripts.py b/docs/scripts/scripts.py index 7439611..f2bf709 100644 --- a/docs/scripts/scripts.py +++ b/docs/scripts/scripts.py @@ -2,6 +2,8 @@ from pathlib import Path from auto_archiver.core.module import available_modules from auto_archiver.core.base_module import BaseModule +from ruamel.yaml import YAML +import io MODULES_FOLDER = Path(__file__).parent.parent.parent.parent / "src" / "auto_archiver" / "modules" SAVE_FOLDER = Path(__file__).parent.parent / "source" / "modules" / "autogen" @@ -18,6 +20,7 @@ type_color = { TABLE_HEADER = ("Option", "Description", "Default", "Type") def generate_module_docs(): + yaml = YAML() SAVE_FOLDER.mkdir(exist_ok=True) modules_by_type = {} @@ -41,22 +44,34 @@ def generate_module_docs(): {types} ``` {description} -""" - if manifest['configs']: - readme_str += "\n## Configuration Options\n" - readme_str += header_row +""" + if not manifest['configs']: + readme_str += "\n*This module has no configuration options.*\n" + else: + config_yaml = {} + config_table = header_row for key, value in manifest['configs'].items(): type = value.get('type', 'string') if type == 'auto_archiver.utils.json_loader': value['type'] = 'json' elif type == 'str': type = "string" - + + default = value.get('default', '') + config_yaml[key] = default help = "**Required**. " if value.get('required', False) else "Optional. " help += value.get('help', '') - readme_str += f"| `{module.name}.{key}` | {help} | {value.get('default', '')} | {type} |\n" - configs_cheatsheet += f"| `{module.name}.{key}` | {help} | {value.get('default', '')} | {type} |\n" - + config_table += f"| `{module.name}.{key}` | {help} | {value.get('default', '')} | {type} |\n" + configs_cheatsheet += f"| `{module.name}.{key}` | {help} | {default} | {type} |\n" + readme_str += "\n## Configuration Options\n" + readme_str += "\n### YAML\n" + yaml_string = io.BytesIO() + yaml.dump({module.name: config_yaml}, yaml_string) + + readme_str += f"```{{code}} yaml\n{yaml_string.getvalue().decode('utf-8')}\n```\n" + + readme_str += "\n### Command Line:\n" + readme_str += config_table # add a link to the autodoc refs readme_str += f"\n[API Reference](../../../autoapi/{module.name}/index)\n" diff --git a/docs/source/conf.py b/docs/source/conf.py index 9ce7e13..d5bd71b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -25,6 +25,7 @@ extensions = [ "autoapi.extension", # Generate API documentation from docstrings "sphinxcontrib.mermaid", # Mermaid diagrams "sphinx.ext.viewcode", # Source code links + "sphinx_copybutton", "sphinx.ext.napoleon", # Google-style and NumPy-style docstrings "sphinx.ext.autosectionlabel", # 'sphinx.ext.autosummary', # Summarize module/class/function docs diff --git a/src/auto_archiver/modules/telethon_extractor/__manifest__.py b/src/auto_archiver/modules/telethon_extractor/__manifest__.py index 6b37654..1de9035 100644 --- a/src/auto_archiver/modules/telethon_extractor/__manifest__.py +++ b/src/auto_archiver/modules/telethon_extractor/__manifest__.py @@ -1,5 +1,5 @@ { - "name": "telethon_extractor", + "name": "Telethon Extractor", "type": ["extractor"], "requires_setup": True, "dependencies": {