Skip to content
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

Link to github for flytekit docs #5831

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
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
64 changes: 63 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pathlib import Path
import logging
import sys
import inspect

import sphinx.application
import sphinx.errors
Expand Down Expand Up @@ -58,8 +59,8 @@
"sphinx.ext.graphviz",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.linkcode",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.extlinks",
"sphinx-prompt",
"sphinx_copybutton",
Expand Down Expand Up @@ -725,6 +726,67 @@ def filter(self, record: logging.LogRecord) -> bool:
return True


def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
"""
if domain != "py":
return None

import flytekit

modname = info["module"]
fullname = info["fullname"]

submod = sys.modules.get(modname)
if submod is None:
return None

obj = submod
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except AttributeError:
return None

if inspect.isfunction(obj):
obj = inspect.unwrap(obj)
try:
fn = inspect.getsourcefile(obj)
except TypeError:
fn = None
if not fn or fn.endswith("__init__.py"):
try:
fn = inspect.getsourcefile(sys.modules[obj.__module__])
except (TypeError, AttributeError, KeyError):
fn = None
if not fn:
return None

try:
source, lineno = inspect.getsourcelines(obj)
except (OSError, TypeError):
lineno = None

linespec = f"#L{lineno:d}-L{lineno + len(source) - 1:d}" if lineno else ""

startdir = Path(flytekit.__file__).parent.parent
try:
fn = os.path.relpath(fn, start=startdir).replace(os.path.sep, "/")
except ValueError:
return None

if not fn.startswith("flytekit/"):
return None

if flytekit.__version__ == "dev":
tag = "master"
else:
tag = f"v{flytekit.__version__}"

return f"https://github.com/flyteorg/flytekit/blob/{tag}/{fn}{linespec}"


def setup(app: sphinx.application.Sphinx) -> None:
"""Setup root logger for Sphinx"""
logger = logging.getLogger("sphinx")
Expand Down
Loading