Add YAML config to the module docs

pull/190/head
Patrick Robertson 2025-02-11 19:42:03 +00:00
rodzic 22fa9ba456
commit 1ee7981c6e
3 zmienionych plików z 25 dodań i 9 usunięć

Wyświetl plik

@ -2,6 +2,8 @@
from pathlib import Path from pathlib import Path
from auto_archiver.core.module import available_modules from auto_archiver.core.module import available_modules
from auto_archiver.core.base_module import BaseModule 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" MODULES_FOLDER = Path(__file__).parent.parent.parent.parent / "src" / "auto_archiver" / "modules"
SAVE_FOLDER = Path(__file__).parent.parent / "source" / "modules" / "autogen" SAVE_FOLDER = Path(__file__).parent.parent / "source" / "modules" / "autogen"
@ -18,6 +20,7 @@ type_color = {
TABLE_HEADER = ("Option", "Description", "Default", "Type") TABLE_HEADER = ("Option", "Description", "Default", "Type")
def generate_module_docs(): def generate_module_docs():
yaml = YAML()
SAVE_FOLDER.mkdir(exist_ok=True) SAVE_FOLDER.mkdir(exist_ok=True)
modules_by_type = {} modules_by_type = {}
@ -41,22 +44,34 @@ def generate_module_docs():
{types} {types}
``` ```
{description} {description}
""" """
if manifest['configs']: if not manifest['configs']:
readme_str += "\n## Configuration Options\n" readme_str += "\n*This module has no configuration options.*\n"
readme_str += header_row else:
config_yaml = {}
config_table = header_row
for key, value in manifest['configs'].items(): for key, value in manifest['configs'].items():
type = value.get('type', 'string') type = value.get('type', 'string')
if type == 'auto_archiver.utils.json_loader': if type == 'auto_archiver.utils.json_loader':
value['type'] = 'json' value['type'] = 'json'
elif type == 'str': elif type == 'str':
type = "string" type = "string"
default = value.get('default', '')
config_yaml[key] = default
help = "**Required**. " if value.get('required', False) else "Optional. " help = "**Required**. " if value.get('required', False) else "Optional. "
help += value.get('help', '') help += value.get('help', '')
readme_str += 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} | {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 # add a link to the autodoc refs
readme_str += f"\n[API Reference](../../../autoapi/{module.name}/index)\n" readme_str += f"\n[API Reference](../../../autoapi/{module.name}/index)\n"

Wyświetl plik

@ -25,6 +25,7 @@ extensions = [
"autoapi.extension", # Generate API documentation from docstrings "autoapi.extension", # Generate API documentation from docstrings
"sphinxcontrib.mermaid", # Mermaid diagrams "sphinxcontrib.mermaid", # Mermaid diagrams
"sphinx.ext.viewcode", # Source code links "sphinx.ext.viewcode", # Source code links
"sphinx_copybutton",
"sphinx.ext.napoleon", # Google-style and NumPy-style docstrings "sphinx.ext.napoleon", # Google-style and NumPy-style docstrings
"sphinx.ext.autosectionlabel", "sphinx.ext.autosectionlabel",
# 'sphinx.ext.autosummary', # Summarize module/class/function docs # 'sphinx.ext.autosummary', # Summarize module/class/function docs

Wyświetl plik

@ -1,5 +1,5 @@
{ {
"name": "telethon_extractor", "name": "Telethon Extractor",
"type": ["extractor"], "type": ["extractor"],
"requires_setup": True, "requires_setup": True,
"dependencies": { "dependencies": {