mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-24 07:51:44 +00:00
Improve codegen scripts
This commit is contained in:
parent
cb3addab1e
commit
06ad65e3a0
@ -67,7 +67,7 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool
|
||||
n = len(t) - 1
|
||||
|
||||
t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join(
|
||||
":obj:`{1} <{0}.{1}>`".format(
|
||||
":obj:`~{}.{}`".format(
|
||||
"pyrogram.types" if is_pyrogram_type else "pyrogram.api.types",
|
||||
i.replace("pyrogram.", "")
|
||||
)
|
||||
@ -88,7 +88,7 @@ def get_references(t: str):
|
||||
n = len(t) - 1
|
||||
|
||||
t = ", ".join(
|
||||
":obj:`{0} <pyrogram.api.functions.{0}>`".format(i)
|
||||
":obj:`~pyrogram.api.functions.{}`".format(i)
|
||||
for i in t
|
||||
)
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
import ast
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
HOME = "compiler/docs"
|
||||
@ -29,8 +30,10 @@ TYPES_PATH = "pyrogram/api/types"
|
||||
FUNCTIONS_BASE = "functions"
|
||||
TYPES_BASE = "types"
|
||||
|
||||
shutil.rmtree(TYPES_BASE, ignore_errors=True)
|
||||
shutil.rmtree(FUNCTIONS_BASE, ignore_errors=True)
|
||||
|
||||
def snek(s: str):
|
||||
s = re.sub(r"(.)([A-Z][a-z]+)", r"\1_\2", s)
|
||||
return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", s).lower()
|
||||
|
||||
|
||||
def generate(source_path, base):
|
||||
@ -50,9 +53,11 @@ def generate(source_path, base):
|
||||
for node in ast.walk(p):
|
||||
if isinstance(node, ast.ClassDef):
|
||||
name = node.name
|
||||
break
|
||||
else:
|
||||
continue
|
||||
|
||||
# name = "".join([str(j.title()) for j in os.path.splitext(i)[0].split("_")])
|
||||
full_path = os.path.basename(path) + "/" + name + ".rst"
|
||||
full_path = os.path.basename(path) + "/" + snek(name).replace("_", "-") + ".rst"
|
||||
|
||||
if level:
|
||||
full_path = base + "/" + full_path
|
||||
@ -65,7 +70,7 @@ def generate(source_path, base):
|
||||
title=name,
|
||||
title_markup="=" * len(name),
|
||||
full_class_path="pyrogram.api.{}".format(
|
||||
os.path.splitext(full_path)[0].replace("/", ".")
|
||||
".".join(full_path.split("/")[:-1]) + "." + name
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -82,7 +87,7 @@ def generate(source_path, base):
|
||||
entities = []
|
||||
|
||||
for i in v:
|
||||
entities.append(i)
|
||||
entities.append(snek(i).replace("_", "-"))
|
||||
|
||||
if k != base:
|
||||
inner_path = base + "/" + k + "/index" + ".rst"
|
||||
@ -98,6 +103,7 @@ def generate(source_path, base):
|
||||
with open(DESTINATION + "/" + inner_path, "w", encoding="utf-8") as f:
|
||||
if k == base:
|
||||
f.write(":tocdepth: 1\n\n")
|
||||
k = "Raw " + k
|
||||
|
||||
f.write(
|
||||
toctree.format(
|
||||
@ -115,6 +121,8 @@ def start():
|
||||
global page_template
|
||||
global toctree
|
||||
|
||||
shutil.rmtree(DESTINATION, ignore_errors=True)
|
||||
|
||||
with open(HOME + "/template/page.txt", encoding="utf-8") as f:
|
||||
page_template = f.read()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user