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

intersphinx: Allow strict prefix matching #8981

Closed
wants to merge 1 commit into from

Conversation

nijel
Copy link
Contributor

@nijel nijel commented Mar 11, 2021

Subject: Add optional strict prefix matching to intersphinx

Feature or Bugfix

  • Feature

Purpose

  • allows better control on what links go to the external documentation

Detail

Strictly using prefix for intersphinx links gives a better control on
external links - only links explicitely declared will point to the
external documentation.

Fixes #2068

Relates

nijel added a commit to WeblateOrg/weblate that referenced this pull request Mar 11, 2021
This is not yet merged feature in Sphinx, see
sphinx-doc/sphinx#8981
@tk0miya tk0miya added the type:proposal a feature suggestion label Mar 13, 2021
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.

LGTM with nits.

doc/usage/extensions/intersphinx.rst Outdated Show resolved Hide resolved
@@ -173,6 +181,7 @@ def test_missing_reference_pydomain(tempdir, app, status, warning):
'https://docs.python.org/': inv_file,
}
app.config.intersphinx_cache_limit = 0
app.config.intersphinx_strict_prefix = False
Copy link
Member

Choose a reason for hiding this comment

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

Is this initialization needed? I think the configuration is initialized as False by default. So this assignment is not needed. I understand setting it up explicitly in test_missing_reference. But I don't understand why are they added in other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't work without that. Unfortunately, I have no clue how this works in the tests...

@tk0miya tk0miya added this to the 4.0.0 milestone Mar 13, 2021
@nijel nijel changed the base branch from 3.x to master March 13, 2021 09:31
@jakobandersen
Copy link
Contributor

Hmm, I'm not sure this is a descriptive name for the feature. How about something like intersphinx_resolve_only_explicit?
But even then, this doesn't seem like the right way to go. As argued in #8418, it seems strange to me to ask a domain to resolve a reference that you don't actually want it to resolve, just so intersphinx can pick it up.
I suggest a more direct apporach with an intersphinx role for requesting an intersphinx resolution, and then more fine-grained config vars to disable the missing-reference event handler.

@nijel
Copy link
Contributor Author

nijel commented Mar 13, 2021

As for name, I'm open to change it to anything. Changing intersphinx massively is something I can't do.

Having a dedicated role for intersphinx as you describe #8418 (comment) and having a way to disable handling of missing references would work for us as well. The drawback of this approach might be that it would require new Sphinx to build, while changing way the lookups works as done in this PR would keep the documentation compatible with current Sphinx as well (only the strict lookup would not be performed, what is fine as long as we do the validation in CI using compatible version).

I want to explicitly define where interphinx should be used and let Sphinx fail on missing references instead of silently picking up a reference from random linked documentation which happens to have a target which we forgot to define.

@phlax
Copy link

phlax commented Apr 25, 2021

it would be incredibly useful to have this feature added.

without it intersphinx is basically unusable for versioning

htuch pushed a commit to envoyproxy/envoy that referenced this pull request Apr 27, 2021
…#16155)

This PR
- adds a patched version of intersphinx (~from sphinx-doc/sphinx#8981)
- uses versioned refs for version history
- cleans up inline literals in version history

Signed-off-by: Ryan Northey <ryan@synca.io>
gokulnair pushed a commit to gokulnair/envoy that referenced this pull request May 6, 2021
…envoyproxy#16155)

This PR
- adds a patched version of intersphinx (~from sphinx-doc/sphinx#8981)
- uses versioned refs for version history
- cleans up inline literals in version history

Signed-off-by: Ryan Northey <ryan@synca.io>
Signed-off-by: Gokul Nair <gnair@twitter.com>
@phlax
Copy link

phlax commented Jun 7, 2021

@nijel do you still need this ? Any chance of rebasing/updating to resolve conflicts ?

if not, i could possibly take on this PR as it would be helpful to us to have this landed upstream

Strictly using prefix for intersphinx links gives a better control on
external links - only links explicitely declared will point to the
external documentation.

Fixes sphinx-doc#2068
@nijel
Copy link
Contributor Author

nijel commented Jun 8, 2021

I've just rebased it...

@jakobandersen
Copy link
Contributor

In connection with some of the other recent intersphinx discussions I think a single config var is too limiting. For example, one may like to disable intersphinx lookup for roles like :ref: and :doc:, but keep it for all xref generated by source code constructs, e.g., all directives in the Python, C, C++, Javascript, RST, etc. domains.
Perhaps it should be a list of disallowed domains, which defaults to [] by in sphinx-quickstart gets set to ['std']? I guess this is the domain that gives the most surprising lookups?

@phlax
Copy link

phlax commented Jul 14, 2021

disable intersphinx lookup for roles like :ref: and :doc:, but keep it for all xref generated by source code constructs...a list of disallowed domains, which defaults to []

this sounds useful but my feeling is that it adds 2 layers of complexity

just being able to disable the lookup up for non explicitly tagged links is incredibly useful if you want to use intersphinx with different versions of the same docs (we are using @nijel 's patch and its working v well)

how about we land this and then i would potentially be up for contributing further in terms of adding more fine-grained controls over intersphinx lookups

jakobandersen added a commit to jakobandersen/sphinx that referenced this pull request Jul 16, 2021
@jakobandersen
Copy link
Contributor

See #9459 for an implementation of #8981 (comment).

@tk0miya tk0miya removed this from the 4.2.0 milestone Sep 12, 2021
@tk0miya tk0miya added this to the 4.3.0 milestone Sep 12, 2021
jakobandersen added a commit to jakobandersen/sphinx that referenced this pull request Sep 18, 2021
jakobandersen added a commit to jakobandersen/sphinx that referenced this pull request Oct 2, 2021
jakobandersen added a commit to jakobandersen/sphinx that referenced this pull request Oct 30, 2021
jakobandersen added a commit to jakobandersen/sphinx that referenced this pull request Oct 31, 2021
@jakobandersen
Copy link
Contributor

Replaced by #9459, specifically by setting intersphinx_disabled_reftypes = ['*']. Though intersphinx_disabled_reftypes = ['std:doc'] should be enough to fix most silent resolution problems.

@nijel nijel deleted the strict-intersphinx branch October 31, 2021 18:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to not use intersphinx references as a fallback
4 participants