Skip to content

Commit 62dff00

Browse files
[3.13] gh-157517: Don't copy HTML sources and fix sidebar sources links in docs builds (GH-157522) (#157570)
(cherry picked from commit 5601e1e) Co-authored-by: Maciej Olko <maciej.olko@affirm.com>
1 parent 8404e15 commit 62dff00

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

Doc/conf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
# and replace the values accordingly.
7777
# See Doc/tools/extensions/patchlevel.py
7878
version, release = get_version_info()
79+
v = get_header_version_info()
80+
branch = "main" if v.releaselevel == "alpha" else f"{v.major}.{v.minor}"
7981

8082
rst_epilog = f"""
8183
.. |python_version_literal| replace:: ``Python {version}``
@@ -294,6 +296,7 @@
294296
"repository_url": repository_url or None,
295297
"pr_id": os.getenv("READTHEDOCS_VERSION"),
296298
"enable_analytics": os.getenv("PYTHON_DOCS_ENABLE_ANALYTICS"),
299+
"source_branch": branch,
297300
}
298301

299302
# This 'Last updated on:' timestamp is inserted at the bottom of every page.
@@ -303,6 +306,9 @@
303306
# Path to find HTML templates to override theme
304307
templates_path = ['tools/templates']
305308

309+
# We link to sources on GitHub, so don't copy them into the HTML output.
310+
html_copy_source = False
311+
306312
# Custom sidebar templates, filenames relative to this file.
307313
html_sidebars = {
308314
# Defaults taken from https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars
@@ -564,9 +570,6 @@
564570
# Options for sphinx.ext.extlinks
565571
# -------------------------------
566572

567-
v = get_header_version_info()
568-
branch = "main" if v.releaselevel == "alpha" else f"{v.major}.{v.minor}"
569-
570573
# This config is a dictionary of external sites,
571574
# mapping unique short aliases to a base URL and a prefix.
572575
# https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html

Doc/tools/templates/customsourcelink.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
{%- if show_source and has_source and sourcename %}
1+
{%- if page_source_suffix is defined %}
22
<div role="note" aria-label="source link">
33
<h3>{{ _('This page') }}</h3>
44
<ul class="this-page-menu">
55
<li><a href="{{ pathto('bugs') }}">{% trans %}Report a bug{% endtrans %}</a></li>
66
<li>
7-
<a href="https://github.com/python/cpython/blob/main/Doc/{{ sourcename|replace('.rst.txt', '.rst') }}?plain=1"
7+
<a href="https://github.com/python/cpython/blob/{{ source_branch }}/Doc/{{ pagename }}.rst?plain=1"
88
rel="nofollow">{{ _('Show source') }}
99
</a>
1010
</li>
11-
{% if language != "en" %}
11+
{% if language != "en" and source_branch != "main" %}
1212
<li>
13-
<a href="https://github.com/python/python-docs-{{ language }}/blob/{{ version }}/{{ pagename }}.po?plain=1"
13+
<a href="https://github.com/python/python-docs-{{ language | replace('_', '-') | lower }}/blob/{{ source_branch }}/{{ pagename }}.po?plain=1"
1414
rel="nofollow">{{ _('Show translation source') }}</a>
1515
</li>
1616
{% endif %}

0 commit comments

Comments
 (0)