[3.14] gh-84232: Fix pydoc docs.python.org link generation (GH-139995) (#143098)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Éric <merwok@netwok.org>
This commit is contained in:
Miss Islington (bot) 2025-12-23 17:26:49 +01:00 committed by GitHub
parent aee8c217bd
commit a007e951ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 396 additions and 8 deletions

View file

@ -140,7 +140,8 @@ doctest:
pydoc-topics: BUILDER = pydoc-topics
pydoc-topics: build
@echo "Building finished; now run this:" \
"cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py"
"cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py" \
"&& cp build/pydoc-topics/module_docs.py ../Lib/pydoc_data/module_docs.py"
.PHONY: gettext
gettext: BUILDER = gettext

View file

@ -109,6 +109,7 @@ class PydocTopicsBuilder(TextBuilder):
def init(self) -> None:
super().init()
self.topics: dict[str, str] = {}
self.module_docs: dict[str, str] = {}
def get_outdated_docs(self) -> str:
# Return a string describing what an update build will build.
@ -130,6 +131,15 @@ def write_documents(self, _docnames: Set[str]) -> None:
continue
doc_labels.setdefault(docname, []).append((topic_label, label_id))
py_domain = env.domains['py']
for module_name, module_info in py_domain.data['modules'].items():
docname = module_info[0]
if docname.startswith('library/'):
doc_file = docname.replace('library/', '')
self.module_docs[module_name] = (
f"{doc_file}#module-{module_name}"
)
for docname, label_ids in status_iterator(
doc_labels.items(),
"building topics... ",
@ -161,6 +171,22 @@ def finish(self) -> None:
"""
self.outdir.joinpath("topics.py").write_text(topics, encoding="utf-8")
module_docs_repr = "\n".join(
f" '{module}': '{doc_file}',"
for module, doc_file in sorted(self.module_docs.items())
)
module_docs = f"""\
# Autogenerated by Sphinx on {asctime()}
# as part of the release process.
module_docs = {{
{module_docs_repr}
}}
"""
self.outdir.joinpath("module_docs.py").write_text(
module_docs, encoding="utf-8"
)
def _display_labels(item: tuple[str, Sequence[tuple[str, str]]]) -> str:
_docname, label_ids = item