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

ext: allow builders to override support for linkcode references #10585

Closed
wants to merge 2 commits into from
Closed

ext: allow builders to override support for linkcode references #10585

wants to merge 2 commits into from

Conversation

jdknight
Copy link
Contributor

Feature or Bugfix

  • Feature

Purpose

The original sphinx.ext.linkcode extension will only include references into a doctree for html builders. Custom builders who would like to handle linkcode references do not have a graceful way to enable this feature.

This commit aims to allow custom builders to override when these references are included. If a builder defines a supported_linkcode attribute, this extension will use the value of this attribute to consider other builders/formats when conditionally adding references.

Relates

@tk0miya tk0miya added extensions type:proposal a feature suggestion labels Jun 26, 2022
@tk0miya tk0miya added this to the 5.1.0 milestone Jun 26, 2022
Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

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

+1: Reasonable. It's much better to describe this behavior in the document of linkcode extension.

@jdknight
Copy link
Contributor Author

jdknight commented Jul 3, 2022

It's much better to describe this behavior in the document of linkcode extension.

Just for clarity, are you asking that we add a comment inside the implementation to explain this option, such as:

@@ -24,6 +24,11 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
         raise LinkcodeError(
             "Function `linkcode_resolve` is not given in conf.py")

+    # By default, the linkcode extension will only inject references
+    # for an `html` builder/format. If a (third-party) builder wishes
+    # to support managing references generated by linkcode as well, they
+    # can override the `supported_linkcode` attribute in their builder
+    # definition.
     node_only_expr = getattr(app.builder, 'supported_linkcode', 'html')

     domain_keys = {

Or is there another document you are referring to? I assume it would not be doc/usage/extensions/linkcode.rst since that is more user focused. Unless you are recommending another document somewhere inside doc/extdev?

@AA-Turner
Copy link
Member

Please may you add the new attribute/override mechanism somewhere in the documentation, and please also update CHANGES.

A

@AA-Turner AA-Turner modified the milestones: 5.1.0, 5.x Jul 17, 2022
@AA-Turner AA-Turner modified the milestones: 5.x, 6.x Oct 4, 2022
@AA-Turner AA-Turner changed the base branch from 5.x to master October 16, 2022 15:28
@jdknight
Copy link
Contributor Author

jdknight commented Jan 3, 2023

@AA-Turner, any chance we can get this in a release window? If there is anything else that needed to be done, please let me know.

@kislyuk
Copy link

kislyuk commented Feb 11, 2023

Hi all, is there anything that can be done to get this merged? I am looking to make use of @jdknight's excellent confluencebuilder extension, but I need it to work with linkcode and this looks to be the blocker.

jdknight added a commit to sphinx-contrib/confluencebuilder that referenced this pull request Mar 4, 2023
For `sphinx.ext.linkcode` extension, prospect changes [1] will provide
support for other Sphinx extensions to take advantage of
linkcode-generated references. Updating this extension to hint that it
will support `sphinx.ext.linkcode`. This should help ensure a future
release the Confluence Builder extension will automatically be ready to
utilize the Sphinx-managed extension (if Sphinx does update to include
linkcode support for custom builders).

If Sphinx changes the way of integrating with linkcode or opts to not
support such an extension, the introduced line in this commit can be
modified or dropped at a later time.

[1]: sphinx-doc/sphinx#10585

Signed-off-by: James Knight <james.d.knight@live.com>
@AA-Turner AA-Turner modified the milestones: 6.x, 7.x Apr 29, 2023
jdknight added 2 commits April 7, 2024 12:32
The original `sphinx.ext.linkcode` extension will only include
references into a doctree for `html` builders. Custom builders who
would like to handle linkcode references do not have a graceful way to
enable this feature.

This commit aims to allow custom builders to override when these
references are included. If a builder defines a `supported_linkcode`
attribute, this extension will use the value of this attribute to
consider other builders/formats when conditionally adding references.

Signed-off-by: James Knight <james.d.knight@live.com>
Adding a document under Sphinx's "extension development" chapter which
provides information about integrating third-party builds with recently
added features to the built-in linkcode extension.

Signed-off-by: James Knight <james.d.knight@live.com>
@jdknight jdknight closed this by deleting the head repository Jul 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions type:proposal a feature suggestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants