Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #572.
The docs already had
sphinx.ext.viewcodeenabled, 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. Sinceviewcodeandlinkcodeare mutually exclusive in Sphinx, this swaps tosphinx.ext.linkcodewith a customlinkcode_resolve.linkcode_revision: reuses the existingcurrent_tagrelease-detection logic — pins to the tag on a tagged release build, otherwise the exactgit rev-parse HEADcommit (so line numbers never drift), falling back tomainif git isn't available.linkcode_resolve(domain, info): resolves the documented object via module/attribute traversal, unwraps decorators, usesinspect.getsourcefile/getsourcelinesfor file+line, and returnshttps://github.com/apache/hamilton/blob/<rev>/<path>#L<line>. ReturnsNonefor 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 thathamilton.base.StrictIndexTypePandasDataFrameResult(the object cited in the issue) now links to the correct GitHub line.