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

docs: module page titles should not start with a link to themselves #117099

Merged
merged 1 commit into from
May 8, 2024

Conversation

nedbat
Copy link
Member

@nedbat nedbat commented Mar 20, 2024

The :mod: role used in the title of module pages turns into a link, but the link is to the same page. That's distracting and unhelpful. This uses the ! prefix to instruct Sphinx to not make a link.

This was done with this thrown-together program:

"""
Change every module page in the CPython docs 
so that the title doesn't link to itself.
"""

from pathlib import Path

# Edge cases:
# - modules with a blank line at the top.
# - modules that already had the !-prefix to suppress the link.
# - had to fix the rule length
# - pages that started with a link, but to the main module page.
#       unittest.mock-examples.rst
# - pages with slightly off names:
#       xml.sax.xmlreader is in xml.sax.reader.rst
#       xml.etree.ElementTree is in xml.etree.elementtree.rst
#       xml.parsers.expat is in pyexpat.rst
#       xml.sax.saxutils is in xml.sax.utils.rst
# - pages with two links in the title!
#       copyreg.rst

def fix_one_file(fpath):
    text = fpath.read_text().lstrip()
    if not text.startswith(":mod:`"):
        return
    if text.startswith(":mod:`!"):
        return
    lines = text.splitlines(keepends=True)
    modname = lines[0].split("`")[1]
    if modname != fpath.stem:
        print(f"WUT: {modname=}, {fpath.stem=}")
    lines[0] = lines[0].replace(":mod:`", ":mod:`!")
    lines[1] = lines[1][0] * (len(lines[0]) - 1) + "\n"
    fpath.write_text("".join(lines))
    print(f"Updated {fpath}")

for fname in Path(".").glob("**/*.rst"):
    fix_one_file(fname)

📚 Documentation preview 📚: https://cpython-previews--117099.org.readthedocs.build/

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news labels Mar 20, 2024
@nedbat
Copy link
Member Author

nedbat commented Mar 20, 2024

This is only marked Draft because I didn't want to ping 29 other people for review. Can that be stopped?

@AlexWaygood
Copy link
Member

This is only marked Draft because I didn't want to ping 29 other people for review. Can that be stopped?

I don't know of a way of avoiding that, unfortunately... It's not possible for me to deselect any of the codeowners from the list of people who are going to be requested for review.

@nedbat nedbat force-pushed the nedbat/dont-self-link-module-pages branch from c711468 to 1485c51 Compare March 20, 2024 20:34
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! I agree that these are distracting for readers, and serve no purpose.

While I agree with @CAM-Gerlach's comments on Discord that a Sphinx extension might be a cleaner way of fixing this, I'm personally happy to merge this unless somebody wants to volunteer to actually do that. I think we should prioritise the experience for readers of the docs, and this PR improves the experience of reading the docs.

@nedbat
Copy link
Member Author

nedbat commented Mar 20, 2024

Since I don't want to ping 29 code owners, and am a little bit interested in learning about Sphinx internals, let's wait on this to see how the CAM+Ned tag team manages on tweaking Sphinx.

@nedbat
Copy link
Member Author

nedbat commented May 8, 2024

Everyone: I know this might ping many people. My apologies. The changes were auto-created across all of the module pages.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

How we did not notice this earlier?

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.12 bug and security fixes labels May 8, 2024
@AlexWaygood AlexWaygood merged commit bcb435e into python:main May 8, 2024
32 checks passed
@miss-islington-app
Copy link

Thanks @nedbat for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 8, 2024
…ythonGH-117099)

(cherry picked from commit bcb435e)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 8, 2024
…ythonGH-117099)

(cherry picked from commit bcb435e)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
@bedevere-app
Copy link

bedevere-app bot commented May 8, 2024

GH-118790 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 8, 2024
@bedevere-app
Copy link

bedevere-app bot commented May 8, 2024

GH-118791 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label May 8, 2024
AlexWaygood pushed a commit that referenced this pull request May 8, 2024
…elves (GH-117099) (#118791)

docs: module page titles should not start with a link to themselves (GH-117099)
(cherry picked from commit bcb435e)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
AlexWaygood pushed a commit that referenced this pull request May 8, 2024
…elves (GH-117099) (#118790)

docs: module page titles should not start with a link to themselves (GH-117099)
(cherry picked from commit bcb435e)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
@nedbat nedbat deleted the nedbat/dont-self-link-module-pages branch May 21, 2024 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants