Skip to content

Commit efcf7d5

Browse files
committed
Move single methods, types and bound-methods to separated pages
The resulting pages were huge and were also taking a while to load This will improve docs navigation
1 parent ee2d5b1 commit efcf7d5

9 files changed

Lines changed: 662 additions & 637 deletions

File tree

compiler/docs/compiler.py

Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
HOME = "compiler/docs"
2525
DESTINATION = "docs/source/telegram"
26+
PYROGRAM_API_DEST = "docs/source/api"
2627

2728
FUNCTIONS_PATH = "pyrogram/api/functions"
2829
TYPES_PATH = "pyrogram/api/types"
@@ -117,6 +118,352 @@ def build(path, level=0):
117118
f.write("\n")
118119

119120

121+
def pyrogram_api():
122+
def get_title_list(s: str) -> list:
123+
return [i.strip() for i in [j.strip() for j in s.split("\n") if j] if i]
124+
125+
# Methods
126+
127+
categories = dict(
128+
utilities="""
129+
Utilities
130+
start
131+
stop
132+
restart
133+
idle
134+
run
135+
add_handler
136+
remove_handler
137+
stop_transmission
138+
export_session_string
139+
""",
140+
messages="""
141+
Messages
142+
send_message
143+
forward_messages
144+
send_photo
145+
send_audio
146+
send_document
147+
send_sticker
148+
send_animated_sticker
149+
send_video
150+
send_animation
151+
send_voice
152+
send_video_note
153+
send_media_group
154+
send_location
155+
send_venue
156+
send_contact
157+
send_cached_media
158+
edit_message_text
159+
edit_message_caption
160+
edit_message_media
161+
edit_message_reply_markup
162+
edit_inline_text
163+
edit_inline_caption
164+
edit_inline_media
165+
edit_inline_reply_markup
166+
send_chat_action
167+
delete_messages
168+
get_messages
169+
get_history
170+
get_history_count
171+
read_history
172+
iter_history
173+
send_poll
174+
vote_poll
175+
stop_poll
176+
retract_vote
177+
download_media
178+
""",
179+
chats="""
180+
Chats
181+
join_chat
182+
leave_chat
183+
kick_chat_member
184+
unban_chat_member
185+
restrict_chat_member
186+
promote_chat_member
187+
export_chat_invite_link
188+
set_chat_photo
189+
delete_chat_photo
190+
set_chat_title
191+
set_chat_description
192+
pin_chat_message
193+
unpin_chat_message
194+
get_chat
195+
get_chat_member
196+
get_chat_members
197+
get_chat_members_count
198+
iter_chat_members
199+
get_dialogs
200+
iter_dialogs
201+
get_dialogs_count
202+
restrict_chat
203+
update_chat_username
204+
archive_chats
205+
unarchive_chats
206+
""",
207+
users="""
208+
Users
209+
get_me
210+
get_users
211+
get_profile_photos
212+
get_profile_photos_count
213+
iter_profile_photos
214+
set_profile_photo
215+
delete_profile_photos
216+
update_username
217+
get_user_dc
218+
block_user
219+
unblock_user
220+
""",
221+
contacts="""
222+
Contacts
223+
add_contacts
224+
get_contacts
225+
get_contacts_count
226+
delete_contacts
227+
""",
228+
password="""
229+
Pssword
230+
enable_cloud_password
231+
change_cloud_password
232+
remove_cloud_password
233+
""",
234+
bots="""
235+
Bots
236+
get_inline_bot_results
237+
send_inline_bot_result
238+
answer_callback_query
239+
answer_inline_query
240+
request_callback_answer
241+
send_game
242+
set_game_score
243+
get_game_high_scores
244+
""",
245+
advanced="""
246+
Advanced
247+
send
248+
resolve_peer
249+
save_file
250+
"""
251+
)
252+
253+
root = PYROGRAM_API_DEST + "/methods"
254+
255+
shutil.rmtree(root, ignore_errors=True)
256+
os.mkdir(root)
257+
258+
with open("template/methods.rst") as f:
259+
template = f.read()
260+
261+
with open(root + "/index.rst", "w") as f:
262+
fmt_keys = {}
263+
264+
for k, v in categories.items():
265+
name, *methods = get_title_list(v)
266+
fmt_keys.update({k: "\n ".join("{0} <{0}>".format(m) for m in methods)})
267+
268+
for method in methods:
269+
with open(root + "/{}.rst".format(method), "w") as f2:
270+
title = "{}()".format(method)
271+
272+
f2.write(title + "\n" + "=" * len(title) + "\n\n")
273+
f2.write(".. automethod:: pyrogram.Client.{}()".format(method))
274+
275+
f.write(template.format(**fmt_keys))
276+
277+
# Types
278+
279+
categories = dict(
280+
users_chats="""
281+
Users & Chats
282+
User
283+
UserStatus
284+
Chat
285+
ChatPreview
286+
ChatPhoto
287+
ChatMember
288+
ChatPermissions
289+
Dialog
290+
""",
291+
messages_media="""
292+
Messages & Media
293+
Message
294+
MessageEntity
295+
Photo
296+
Thumbnail
297+
Audio
298+
Document
299+
Animation
300+
Video
301+
Voice
302+
VideoNote
303+
Contact
304+
Location
305+
Venue
306+
Sticker
307+
Game
308+
WebPage
309+
Poll
310+
PollOption
311+
""",
312+
bots_keyboard="""
313+
Bots & Keyboards
314+
ReplyKeyboardMarkup
315+
KeyboardButton
316+
ReplyKeyboardRemove
317+
InlineKeyboardMarkup
318+
InlineKeyboardButton
319+
ForceReply
320+
CallbackQuery
321+
GameHighScore
322+
CallbackGame
323+
""",
324+
input_media="""
325+
Input Media
326+
InputMedia
327+
InputMediaPhoto
328+
InputMediaVideo
329+
InputMediaAudio
330+
InputMediaAnimation
331+
InputMediaDocument
332+
InputPhoneContact
333+
""",
334+
inline_mode="""
335+
Inline Mode
336+
InlineQuery
337+
InlineQueryResult
338+
InlineQueryResultArticle
339+
""",
340+
input_message_content="""
341+
InputMessageContent
342+
InputMessageContent
343+
InputTextMessageContent
344+
"""
345+
)
346+
347+
root = PYROGRAM_API_DEST + "/types"
348+
349+
shutil.rmtree(root, ignore_errors=True)
350+
os.mkdir(root)
351+
352+
with open("template/types.rst") as f:
353+
template = f.read()
354+
355+
with open(root + "/index.rst", "w") as f:
356+
fmt_keys = {}
357+
358+
for k, v in categories.items():
359+
name, *types = get_title_list(v)
360+
361+
fmt_keys.update({k: "\n ".join(types)})
362+
363+
# noinspection PyShadowingBuiltins
364+
for type in types:
365+
with open(root + "/{}.rst".format(type), "w") as f2:
366+
title = "{}".format(type)
367+
368+
f2.write(title + "\n" + "=" * len(title) + "\n\n")
369+
f2.write(".. autoclass:: pyrogram.{}()".format(type))
370+
371+
f.write(template.format(**fmt_keys))
372+
373+
# Bound Methods
374+
375+
categories = dict(
376+
message="""
377+
Message
378+
Message.click
379+
Message.delete
380+
Message.download
381+
Message.forward
382+
Message.pin
383+
Message.edit_text
384+
Message.edit_caption
385+
Message.edit_media
386+
Message.edit_reply_markup
387+
Message.reply_text
388+
Message.reply_animation
389+
Message.reply_audio
390+
Message.reply_cached_media
391+
Message.reply_chat_action
392+
Message.reply_contact
393+
Message.reply_document
394+
Message.reply_game
395+
Message.reply_inline_bot_result
396+
Message.reply_location
397+
Message.reply_media_group
398+
Message.reply_photo
399+
Message.reply_poll
400+
Message.reply_sticker
401+
Message.reply_venue
402+
Message.reply_video
403+
Message.reply_video_note
404+
Message.reply_voice
405+
""",
406+
chat="""
407+
Chat
408+
Chat.archive
409+
Chat.unarchive
410+
Chat.set_title
411+
Chat.set_description
412+
Chat.set_photo
413+
Chat.kick_member
414+
Chat.unban_member
415+
Chat.restrict_member
416+
Chat.promote_member
417+
""",
418+
user="""
419+
User
420+
User.archive
421+
User.unarchive
422+
""",
423+
callback_query="""
424+
Callback Query
425+
CallbackQuery.answer
426+
CallbackQuery.edit_message_text
427+
CallbackQuery.edit_message_caption
428+
CallbackQuery.edit_message_media
429+
CallbackQuery.edit_message_reply_markup
430+
""",
431+
inline_query="""
432+
InlineQuery
433+
InlineQuery.answer
434+
"""
435+
)
436+
437+
root = PYROGRAM_API_DEST + "/bound-methods"
438+
439+
shutil.rmtree(root, ignore_errors=True)
440+
os.mkdir(root)
441+
442+
with open("template/bound-methods.rst") as f:
443+
template = f.read()
444+
445+
with open(root + "/index.rst", "w") as f:
446+
fmt_keys = {}
447+
448+
for k, v in categories.items():
449+
name, *bound_methods = get_title_list(v)
450+
451+
fmt_keys.update({"{}_hlist".format(k): "\n ".join("- :meth:`~{}`".format(bm) for bm in bound_methods)})
452+
453+
fmt_keys.update(
454+
{"{}_toctree".format(k): "\n ".join("{} <{}>".format(bm.split(".")[1], bm) for bm in bound_methods)})
455+
456+
# noinspection PyShadowingBuiltins
457+
for bm in bound_methods:
458+
with open(root + "/{}.rst".format(bm), "w") as f2:
459+
title = "{}()".format(bm)
460+
461+
f2.write(title + "\n" + "=" * len(title) + "\n\n")
462+
f2.write(".. automethod:: pyrogram.{}()".format(bm))
463+
464+
f.write(template.format(**fmt_keys))
465+
466+
120467
def start():
121468
global page_template
122469
global toctree
@@ -131,12 +478,14 @@ def start():
131478

132479
generate(TYPES_PATH, TYPES_BASE)
133480
generate(FUNCTIONS_PATH, FUNCTIONS_BASE)
481+
pyrogram_api()
134482

135483

136484
if "__main__" == __name__:
137485
FUNCTIONS_PATH = "../../pyrogram/api/functions"
138486
TYPES_PATH = "../../pyrogram/api/types"
139487
HOME = "."
140488
DESTINATION = "../../docs/source/telegram"
489+
PYROGRAM_API_DEST = "../../docs/source/api"
141490

142491
start()

0 commit comments

Comments
 (0)