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

Allow builders to override support for linkcode references #12852

Conversation

jdknight
Copy link
Contributor

Note: this was originally proposed in #10585, but was accidentally removed during some cleanup; republishing.

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

@jayaddison jayaddison added extensions type:proposal a feature suggestion labels Sep 3, 2024
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Some comments:

  • I would expect supports_linkcode = True to indicate 'html'
  • I would expect supports_linkcode = False to entirely disable linkcode support.
  • I would recommend the documentation to explain that whatever is in supports_linkcode should match the only directive argument.

doc/extdev/extensions/linkcode.rst Outdated Show resolved Hide resolved
doc/extdev/extensions/linkcode.rst Outdated Show resolved Hide resolved
@jdknight
Copy link
Contributor Author

I would recommend the documentation to explain that whatever is in supports_linkcode should match...

I would be happy to extend the documentation to be a bit more clear on what value should be used. The original submission would be that the value of this attribute is expected to have a compatible <expression> value that follows the only directive.

  • I would expect supports_linkcode = True to indicate 'html'
  • I would expect supports_linkcode = False to entirely disable linkcode support.

I am a bit confused on these statements. Setting supports_linkcode = False with the proposed change would disable linkcode support on any custom builder (in the same manner as if it was not set). And setting supports_linkcode = True would achieve the same results as if a builder specified supports_linkcode = 'html'.

 class MyAwesomeBuilder(Builder):
     supported_linkcode = True

... you would have an only node with True and not 'html'.

Is the ask here to instead of using an <expression> value, you want some sort of generator to create a custom only node?

@picnixz
Copy link
Member

picnixz commented Sep 27, 2024

Setting supports_linkcode = False with the proposed change would disable linkcode support on any custom builder (in the same manner as if it was not set).

Is the ask here to instead of using an value, you want some sort of generator to create a custom only node?

Forget about my comment on them, I was mistaken.

I would be happy to extend the documentation to be a bit more clear on what value should be used. The original submission would be that the value of this attribute is expected to have a compatible

You can just say that whatever you use in supported_linkcode should match the expectations of the :rst:dir:`only` directive.


Also, you'll need a CHANGELOG entry!

@jdknight
Copy link
Contributor Author

How about the following text?

The linkcode extension, by default, will only inject references for an html builder. If a non-html builder wishes to support managing references generated by linkcode, the supported_linkcode attribute can be defined in the builder's implementation. The expected value for this attribute is an expression which is compatible with only.

For example, if a builder was named my-awesome-builder, the following can be used:

class MyAwesomeBuilder(Builder):
    supported_linkcode = 'my-awesome-builder'
    ...

(note: will format with proper rst/directives in the final change set)

jdknight and others added 2 commits October 6, 2024 01:15
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 force-pushed the ext-linkcode-allow-builder-to-enable-references branch from 0e30145 to 4e82173 Compare October 6, 2024 05:16
@AA-Turner AA-Turner requested a review from picnixz October 6, 2024 19:06
@AA-Turner
Copy link
Member

@jdknight I can't request a review from you as it's your PR -- please have a look at the pushed changes before merge.

A

@AA-Turner AA-Turner changed the title Allow builders to override support for linkcode references (republish) Allow builders to override support for linkcode references Oct 6, 2024
@jdknight
Copy link
Contributor Author

jdknight commented Oct 6, 2024

Changes look great; thanks!

@AA-Turner AA-Turner merged commit d1c4480 into sphinx-doc:master Oct 6, 2024
23 checks passed
@AA-Turner
Copy link
Member

Thank you, James (@jdknight).

A

@AA-Turner AA-Turner added this to the 8.1.x milestone Oct 6, 2024
@jdknight jdknight deleted the ext-linkcode-allow-builder-to-enable-references branch October 6, 2024 22:04
@picnixz
Copy link
Member

picnixz commented Oct 7, 2024

I wasn't around for the review but the text is great! so thanks again!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 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