Skip to content

Commit

Permalink
Move to linkcode extension on docs
Browse files Browse the repository at this point in the history
Signed-off-by: Ankita Katiyar <[email protected]>
  • Loading branch information
ankatiyar committed Jan 13, 2025
1 parent e9542ad commit d11d044
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
from __future__ import annotations

import importlib
import inspect
import os
import re
import sys
from inspect import getmembers, isclass, isfunction
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"
Expand Down Expand Up @@ -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

0 comments on commit d11d044

Please sign in to comment.