diff --git a/changes/unreleased/4839.gExNhF7C6kR5VrBg6cBaar.toml b/changes/unreleased/4839.gExNhF7C6kR5VrBg6cBaar.toml new file mode 100644 index 00000000000..cb93ea41ab9 --- /dev/null +++ b/changes/unreleased/4839.gExNhF7C6kR5VrBg6cBaar.toml @@ -0,0 +1,8 @@ +documentation = """Documentation improvements. + +* Fix [source] linking. +""" +[[pull_requests]] +uid = "4839" +author_uid = "aelkheir" +closes_threads = ["4838"] diff --git a/docs/auxil/sphinx_hooks.py b/docs/auxil/sphinx_hooks.py index 47fd9c9281c..62d8613c8b0 100644 --- a/docs/auxil/sphinx_hooks.py +++ b/docs/auxil/sphinx_hooks.py @@ -55,6 +55,8 @@ } +# Resolves to the parent directory of `telegram/`, depending on installation setup, +# could either be `/src` or `/site-packages` FILE_ROOT = Path(inspect.getsourcefile(telegram)).parent.parent.resolve() @@ -161,7 +163,7 @@ def autodoc_process_docstring( with contextlib.suppress(Exception): source_lines, start_line = inspect.getsourcelines(obj) end_line = start_line + len(source_lines) - file = Path(inspect.getsourcefile(obj)).relative_to(FILE_ROOT) + file = Path("src") / Path(inspect.getsourcefile(obj)).relative_to(FILE_ROOT) LINE_NUMBERS[name] = (file, start_line, end_line) # Since we don't document the `__init__`, we call this manually to have it available for