mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Make use of the new method info when generating docs
This commit is contained in:
parent
f05109f186
commit
8eca29be25
6
setup.py
6
setup.py
|
@ -54,7 +54,6 @@ DOCS_OUT = 'docs'
|
|||
|
||||
|
||||
def generate(which):
|
||||
# TODO make docs generator use the new CSV too
|
||||
from telethon_generator.parsers import\
|
||||
parse_errors, parse_methods, parse_tl, find_layer
|
||||
|
||||
|
@ -64,8 +63,7 @@ def generate(which):
|
|||
layer = find_layer(TLOBJECT_IN_TL)
|
||||
errors = list(parse_errors(ERRORS_IN))
|
||||
methods = list(parse_methods(METHODS_IN, {e.str_code: e for e in errors}))
|
||||
invalid_bot_methods = {m.name for m in methods
|
||||
if not m.usability.startswith('bot')}
|
||||
invalid_bot_methods = {m.name for m in methods if m.usability == 'user'}
|
||||
|
||||
tlobjects = list(itertools.chain(
|
||||
parse_tl(TLOBJECT_IN_CORE_TL, layer, invalid_bot_methods),
|
||||
|
@ -110,7 +108,7 @@ def generate(which):
|
|||
if os.path.isdir(DOCS_OUT):
|
||||
shutil.rmtree(DOCS_OUT)
|
||||
else:
|
||||
generate_docs(tlobjects, errors, layer, DOCS_IN_RES, DOCS_OUT)
|
||||
generate_docs(tlobjects, methods, layer, DOCS_IN_RES, DOCS_OUT)
|
||||
|
||||
if 'json' in which:
|
||||
which.remove('json')
|
||||
|
|
|
@ -231,7 +231,7 @@ def _copy_replace(src, dst, replacements):
|
|||
))
|
||||
|
||||
|
||||
def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
||||
def _write_html_pages(tlobjects, methods, layer, input_res, output_dir):
|
||||
"""
|
||||
Generates the documentation HTML files from from ``scheme.tl``
|
||||
to ``/methods`` and ``/constructors``, etc.
|
||||
|
@ -263,15 +263,7 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||
for t, cs in type_to_constructors.items():
|
||||
type_to_constructors[t] = list(sorted(cs, key=lambda c: c.name))
|
||||
|
||||
# Telegram may send errors with the same str_code but different int_code.
|
||||
# They are all imported on telethon.errors anyway so makes no difference.
|
||||
errors = list(sorted({e.str_code: e for e in errors}.values(),
|
||||
key=lambda e: e.name))
|
||||
|
||||
method_causes_errors = defaultdict(list)
|
||||
for error in errors:
|
||||
for method in error.caused_by:
|
||||
method_causes_errors[method].append(error)
|
||||
methods = {m.name: m for m in methods}
|
||||
|
||||
# Since the output directory is needed everywhere partially apply it now
|
||||
create_path_for = functools.partial(_get_create_path_for, output_dir)
|
||||
|
@ -394,7 +386,8 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
|||
|
||||
if tlobject.is_function:
|
||||
docs.write_title('Known RPC errors')
|
||||
errors = method_causes_errors[tlobject.fullname]
|
||||
method_info = methods.get(tlobject.fullname)
|
||||
errors = method_info and method_info.errors
|
||||
if not errors:
|
||||
docs.write_text("This request can't cause any RPC error "
|
||||
"as far as we know.")
|
||||
|
@ -650,7 +643,7 @@ def _copy_resources(res_dir, out_dir):
|
|||
shutil.copy(os.path.join(res_dir, dirname, file), dirpath)
|
||||
|
||||
|
||||
def generate_docs(tlobjects, errors, layer, input_res, output_dir):
|
||||
def generate_docs(tlobjects, methods, layer, input_res, output_dir):
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
_write_html_pages(tlobjects, errors, layer, input_res, output_dir)
|
||||
_write_html_pages(tlobjects, methods, layer, input_res, output_dir)
|
||||
_copy_resources(input_res, output_dir)
|
||||
|
|
Loading…
Reference in New Issue
Block a user