plugin done
This commit is contained in:
parent
d6840b05e0
commit
5777aa57d9
3 changed files with 69 additions and 20 deletions
62
tools/docgen/plugins.py
Normal file
62
tools/docgen/plugins.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import inspect
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
|
from tools.docgen.utils import section
|
||||||
|
from ytdl_sub.config.overrides import Overrides
|
||||||
|
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
|
||||||
|
from ytdl_sub.config.preset_options import OutputOptions
|
||||||
|
from ytdl_sub.config.preset_options import YTDLOptions
|
||||||
|
from ytdl_sub.config.validators.options import OptionsValidator
|
||||||
|
|
||||||
|
|
||||||
|
def should_filter_property(property_name: str) -> bool:
|
||||||
|
return property_name.startswith("_") or property_name in (
|
||||||
|
"value",
|
||||||
|
"source_variable_capture_dict",
|
||||||
|
"dict",
|
||||||
|
"keys",
|
||||||
|
"dict_with_format_strings",
|
||||||
|
"subscription_name",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_plugin_docs(name: str, options: Type[OptionsValidator], offset: int):
|
||||||
|
docs = ""
|
||||||
|
docs += section(name, level=offset + 0)
|
||||||
|
|
||||||
|
docs += inspect.cleandoc(options.__doc__)
|
||||||
|
docs += "\n"
|
||||||
|
|
||||||
|
property_names = [
|
||||||
|
prop
|
||||||
|
for prop in dir(options)
|
||||||
|
if isinstance(getattr(options, prop), property) and not should_filter_property(prop)
|
||||||
|
]
|
||||||
|
for property_name in sorted(property_names):
|
||||||
|
docs += section(property_name, level=offset + 1)
|
||||||
|
docs += inspect.cleandoc(getattr(options, property_name).__doc__)
|
||||||
|
docs += "\n"
|
||||||
|
|
||||||
|
return docs
|
||||||
|
|
||||||
|
|
||||||
|
def generate_plugin_rst():
|
||||||
|
options_dict: Dict[str, Type[OptionsValidator]] = {
|
||||||
|
"output_options": OutputOptions,
|
||||||
|
"ytdl_options": YTDLOptions,
|
||||||
|
"overrides": Overrides,
|
||||||
|
}
|
||||||
|
for plugin_name, plugin_type in PluginMapping._MAPPING.items():
|
||||||
|
if plugin_name.startswith("_"):
|
||||||
|
continue
|
||||||
|
options_dict[plugin_name] = plugin_type.plugin_options_type
|
||||||
|
|
||||||
|
docs = section("Plugins", level=0)
|
||||||
|
for name in sorted(options_dict.keys()):
|
||||||
|
docs += generate_plugin_docs(name, options_dict[name], offset=1)
|
||||||
|
|
||||||
|
return docs
|
||||||
|
|
||||||
|
|
||||||
|
print(generate_plugin_rst())
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
import inspect
|
|
||||||
|
|
||||||
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
|
|
||||||
from ytdl_sub.config.validators.options import OptionsValidator
|
|
||||||
|
|
||||||
|
|
||||||
def generate_docs(name: str, plugin_options: OptionsValidator):
|
|
||||||
|
|
||||||
docs = ""
|
|
||||||
docs += f"{name}\n{len(name) * '-'}\n"
|
|
||||||
|
|
||||||
docs += inspect.cleandoc(plugin_options.__doc__)
|
|
||||||
|
|
||||||
print(docs)
|
|
||||||
|
|
||||||
|
|
||||||
generate_docs(
|
|
||||||
"output_directory_nfo_tags",
|
|
||||||
PluginMapping._MAPPING["output_directory_nfo_tags"].plugin_options_type,
|
|
||||||
)
|
|
||||||
7
tools/docgen/utils.py
Normal file
7
tools/docgen/utils.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
LEVEL_CHARS: Dict[int, str] = {0: "=", 1: "-", 2: "~", 3: "^"}
|
||||||
|
|
||||||
|
|
||||||
|
def section(name: str, level: int) -> str:
|
||||||
|
return f"\n{name}\n{len(name) * LEVEL_CHARS[level]}\n"
|
||||||
Loading…
Reference in a new issue