Skip to content

[ENH] Correct broken source links for set_params and get_params in Aeon estimator docs #2754

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

Merged
merged 13 commits into from
Jun 6, 2025
Merged
46 changes: 39 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,55 @@ def linkcode_resolve(domain, info):
def find_source():
# try to find the file and line number, based on code from numpy:
# https://github.com/numpy/numpy/blob/main/doc/source/conf.py#L286
obj = sys.modules[info["module"]]
for part in info["fullname"].split("."):
obj = getattr(obj, part)

import inspect
import os

obj = inspect.unwrap(obj)
# Get the top-level object from the module name
obj = sys.modules[info["module"]]

# Traverse dotted path (e.g., module.submodule.Class.method)
for part in info["fullname"].split("."):
obj = getattr(obj, part)

fn = inspect.getsourcefile(obj)
fn = os.path.relpath(fn, start=os.path.dirname(aeon.__file__))
# Unwrapping decorators (if any), so we can get the true
# source function
if inspect.isfunction(obj):
obj = inspect.unwrap(obj)

# Get the source filename
try:
fn = inspect.getsourcefile(obj)
except TypeError:
fn = None

# If no source file is found, return None (no link)
if not fn:
return None

# Make filename relative to the aeon source directory
startdir = Path(aeon.__file__).parent.parent
try:
fn = os.path.relpath(fn, start=startdir).replace(os.path.sep, "/")
except ValueError:
return None

# Filter out files not in the aeon package
# (e.g., inherited from sklearn)
if not fn.startswith("aeon/"):
return None

# Get line range of the object
source, lineno = inspect.getsourcelines(obj)
return fn, lineno, lineno + len(source) - 1

if domain != "py" or not info["module"]:
return None
try:
filename = "aeon/%s#L%d-L%d" % find_source()
result = find_source()
if not result:
return None
filename = "%s#L%d-L%d" % result
except Exception:
filename = info["module"].replace(".", "/") + ".py"
return "https://github.com/aeon-toolkit/aeon/blob/{}/{}".format(
Expand Down