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 default_role for Sphinx. #571

Merged
merged 13 commits into from
Sep 9, 2019
Merged

Add default_role for Sphinx. #571

merged 13 commits into from
Sep 9, 2019

Conversation

Julian
Copy link
Member

@Julian Julian commented Sep 8, 2019

(Mentioned in #568 (comment))

Fix a bunch of broken refs along the way, which become
errors now via -W if you have default_role set.

In theory you can catch those via sphinx-build -n (i.e.
nitpick mode), which IMHO is a decent idea anyhow, but it's
a longer diff to enable that because it'd involve fixing a
bunch of the places that try to reference types that don't
exist (e.g. :type foo: Any value). But obviously can be done.

Also didn't actually use this anywhere yet (the any role),
but will do so in a follow-up if this is acceptable.

But throwing the PR up as-is just to show what I meant / see if it's something we want.

Pull Request Check List

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.

  • Added tests for changed code.
  • New features have been added to our Hypothesis testing strategy.
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
    • ...and used in the stub test file tests/typing_example.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changes to the signature of @attr.s() have to be added by hand too.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Documentation in .rst files is written using semantic newlines.
  • Changes (and possible deprecations) have news fragments in changelog.d.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

Fix a bunch of broken refs along the way, which become
errors now via -W if you have default_role set.

In theory you can catch those via sphinx-build -n (i.e.
nitpick mode), which IMHO is a decent idea anyhow, but it's
a longer diff to enable that because it'd involve fixing a
bunch of the places that try to reference types that don't
exist (e.g. :type foo: Any value). But obviously can be done.

Also didn't actually use this anywhere yet (the any role),
but will do so in a follow-up if this is acceptable.
@Julian Julian requested a review from hynek September 8, 2019 17:39
@Julian
Copy link
Member Author

Julian commented Sep 8, 2019

OK and now I just used this for a bunch of builtin refs just to show you how it looks. I can keep going, but actually there are some more broken refs hiding that don't become errors without nitpick. E.g.:

A validator that raises a :class:`attr.exceptions.NotCallableError`
this is actually a broken ref (to NotCallableError), which doesn't seem like it's included in any document, but that doesn't raise an error without having nitpick mode turned on unless you try to any-role-ref it.

@hynek
Copy link
Member

hynek commented Sep 9, 2019

That looks cool overall. If we go that way it should definitely pass in nitpick mode if it's possible at all.

Enables the link to z.i.Interface.
Fix the remaining broken links or whitelist them via nitpick_ignore.
Except one, that probably meant :func:, and which
is a duplicate ref.
@Julian
Copy link
Member Author

Julian commented Sep 9, 2019

OK done. And looks like there weren't very many more broken references after the first few, so that's good, was fairly easy.

So nitpick mode is enabled -- I use the most "conservative" way to handle non-types being mentioned as types myself -- which is basically from now on you literally need to whitelist those in Sphinx's config. IMO this is the right idea considering just how easy it is to get Sphinx to silently not link a reference (as you saw without -n :/) but there are some other ways to do this if you don't like this one.

(Sphinx will though error if the default_role finds multiple possible targets, so if you accidentally have a doc and a type named the same thing or whatever, you're still fine in that you'll get a non-silent failure.)

@hynek
Copy link
Member

hynek commented Sep 9, 2019

Cool, TIL, thanks!

@hynek hynek merged commit 8824dc2 into master Sep 9, 2019
@hynek hynek deleted the sphinx-any-default-role branch September 9, 2019 13:02
@hynek hynek mentioned this pull request Mar 30, 2020
@hynek hynek mentioned this pull request Nov 17, 2021
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