mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add microdocumentation generator
This commit is contained in:
parent
88320bbf7a
commit
b5f4f17103
7 changed files with 120 additions and 31 deletions
|
@ -24,29 +24,5 @@
|
||||||
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
||||||
</formatting-settings>
|
</formatting-settings>
|
||||||
</DBN-SQL>
|
</DBN-SQL>
|
||||||
<DBN-PSQL>
|
|
||||||
<case-options enabled="true">
|
|
||||||
<option name="KEYWORD_CASE" value="lower" />
|
|
||||||
<option name="FUNCTION_CASE" value="lower" />
|
|
||||||
<option name="PARAMETER_CASE" value="lower" />
|
|
||||||
<option name="DATATYPE_CASE" value="lower" />
|
|
||||||
<option name="OBJECT_CASE" value="preserve" />
|
|
||||||
</case-options>
|
|
||||||
<formatting-settings enabled="false" />
|
|
||||||
</DBN-PSQL>
|
|
||||||
<DBN-SQL>
|
|
||||||
<case-options enabled="true">
|
|
||||||
<option name="KEYWORD_CASE" value="lower" />
|
|
||||||
<option name="FUNCTION_CASE" value="lower" />
|
|
||||||
<option name="PARAMETER_CASE" value="lower" />
|
|
||||||
<option name="DATATYPE_CASE" value="lower" />
|
|
||||||
<option name="OBJECT_CASE" value="preserve" />
|
|
||||||
</case-options>
|
|
||||||
<formatting-settings enabled="false">
|
|
||||||
<option name="STATEMENT_SPACING" value="one_line" />
|
|
||||||
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
|
|
||||||
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
|
||||||
</formatting-settings>
|
|
||||||
</DBN-SQL>
|
|
||||||
</code_scheme>
|
</code_scheme>
|
||||||
</component>
|
</component>
|
|
@ -9,7 +9,7 @@
|
||||||
<excludeFolder url="file://$MODULE_DIR$/docs" />
|
<excludeFolder url="file://$MODULE_DIR$/docs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/royalnet.egg-info" />
|
<excludeFolder url="file://$MODULE_DIR$/royalnet.egg-info" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.8 (royalnet-1MWM6-kd-py3.8)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.8 (royalnet-Yo3bJ6Dg-py3.8)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TestRunnerService">
|
<component name="TestRunnerService">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "royalnet"
|
name = "royalnet"
|
||||||
version = "5.1.5"
|
version = "5.1.6"
|
||||||
description = "A multipurpose bot and web framework"
|
description = "A multipurpose bot and web framework"
|
||||||
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||||
license = "AGPL-3.0+"
|
license = "AGPL-3.0+"
|
||||||
|
|
|
@ -17,7 +17,7 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("-c", "--config-filename", default="./config.toml", type=str,
|
@click.option("-c", "--config-filename", default="./config.toml", type=click.Path(exists=True),
|
||||||
help="The filename of the Royalnet configuration file.")
|
help="The filename of the Royalnet configuration file.")
|
||||||
def run(config_filename: str):
|
def run(config_filename: str):
|
||||||
# Read the configuration file
|
# Read the configuration file
|
||||||
|
|
|
@ -2,14 +2,11 @@ import royalnet
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import *
|
from starlette.responses import *
|
||||||
from royalnet.constellation import PageStar
|
from royalnet.constellation import PageStar
|
||||||
from ..tables import available_tables
|
|
||||||
|
|
||||||
|
|
||||||
class ApiRoyalnetVersionStar(PageStar):
|
class ApiRoyalnetVersionStar(PageStar):
|
||||||
path = "/api/royalnet/version"
|
path = "/api/royalnet/version"
|
||||||
|
|
||||||
tables = set(available_tables)
|
|
||||||
|
|
||||||
async def page(self, request: Request) -> JSONResponse:
|
async def page(self, request: Request) -> JSONResponse:
|
||||||
return JSONResponse({
|
return JSONResponse({
|
||||||
"version": {
|
"version": {
|
||||||
|
|
116
royalnet/generate.py
Normal file
116
royalnet/generate.py
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
import toml
|
||||||
|
import importlib
|
||||||
|
import click
|
||||||
|
|
||||||
|
p = click.echo
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option("-c", "--config-filename", default="./config.toml", type=click.Path(exists=True),
|
||||||
|
help="The filename of the Royalnet configuration file.")
|
||||||
|
@click.option("-f", "--file-format", type=str, help="The name of the format that should be generated.")
|
||||||
|
def run(config_filename, file_format):
|
||||||
|
with open(config_filename, "r") as t:
|
||||||
|
config: dict = toml.load(t)
|
||||||
|
|
||||||
|
# Import packs
|
||||||
|
packs_cfg = config["Packs"]
|
||||||
|
pack_names = packs_cfg["active"]
|
||||||
|
packs = {}
|
||||||
|
for pack_name in pack_names:
|
||||||
|
try:
|
||||||
|
packs[pack_name] = importlib.import_module(pack_name)
|
||||||
|
except ImportError as e:
|
||||||
|
p(f"Skipping `{pack_name}`: {e}", err=True)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if file_format == "botfather":
|
||||||
|
for pack_name in packs:
|
||||||
|
pack = packs[pack_name]
|
||||||
|
lines = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
commands = pack.available_commands
|
||||||
|
except AttributeError:
|
||||||
|
p(f"Pack `{pack}` does not have the `available_commands` attribute.", err=True)
|
||||||
|
continue
|
||||||
|
for command in commands:
|
||||||
|
lines.append(f"{command.name} - {command.description}")
|
||||||
|
|
||||||
|
lines.sort()
|
||||||
|
for line in lines:
|
||||||
|
p(line)
|
||||||
|
|
||||||
|
elif file_format == "markdown":
|
||||||
|
for pack_name in packs:
|
||||||
|
pack = packs[pack_name]
|
||||||
|
p(f"# {pack_name}")
|
||||||
|
p("")
|
||||||
|
|
||||||
|
try:
|
||||||
|
commands = pack.available_commands
|
||||||
|
except AttributeError:
|
||||||
|
p(f"Pack `{pack}` does not have the `available_commands` attribute.", err=True)
|
||||||
|
else:
|
||||||
|
p(f"## Commands")
|
||||||
|
p("")
|
||||||
|
for command in commands:
|
||||||
|
p(f"### `{command.name}`")
|
||||||
|
p("")
|
||||||
|
p(f"{command.description}")
|
||||||
|
p("")
|
||||||
|
if len(command.aliases) > 0:
|
||||||
|
p(f"> Aliases: {''.join(['`' + alias + '` ' for alias in command.aliases])}")
|
||||||
|
p("")
|
||||||
|
|
||||||
|
try:
|
||||||
|
events = pack.available_events
|
||||||
|
except AttributeError:
|
||||||
|
p(f"Pack `{pack}` does not have the `available_events` attribute.", err=True)
|
||||||
|
else:
|
||||||
|
p(f"## Events")
|
||||||
|
p("")
|
||||||
|
for event in events:
|
||||||
|
p(f"### `{event.name}`")
|
||||||
|
p("")
|
||||||
|
|
||||||
|
try:
|
||||||
|
page_stars = pack.available_page_stars
|
||||||
|
except AttributeError:
|
||||||
|
p(f"Pack `{pack}` does not have the `available_page_stars` attribute.", err=True)
|
||||||
|
else:
|
||||||
|
p(f"## Page Stars")
|
||||||
|
p("")
|
||||||
|
for page_star in page_stars:
|
||||||
|
p(f"### `{page_star.path}`")
|
||||||
|
p("")
|
||||||
|
|
||||||
|
try:
|
||||||
|
exc_stars = pack.available_exception_stars
|
||||||
|
except AttributeError:
|
||||||
|
p(f"Pack `{pack}` does not have the `available_exception_stars` attribute.", err=True)
|
||||||
|
else:
|
||||||
|
p(f"## Exception Stars")
|
||||||
|
p("")
|
||||||
|
for exc_star in exc_stars:
|
||||||
|
p(f"### `{exc_star.error}`")
|
||||||
|
p("")
|
||||||
|
|
||||||
|
try:
|
||||||
|
tables = pack.available_tables
|
||||||
|
except AttributeError:
|
||||||
|
p(f"Pack `{pack}` does not have the `available_tables` attribute.", err=True)
|
||||||
|
else:
|
||||||
|
p(f"## Tables")
|
||||||
|
p("")
|
||||||
|
for table in tables:
|
||||||
|
p(f"### `{table.__tablename__}`")
|
||||||
|
p("")
|
||||||
|
# TODO: list columns
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise click.ClickException("Unknown format")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
|
@ -1 +1 @@
|
||||||
semantic = "5.1.5"
|
semantic = "5.1.6"
|
||||||
|
|
Loading…
Reference in a new issue