Skip to content

Commit

Permalink
Switch to linkcode extension (#4410)
Browse files Browse the repository at this point in the history
* Switch to linkcode extension

Signed-off-by: Ankita Katiyar <[email protected]>

* remove os

Signed-off-by: Ankita Katiyar <[email protected]>

* remove os

Signed-off-by: Ankita Katiyar <[email protected]>

* remove os

Signed-off-by: Ankita Katiyar <[email protected]>

* Refactor

Signed-off-by: Ankita Katiyar <[email protected]>

* use os

Signed-off-by: Ankita Katiyar <[email protected]>

---------

Signed-off-by: Ankita Katiyar <[email protected]>
  • Loading branch information
ankatiyar authored Jan 13, 2025
1 parent 396a1f5 commit 71650a0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
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

import kedro
from kedro import __version__ as release

# -- Project information -----------------------------------------------------
Expand All @@ -47,7 +50,7 @@
"sphinx_autodoc_typehints",
"sphinx.ext.doctest",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.linkcode",
"sphinx_copybutton",
"myst_parser",
"notfound.extension",
Expand Down Expand Up @@ -534,3 +537,26 @@ def setup(app):

myst_heading_anchors = 5
myst_enable_extensions = ["colon_fence"]

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.__file__))

return 'https://github.com/kedro-org/kedro/blob/main/kedro/%s#L%d#L%d' % (
relpath, lineno, lineno + len(source) - 1
)
except (KeyError, ImportError, AttributeError, TypeError, OSError, ValueError):
return None

0 comments on commit 71650a0

Please sign in to comment.