Skip to content

Docs link python classes to docs #2633 #2738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ed0bb9e
Temporarily enable tests for the v14 branch
Bibo-Joshi Jul 14, 2021
f58368a
Wikipedia != wiki
Bibo-Joshi Jul 21, 2021
6680445
document that inputfile has 'mimetype' attribute.
harshil21 Aug 1, 2021
993c86a
fix spelling -> it's longitude.
harshil21 Aug 1, 2021
9b1080f
Fix: Updated docs
Poolitzer Aug 8, 2021
c3774c6
Temporarily enable tests for the v14 branch
Bibo-Joshi Jul 14, 2021
d9b48cc
Move and Rename TelegramDecryptionError to telegram.error.PassportDec…
harshil21 Aug 11, 2021
b37f9d2
Add Code Comment Guidelines to Contribution Guide (#2612)
Poolitzer Aug 11, 2021
d696412
Improve Type Hinting for CallbackContext (#2587)
revolter Aug 12, 2021
2ed8869
Add Custom pytest Marker to Ease Development (#2628)
Poolitzer Aug 12, 2021
be00397
Make BasePersistence Methods Abstract (#2624)
starry-shivam Aug 12, 2021
f284061
Refactor Initialization of Persistence Classes (#2604)
Bibo-Joshi Aug 13, 2021
5fe3baf
Merge branch 'v14' into doc-fixes
Bibo-Joshi Aug 13, 2021
5b18805
Fix Wrong Extra Requirement for ujson in Readme (#2629)
Behoston Aug 13, 2021
b65c1c3
Remove `__dict__` from `__slots__` and drop Python 3.6 (#2619, #2636)
harshil21 Aug 19, 2021
209642b
Remove day_is_strict argument of JobQueue.run_monthly (#2634)
iota-008 Aug 26, 2021
28a6c25
Remove already remove argument `bot` for JobQueue
Bibo-Joshi Aug 29, 2021
fd47e5c
remove doc about deprecated JobQueue's bot in set_dispatcher
harshil21 Aug 31, 2021
5240655
Drop Non-CallbackContext API (#2617)
Poolitzer Aug 29, 2021
76e4875
Fix Signatures and Improve test_official (#2643)
harshil21 Aug 29, 2021
930a615
Remove Deprecated Functionality (#2644)
Bibo-Joshi Aug 30, 2021
c8debee
Merge branch 'v14' into doc-fixes
Bibo-Joshi Sep 4, 2021
63e1bab
Temporarily enable tests for the v14 branch
Bibo-Joshi Jul 14, 2021
4598eea
Move and Rename TelegramDecryptionError to telegram.error.PassportDec…
harshil21 Aug 11, 2021
d7366fc
Add Code Comment Guidelines to Contribution Guide (#2612)
Poolitzer Aug 11, 2021
5b3983d
Improve Type Hinting for CallbackContext (#2587)
revolter Aug 12, 2021
df2e48f
Add Custom pytest Marker to Ease Development (#2628)
Poolitzer Aug 12, 2021
e72ca06
Make BasePersistence Methods Abstract (#2624)
starry-shivam Aug 12, 2021
60f6c38
Refactor Initialization of Persistence Classes (#2604)
Bibo-Joshi Aug 13, 2021
fe60272
Remove `__dict__` from `__slots__` and drop Python 3.6 (#2619, #2636)
harshil21 Aug 19, 2021
df81477
Remove day_is_strict argument of JobQueue.run_monthly (#2634)
iota-008 Aug 26, 2021
f857f06
Drop Non-CallbackContext API (#2617)
Poolitzer Aug 29, 2021
a717db8
Fix Signatures and Improve test_official (#2643)
harshil21 Aug 29, 2021
12fe042
Remove Deprecated Functionality (#2644)
Bibo-Joshi Aug 30, 2021
11e4d54
Merge branch 'v14' into doc-fixes
Bibo-Joshi Sep 9, 2021
331c4f5
Temporarily enable tests for the v14 branch
Bibo-Joshi Jul 14, 2021
9dc30cf
Move and Rename TelegramDecryptionError to telegram.error.PassportDec…
harshil21 Aug 11, 2021
b089cc9
Add Code Comment Guidelines to Contribution Guide (#2612)
Poolitzer Aug 11, 2021
3a19383
Improve Type Hinting for CallbackContext (#2587)
revolter Aug 12, 2021
414a18c
Add Custom pytest Marker to Ease Development (#2628)
Poolitzer Aug 12, 2021
8edb49d
Make BasePersistence Methods Abstract (#2624)
starry-shivam Aug 12, 2021
cce9c18
Refactor Initialization of Persistence Classes (#2604)
Bibo-Joshi Aug 13, 2021
dc0207a
Remove `__dict__` from `__slots__` and drop Python 3.6 (#2619, #2636)
harshil21 Aug 19, 2021
4af252f
Remove day_is_strict argument of JobQueue.run_monthly (#2634)
iota-008 Aug 26, 2021
b6e4b54
Drop Non-CallbackContext API (#2617)
Poolitzer Aug 29, 2021
4359812
Fix Signatures and Improve test_official (#2643)
harshil21 Aug 29, 2021
dbdd35e
Remove Deprecated Functionality (#2644)
Bibo-Joshi Aug 30, 2021
a7c7c82
Add User Friendly Type Check For Init Of {Inline, Reply}KeyboardMarku…
harshil21 Sep 15, 2021
767fbb9
Merge branch 'v14' into doc-fixes
Bibo-Joshi Sep 15, 2021
8ac65fc
Refine Dispatcher.dispatch_error (#2660)
Bibo-Joshi Sep 17, 2021
66f0604
Warnings Overhaul (#2662)
harshil21 Sep 20, 2021
4f21c06
Clear Up Import Policy (#2671)
Bibo-Joshi Sep 22, 2021
5542a46
Make InlineQuery.answer Raise ValueError (#2675)
Bibo-Joshi Sep 24, 2021
2cf9311
Doc Fixes (#2597)
Bibo-Joshi Oct 1, 2021
bcc62bb
Merge remote-tracking branch 'upstream/v14' into v14
eldbud Oct 3, 2021
9ed515a
Merge remote-tracking branch 'upstream/v14' into v14
eldbud Oct 7, 2021
d82473a
Merge remote-tracking branch 'upstream/v14' into v14
eldbud Oct 11, 2021
10f3786
Merge remote-tracking branch 'upstream/v14' into v14
eldbud Oct 17, 2021
757a499
added intersphinx to RTD conf.py, and fixed minor docs issues
eldbud Oct 18, 2021
6720c88
added intersphinx to RTD conf.py, and fixed minor docs issues
eldbud Oct 18, 2021
b24d7d8
Introduce Enums for telegram.constants (#2708)
Bibo-Joshi Oct 19, 2021
2ca6a98
Merge remote-tracking branch 'upstream/v14' into v14
eldbud Oct 19, 2021
948582f
Merge branch 'v14' into docs-link_python_classes_to_docs_#2633
eldbud Oct 19, 2021
a060da3
Merge remote-tracking branch 'origin/doc-fixes' into docs-link_python…
eldbud Oct 19, 2021
41d4ad3
added APScheduler to intersphinx
eldbud Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Hey! You're PRing? Cool! Please have a look at the below checklist. It's here to
* If relevant:

- [ ] Added new constants at `telegram.constants` and shortcuts to them as class variables
- [ ] Link new and existing constants in docstrings instead of hard coded number and strings
- [ ] Add new message types to `Message.effective_attachment`
- [ ] Added new handlers for new update types
- [ ] Added new filters for new message (sub)types
- [ ] Added or updated documentation for the changed class(es) and/or method(s)
Expand Down
74 changes: 70 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
# serve to show the default.
import sys
import os
# import telegram
from enum import Enum
from typing import Tuple

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
from docutils.nodes import Element
from sphinx.application import Sphinx
from sphinx.domains.python import PyXRefRole
from sphinx.environment import BuildEnvironment
from sphinx.util import logging

sys.path.insert(0, os.path.abspath('../..'))

# -- General configuration ------------------------------------------------
Expand All @@ -30,8 +37,16 @@
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon'
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx'
]

# Use intersphinx to reference the python builtin library docs
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'APScheduler': ('https://apscheduler.readthedocs.io/en/3.x/', None)
}

# Don't show type hints in the signature - that just makes it hardly readable
# and we document the types anyway
autodoc_typehints = 'none'
Expand All @@ -45,7 +60,7 @@
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8-sig'
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
Expand Down Expand Up @@ -299,11 +314,62 @@

# -- script stuff --------------------------------------------------------

# get the sphinx(!) logger
# Makes sure logs render in red and also plays nicely with e.g. the `nitpicky` option.
sphinx_logger = logging.getLogger(__name__)

CONSTANTS_ROLE = 'tg-const'
import telegram # We need this so that the `eval` below works


class TGConstXRefRole(PyXRefRole):
"""This is a bit of Sphinx magic. We add a new role type called tg-const that allows us to
reference values from the `telegram.constants.module` while using the actual value as title
of the link.

Example:

:tg-const:`telegram.constants.MessageLimit.TEXT_LENGTH` renders as `4096` but links to the
constant.
"""
def process_link(self, env: BuildEnvironment, refnode: Element,
has_explicit_title: bool, title: str, target: str) -> Tuple[str, str]:
title, target = super().process_link(env, refnode, has_explicit_title, title, target)
try:
# We use `eval` to get the value of the expression. Maybe there are better ways to
# do this via importlib or so, but it does the job for now
value = eval(target)
# Maybe we need a better check if the target is actually from tg.constants
# for now checking if it's an Enum suffices since those are used nowhere else in PTB
if isinstance(value, Enum):
# Special casing for file size limits
if isinstance(value, telegram.constants.FileSizeLimit):
return f'{int(value.value / 1e6)} MB', target
return repr(value.value), target
sphinx_logger.warning(
f'%s:%d: WARNING: Did not convert reference %s. :{CONSTANTS_ROLE}: is not supposed'
' to be used with this type of target.',
refnode.source,
refnode.line,
refnode.rawsource,
)
return title, target
except Exception as exc:
sphinx_logger.exception(
f'%s:%d: WARNING: Did not convert reference %s due to an exception.',
refnode.source,
refnode.line,
refnode.rawsource,
exc_info=exc
)
return title, target


def autodoc_skip_member(app, what, name, obj, skip, options):
pass


def setup(app):
def setup(app: Sphinx):
app.add_css_file("dark.css")
app.connect('autodoc-skip-member', autodoc_skip_member)
app.add_role_to_domain('py', CONSTANTS_ROLE, TGConstXRefRole())
8 changes: 0 additions & 8 deletions docs/source/telegram.chataction.rst

This file was deleted.

8 changes: 0 additions & 8 deletions docs/source/telegram.ext.utils.stack.rst

This file was deleted.

8 changes: 0 additions & 8 deletions docs/source/telegram.parsemode.rst

This file was deleted.

2 changes: 0 additions & 2 deletions docs/source/telegram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ telegram package
telegram.botcommandscopechatmember
telegram.callbackquery
telegram.chat
telegram.chataction
telegram.chatinvitelink
telegram.chatlocation
telegram.chatmember
Expand Down Expand Up @@ -52,7 +51,6 @@ telegram package
telegram.messageautodeletetimerchanged
telegram.messageid
telegram.messageentity
telegram.parsemode
telegram.photosize
telegram.poll
telegram.pollanswer
Expand Down
3 changes: 2 additions & 1 deletion examples/chatmemberbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import logging
from typing import Tuple, Optional

from telegram import Update, Chat, ChatMember, ParseMode, ChatMemberUpdated
from telegram import Update, Chat, ChatMember, ChatMemberUpdated
from telegram.constants import ParseMode
from telegram.ext import (
CommandHandler,
ChatMemberHandler,
Expand Down
5 changes: 3 additions & 2 deletions examples/contexttypesbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from collections import defaultdict
from typing import DefaultDict, Optional, Set

from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ParseMode
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ParseMode
from telegram.ext import (
CommandHandler,
CallbackContext,
Expand Down Expand Up @@ -57,7 +58,7 @@ def message_clicks(self) -> Optional[int]:
def message_clicks(self, value: int) -> None:
"""Allow to change the count"""
if not self._message_id:
raise RuntimeError('There is no message associated with this context obejct.')
raise RuntimeError('There is no message associated with this context object.')
self.chat_data.clicks_per_message[self._message_id] = value

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion examples/deeplinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import logging

from telegram import ParseMode, InlineKeyboardMarkup, InlineKeyboardButton, Update, helpers
from telegram import InlineKeyboardMarkup, InlineKeyboardButton, Update, helpers
from telegram.constants import ParseMode
from telegram.ext import (
CommandHandler,
CallbackQueryHandler,
Expand Down
3 changes: 2 additions & 1 deletion examples/errorhandlerbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import logging
import traceback

from telegram import Update, ParseMode
from telegram import Update
from telegram.constants import ParseMode
from telegram.ext import CommandHandler, Updater, CallbackContext

# Enable logging
Expand Down
3 changes: 2 additions & 1 deletion examples/inlinebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import logging
from uuid import uuid4

from telegram import InlineQueryResultArticle, ParseMode, InputTextMessageContent, Update
from telegram import InlineQueryResultArticle, InputTextMessageContent, Update
from telegram.constants import ParseMode
from telegram.helpers import escape_markdown
from telegram.ext import Updater, InlineQueryHandler, CommandHandler, CallbackContext

Expand Down
2 changes: 1 addition & 1 deletion examples/pollbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

from telegram import (
Poll,
ParseMode,
KeyboardButton,
KeyboardButtonPollType,
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
Update,
)
from telegram.constants import ParseMode
from telegram.ext import (
CommandHandler,
PollAnswerHandler,
Expand Down
5 changes: 1 addition & 4 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from ._files.location import Location
from ._files.venue import Venue
from ._files.videonote import VideoNote
from ._chataction import ChatAction
from ._dice import Dice
from ._userprofilephotos import UserProfilePhotos
from ._keyboardbuttonpolltype import KeyboardButtonPollType
Expand All @@ -58,7 +57,6 @@
from ._forcereply import ForceReply
from ._files.inputfile import InputFile
from ._files.file import File
from ._parsemode import ParseMode
from ._messageentity import MessageEntity
from ._messageid import MessageId
from ._games.game import Game
Expand Down Expand Up @@ -168,6 +166,7 @@
'Animation',
'Audio',
'Bot',
'bot_api_version',
'BotCommand',
'BotCommandScope',
'BotCommandScopeAllChatAdministrators',
Expand All @@ -180,7 +179,6 @@
'CallbackGame',
'CallbackQuery',
'Chat',
'ChatAction',
'ChatInviteLink',
'ChatLocation',
'ChatMember',
Expand Down Expand Up @@ -256,7 +254,6 @@
'MessageEntity',
'MessageId',
'OrderInfo',
'ParseMode',
'PassportData',
'PassportElementError',
'PassportElementErrorDataField',
Expand Down
Loading