Skip to content

docs: link reference API docs back to GitHub source - #1717

Draft
naikvaib wants to merge 1 commit into
apache:mainfrom
naikvaib:docs/link-to-github-source
Draft

naikvaib wants to merge 1 commit into
apache:mainfrom
naikvaib:docs/link-to-github-source

Conversation

@naikvaib

Copy link
Copy Markdown

Fixes #572.

The docs already had sphinx.ext.viewcode enabled, but that only links to a copy of the source hosted on the docs site itself (_modules/...), not to GitHub — which is what this issue asks for. Since viewcode and linkcode are mutually exclusive in Sphinx, this swaps to sphinx.ext.linkcode with a custom linkcode_resolve.

  • linkcode_revision: reuses the existing current_tag release-detection logic — pins to the tag on a tagged release build, otherwise the exact git rev-parse HEAD commit (so line numbers never drift), falling back to main if git isn't available.
  • linkcode_resolve(domain, info): resolves the documented object via module/attribute traversal, unwraps decorators, uses inspect.getsourcefile/getsourcelines for file+line, and returns https://github.com/apache/hamilton/blob/<rev>/<path>#L<line>. Returns None for non-Python domains or objects outside the repo.

Verified with a full local docs build (sphinx-build -b dirhtml -E -T docs, heavy optional ML extras like mlflow/pyspark/dask skipped as infeasible to install quickly — build succeeded with only pre-existing unrelated autodoc warnings for those). Confirmed in the generated HTML that hamilton.base.StrictIndexTypePandasDataFrameResult (the object cited in the issue) now links to the correct GitHub line.

Replace sphinx.ext.viewcode with sphinx.ext.linkcode and a custom
linkcode_resolve() in docs/conf.py. viewcode only rendered a local copy
of the source inside the docs site; linkcode points each object's
"[source]" link directly at its file/line on
github.com/apache/hamilton, pinned to the release tag when building
from a tag and to the exact commit otherwise so line numbers stay in
sync.

Verified with a local sphinx-build: the StrictIndexTypePandasDataFrameResult
entry cited in the issue now links to
github.com/apache/hamilton/blob/<sha>/hamilton/base.py#L306, the correct
line.

Fixes apache#572

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link back to github from reference API docs

1 participant