Skip to content

Replace hardcoded links with intersphinx refs in docs #7623

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

Merged
merged 1 commit into from
Oct 4, 2019

Conversation

hoefling
Copy link
Contributor

@hoefling hoefling commented Oct 4, 2019

This is the first part of adding referencing to mypys docs (second part being #7624). I have configured intersphinx and replaced hardcoded links with intersphinx references. IMO this has a huge benefit of maintaining links consistency: while the hardcoded link is unmanageable (for example, currently the link https://pythonhosted.org/six/#six.with_metaclass points to nowhere since six documentation has moved to https://six.readthedocs.io), the intersphinx refs are checked implicitly - if a ref is dead, Sphinx will emit a warning when building docs1. intersphinx is an extension that is included in Sphinx by default, so no extra dependencies needed.

Another advantage is the referencing simplicity: for example, instead of writing

any string supported by `sys.platform <https://docs.python.org/3/library/sys.html#sys.platform>`_

rendered as
image
you do

any string supported by :py:data:`sys.platform`

rendered as
image

which is IMO a lot less work when typing and has a different style when rendered, pointing out the fact that the link leads to a library documentation.

Also, Sphinx has a :pep: role that generates links to PEP pages, so e.g.

PEP 561 <https://www.python.org/dev/peps/pep-0561/>`__ specifies ...

rendered as
image

becomes

:pep:`561` specifies ...

rendered as

image

1 Of course, there's the linkcheck builder that checks for dead references, but it has to be run explicitly, so it's still beneficial to reduce the amount of hardcoded links to a minimum. Also, linkcheck doesn't check for the link formatting: if one e.g. uses markdown instead of ReST to format the link, this will render wrong, but linkcheck won't complain.

@gvanrossum
Copy link
Member

I think this is a brilliant idea and will review shortly.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I'll just land this.

@gvanrossum gvanrossum merged commit 47dab6a into python:master Oct 4, 2019
@hoefling hoefling deleted the intersphinx branch October 4, 2019 16:45
@gvanrossum
Copy link
Member

@hoefling Is it expected that the mouse-over text for the new links is always "(in Python v3.7)"? This seems a little cryptic, and I'm not sure where it comes from (I suppose this is hardcoded in sphinx interlink?)

@hoefling
Copy link
Contributor Author

hoefling commented Oct 7, 2019

Yes, looks like it's hardcoded in intersphinx code:

https://github.com/sphinx-doc/sphinx/blob/7faeb793e2e16cde4e5759443fb7f84efddcd9ea/sphinx/ext/intersphinx.py#L299-L303

I imagine this can be customized though - a custom extension that walks over document nodes and adapts reftitle to something more meaningful.

Also, thank you for the advices in the other issue - these are golden, especially the hint with no restrictions on the line length in docs! I was concerned with keeping the lines under 99 chars which resulted in lots of unnecessary changes. Knowing that now, I'm sure this will reduce the amount of diffs drastically.

@gvanrossum
Copy link
Member

gvanrossum commented Oct 7, 2019 via email

@hauntsaninja hauntsaninja mentioned this pull request Sep 27, 2020
17 tasks
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.

2 participants