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 extensions to define the keys returned by linkcode ext #11824

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

n-peugnet
Copy link
Contributor

@n-peugnet n-peugnet commented Dec 29, 2023

Subject: Allow extensions to define the keys the linkcode extension should return for a domain.

Feature or Bugfix

  • Feature

Purpose

  • The linkcode extension currently only works for some pre-defined domains.
    By allowing extensions to define the keys associated with a domain, it opens up the linkcode extension to a lot more new domains.
    For instance, in the sphinxcontrib-phpdomain, one could simply add the following in setup(app) function to make linkcode work for the php domain:

    app.add_linkcode_domain('php', ['namespace', 'class', 'fullname'])

Detail

  • I am not sure that it is the best way to do it. I took inspiration from the methods above that allow to interact with autodoc extension.

Relates

  • Did not find any related issue.

P.S. Ah sorry, I made this commit on an old tag for my tests, I will rebase my branch.

@n-peugnet n-peugnet force-pushed the linkcode-generic branch 3 times, most recently from 9fe04da to 669a355 Compare December 29, 2023 11:52
@picnixz
Copy link
Member

picnixz commented Jan 1, 2024

It appears to be quite similar to what we do for search languages so I'd say it's fine?

Can you also add a CHANGELOG entry and a test? (probably of the same kind as those for the search languages, if any)

@n-peugnet
Copy link
Contributor Author

n-peugnet commented Jan 1, 2024

@picnixz I just pushed commits that add a test and a changelog entry. Don't hesitate to edit it and my change in the docs as well if you find better ways to describe it.

P.S. I will also add a small sentence in the linkcode docs that links to this new function.
P.S. 2 I don't get why the tests are failing on Windows with the last commit and not the previous one.

@picnixz
Copy link
Member

picnixz commented Jan 1, 2024

Windows tests for PO files are flaky, don't worry about it

@picnixz
Copy link
Member

picnixz commented Jan 1, 2024

By the way, in the future, it's better not to force push commits. We squash them before merging and force-pushing makes review harder (I also used to rebase/force push)

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.

Personally I don't mind the feature and I think it can land in 7.3. When we'll do the release and it's not included, you can ask for it be included (assuming you addressed the small comments, sorry if I didn't put them before).

doc/usage/extensions/linkcode.rst Outdated Show resolved Hide resolved
.. versionadded:: 7.3
"""
from sphinx.ext.linkcode import domain_keys
domain_keys[domain] = keys
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering but what happens if two extensions do the same? should extend the keys and removing duplicates?

Also, you should probably say (in the doc) that the keys an extension defines overrides whatever keys were previously defined if we go with the current implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wondering but what happens if two extensions do the same? should extend the keys and removing duplicates?

I don't think so, the idea is that an extension that provides support for a new domain, for instance sphinxcontrib-phpdomain, can now add the php domain to the list of domains supported by linkcode. I don't think that anybody uses two extensions adding support for the same domain, so I don't see any chances of conflict here.

Another possibility I see would be to completely forbid overriding an existing key, or maybe add a warning when a key is overridden. But I thought overriding the existing keys could also be useful in a way.

Maybe we should wait for another opinion? I'm not in a hurry for this feature.

Also, you should probably say (in the doc) that the keys an extension defines overrides whatever keys were previously defined if we go with the current implementation.

I will add a more descriptive explanation when we settle on the preferred behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

I would like the opinion of another maintainer/contributor. Since we are in a holiday period, it might take a while though. When we release new versions, we create an issue and you can ask at that moment if we didn't decide on anything.

@AA-Turner
Copy link
Member

@jdknight you were looking at linkcode recently - any thoughts on this?

@jdknight
Copy link
Contributor

@jdknight you were looking at linkcode recently - any thoughts on this?

Adding support for custom domains looks like a good idea to me.

# Conflicts:
#	CHANGES.rst
#	sphinx/application.py
#	sphinx/ext/linkcode.py
#	tests/roots/test-ext-viewcode/conf.py
#	tests/test_extensions/test_ext_viewcode.py
@AA-Turner
Copy link
Member

@n-peugnet I am not sure that this should be a method on app/Sphinx, as the first-party extensions should try and act like normal extensions as much as possible. As such, I've pushed a proposal to make this a function within sphinx.ext.linkcode -- please let me know your thoughts.

A

@n-peugnet
Copy link
Contributor Author

I am not sure that this should be a method on app/Sphinx, as the first-party extensions should try and act like normal extensions as much as possible. As such, I've pushed a proposal to make this a function within sphinx.ext.linkcode -- please let me know your thoughts.

If I remember correctly, the reason I chose to add it in app/Sphinx was to imitate add_autodocumenter(), also described in Developing autodoc extensions. But I completely understand, and I agree that core Sphinx should avoid having special code for extensions, even if they are first-party.

So this is fine by me.

@AA-Turner AA-Turner added this to the 8.2.0 milestone Oct 24, 2024
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.

4 participants