提交 cb86bd63 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Fix docs source linking

上级 afb0e1c1
import os
import inspect
import sys
import pytensor
from pathlib import Path
......@@ -234,24 +235,41 @@ htmlhelp_basename = "pytensor_doc"
# Resolve function
# This function is used to populate the (source) links in the API
def linkcode_resolve(domain, info):
def find_source():
def find_obj() -> object:
# try to find the file and line number, based on code from numpy:
# https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
obj = sys.modules[info["module"]]
for part in info["fullname"].split("."):
obj = getattr(obj, part)
return obj
def find_source(obj):
fn = Path(inspect.getsourcefile(obj))
fn = fn.relative_to(Path(__file__).parent)
fn = fn.relative_to(Path(pytensor.__file__).parent)
source, lineno = inspect.getsourcelines(obj)
return fn, lineno, lineno + len(source) - 1
def fallback_source():
return info["module"].replace(".", "/") + ".py"
if domain != "py" or not info["module"]:
return None
try:
filename = "pytensor/%s#L%d-L%d" % find_source()
obj = find_obj()
except Exception:
filename = info["module"].replace(".", "/") + ".py"
filename = fallback_source()
else:
try:
filename = "pytensor/%s#L%d-L%d" % find_source(obj)
except Exception:
# warnings.warn(f"Could not find source code for {domain}:{info}")
try:
filename = obj.__module__.replace(".", "/") + ".py"
except AttributeError:
# Some objects do not have a __module__ attribute (?)
filename = fallback_source()
import subprocess
tag = subprocess.Popen(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论