Skip to content

Commit 3628396

Browse files
miss-islingtonm-aciekStanFromIreland
authored
[3.15] gh-157517: Don't copy HTML sources and fix sidebar sources links in docs builds (GH-157522) (#157567)
Co-authored-by: Maciej Olko <maciej.olko@affirm.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 87b459e commit 3628396

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
@@ -78,6 +78,8 @@
7878
# and replace the values accordingly.
7979
# See Doc/tools/extensions/patchlevel.py
8080
version, release = get_version_info()
81+
v = get_header_version_info()
82+
branch = "main" if v.releaselevel == "alpha" else f"{v.major}.{v.minor}"
8183

8284
rst_epilog = f"""
8385
.. |python_version_literal| replace:: ``Python {version}``
@@ -298,6 +300,7 @@
298300
"repository_url": repository_url or None,
299301
"pr_id": os.getenv("READTHEDOCS_VERSION"),
300302
"enable_analytics": os.getenv("PYTHON_DOCS_ENABLE_ANALYTICS"),
303+
"source_branch": branch,
301304
}
302305

303306
# This 'Last updated on:' timestamp is inserted at the bottom of every page.
@@ -307,6 +310,9 @@
307310
# Path to find HTML templates to override theme
308311
templates_path = ['tools/templates']
309312

313+
# We link to sources on GitHub, so don't copy them into the HTML output.
314+
html_copy_source = False
315+
310316
# Custom sidebar templates, filenames relative to this file.
311317
html_sidebars = {
312318
# Defaults taken from https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars
@@ -573,9 +579,6 @@
573579
# Options for sphinx.ext.extlinks
574580
# -------------------------------
575581

576-
v = get_header_version_info()
577-
branch = "main" if v.releaselevel == "alpha" else f"{v.major}.{v.minor}"
578-
579582
# This config is a dictionary of external sites,
580583
# mapping unique short aliases to a base URL and a prefix.
581584
# 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,4 +1,4 @@
1-
{%- if show_source and has_source and sourcename %}
1+
{%- if page_source_suffix is defined %}
22
<script>
33
document.addEventListener('DOMContentLoaded', () => {
44
const title = document.querySelector('meta[property="og:title"]').content;
@@ -19,13 +19,13 @@ <h3>{{ _('This page') }}</h3>
1919
<li><a href="{{ pathto('bugs') }}">{% trans %}Report a bug{% endtrans %}</a></li>
2020
<li><a class="improvepage" href="{{ pathto('improve-page-nojs') }}">{% trans %}Improve this page{% endtrans %}</a></li>
2121
<li>
22-
<a href="https://github.com/python/cpython/blob/main/Doc/{{ pagename }}.rst?plain=1"
22+
<a href="https://github.com/python/cpython/blob/{{ source_branch }}/Doc/{{ pagename }}.rst?plain=1"
2323
rel="nofollow">{{ _('Show source') }}
2424
</a>
2525
</li>
26-
{% if language != "en" %}
26+
{% if language != "en" and source_branch != "main" %}
2727
<li>
28-
<a href="https://github.com/python/python-docs-{{ language }}/blob/{{ version }}/{{ pagename }}.po?plain=1"
28+
<a href="https://github.com/python/python-docs-{{ language | replace('_', '-') | lower }}/blob/{{ source_branch }}/{{ pagename }}.po?plain=1"
2929
rel="nofollow">{{ _('Show translation source') }}</a>
3030
</li>
3131
{% endif %}

0 commit comments

Comments
 (0)