diff --git a/docs/source/conf.py b/docs/source/conf.py index b8ae078b7..bbae7e99e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,6 +10,7 @@ from __future__ import annotations import importlib +import inspect import os import re import sys @@ -17,9 +18,10 @@ from pathlib import Path from click import secho, style - from kedro_viz import __version__ as release +from package import kedro_viz + # -- Project information ----------------------------------------------------- project = "kedro-viz" @@ -90,4 +92,25 @@ def _override_permalinks_icon(app): def setup(app): app.connect("builder-inited", _override_permalinks_icon) - + +def linkcode_resolve(domain, info): + """Resolve a GitHub URL corresponding to a Python object.""" + if domain != 'py': + return None + + try: + mod = sys.modules[info['module']] + obj = mod + for attr in info['fullname'].split('.'): + obj = getattr(obj, attr) + obj = inspect.unwrap(obj) + + filename = inspect.getsourcefile(obj) + source, lineno = inspect.getsourcelines(obj) + relpath = os.path.relpath(filename, start=os.path.dirname( + kedro_viz.__file__)) + + return f'https://github.com/kedro-org/kedro-viz/tree/main/package/{relpath}#L{lineno}#L{lineno + len(source) - 1}' + + except (KeyError, ImportError, AttributeError, TypeError, OSError, ValueError): + return None