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

Add links to externally hosted source code for documented symbols #188

Merged
merged 3 commits into from
Oct 25, 2023

Conversation

jnikula
Copy link
Owner

@jnikula jnikula commented Oct 7, 2023

Add [source] links for documented symbols, similar to what sphinx.ext.viewcode and sphinx.ext.linkcode do.

https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html
https://www.sphinx-doc.org/en/master/usage/extensions/viewcode.html

Running make html and looking at examples.html gives the best idea what this does.

Copy link
Collaborator

@BrunoMSantos BrunoMSantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ;)

doc/conf.py Outdated
@@ -56,6 +56,11 @@

hawkmoth_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../test/examples')

source_uri = 'https://github.com/jnikula/hawkmoth/tree/{version}/test/examples/{{source}}#L{{line}}'
source_version = version if len(version.split('.')) == 3 else 'master'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should have an intermediate fallback to a specific hash revision instead of using a branch name which is moving target. But I guess it's fine for the current use case.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That requires looking at git, and opens up more problems. I'd revisit that later.

I did notice the VERSION file does not have v prefix, but the tags do, so I fixed that.

@jnikula
Copy link
Owner Author

jnikula commented Oct 21, 2023

I noticed some weirdness in the line numbers, also in warnings. Probably related to how docstring adds/removes lines. I'll look into it before merging this one.

Fix some issues in line number references. Take into account stripping
blank lines from the comments and adding header lines before the
comments. Take into account that ViewList uses 0-based line numbers.

With this, error reporting should have more accurate line numbers.
Sphinx has sphinx.ext.viewcode and sphinx.ext.linkcode extensions to
fully incorporate source code into the documentation and to link to
externally hosted source code, respectively. They are not trivial to
integrate with Hawkmoth, however.

Add a dedicated version of linkcode that can be configured with a simple
template URI.
This is a bit more convoluted than usual, because we want documentation
built for tagged releases to point at the source code for the release,
and master otherwise. We rely on version having a '.dev0' suffix (or
'.<anything>', really) once we've deviated from the latest release.

The first formatting pass also requires us to wrap {source} and {line}
in extra {}'s.
@jnikula
Copy link
Owner Author

jnikula commented Oct 23, 2023

I noticed some weirdness in the line numbers, also in warnings. Probably related to how docstring adds/removes lines. I'll look into it before merging this one.

Added a new commit fixing that, and adjusted signode.line a bit. The references seem more sensible now.

@BrunoMSantos
Copy link
Collaborator

Cool. Looks even better now I guess :)

@jnikula jnikula merged commit 79bc1e2 into master Oct 25, 2023
5 checks passed
@jnikula
Copy link
Owner Author

jnikula commented Oct 25, 2023

Cool. Looks even better now I guess :)

Thanks, merged!

@jnikula jnikula deleted the source-link branch October 25, 2023 17:45
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.

None yet

2 participants