diff --git a/Makefile b/Makefile index e0e439e1..6186c33c 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TAG = v$(shell grep -E '__version__ = ".*"' pyrogram/__init__.py | cut -d\" -f2) RM := rm -rf -.PHONY: venv clean-build clean-api clean api build +.PHONY: venv clean-build clean-api clean-docs clean api docs build venv: $(RM) $(VENV) @@ -21,7 +21,7 @@ clean-api: $(RM) pyrogram/errors/exceptions pyrogram/raw/all.py pyrogram/raw/base pyrogram/raw/functions pyrogram/raw/types clean-docs: - $(RM) docs/build docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/telegram + $(RM) docs/build docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/api/enums docs/source/telegram clean: make clean-build diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 4ed7e3c0..a14e0d7d 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -824,6 +824,78 @@ def pyrogram_api(): f.write(template.format(**fmt_keys)) + # Enumerations + + categories = dict( + enums=""" + Enumerations + BusinessSchedule + ChatAction + ChatEventAction + ChatMemberStatus + ChatMembersFilter + ChatType + ClientPlatform + FolderColor + MessageEntityType + MessageServiceType + MessagesFilter + NextCodeType + ParseMode + PollType + PrivacyKey + ProfileColor + ReplyColor + SentCodeType + StoriesPrivacyRules + UserStatus + """, + ) + + root = PYROGRAM_API_DEST + "/enums" + + shutil.rmtree(root, ignore_errors=True) + os.mkdir(root) + + with open(HOME + "/template/enums.rst") as f: + template = f.read() + + with open(root + "/cleanup.html", "w") as f: + f.write("""""") + + with open(root + "/index.rst", "w") as f: + fmt_keys = {} + + for k, v in categories.items(): + name, *enums = get_title_list(v) + + fmt_keys.update({"{}_hlist".format(k): "\n ".join("{}".format(enum) for enum in enums)}) + + fmt_keys.update( + {"{}_toctree".format(k): "\n ".join("{}".format(enum) for enum in enums)}) + + # noinspection PyShadowingBuiltins + for enum in enums: + with open(root + "/{}.rst".format(enum), "w") as f2: + title = "{}".format(enum) + + f2.write(title + "\n" + "=" * len(title) + "\n\n") + f2.write(".. autoclass:: pyrogram.enums.{}()".format(enum)) + f2.write("\n :members:\n") + + f2.write("\n.. raw:: html\n :file: ./cleanup.html\n") + + f.write(template.format(**fmt_keys)) + + def start(): global page_template global toctree diff --git a/compiler/docs/template/enums.rst b/compiler/docs/template/enums.rst new file mode 100644 index 00000000..c7b61921 --- /dev/null +++ b/compiler/docs/template/enums.rst @@ -0,0 +1,21 @@ +Enumerations +============ + +This page is about Pyrogram enumerations. +Enumerations are types that hold a group of related values to be used whenever a constant value is required. +They will help you deal with those values in a type-safe way and also enable code completion so that you can be sure +to apply only a valid value among the expected ones. + +----- + +.. currentmodule:: pyrogram.enums + +.. autosummary:: + :nosignatures: + + {enums_hlist} + +.. toctree:: + :hidden: + + {enums_toctree}