From 7be97e2b64291ac6fb201f091c046bda5880965a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 2 Feb 2025 16:30:00 +0000 Subject: [PATCH 1/7] Drop Python 3.9 --- .github/workflows/tests.yml | 2 +- README.md | 2 +- pyproject.toml | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ace177ed..90e4b632 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,7 +56,7 @@ jobs: matrix: os: ["ubuntu-latest", "windows-latest"] # Test minimum supported and latest stable from 3.x series - python-version: ["3.9", "3"] + python-version: ["3.10", "3"] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/README.md b/README.md index 24308f77..e46dc66e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Python Docs Sphinx Theme This is the theme for the Python documentation. -It requires Python 3.9 or newer and Sphinx 3.4 or newer. +It requires Python 3.10 or newer and Sphinx 3.4 or newer. Note that when adopting this theme, you're also borrowing an element of the trust and credibility established by the CPython core developers over the diff --git a/pyproject.toml b/pyproject.toml index 1b34d905..d9a99b69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ description = "The Sphinx theme for the CPython docs and related projects" readme = "README.md" license.file = "LICENSE" authors = [ { name = "PyPA", email = "distutils-sig@python.org" } ] -requires-python = ">=3.9" +requires-python = ">=3.10" classifiers = [ "Development Status :: 5 - Production/Stable", "Framework :: Sphinx :: Theme", @@ -20,7 +20,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", From 1d36ee8c67e5d55d128c861f780c35643c652399 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:09:47 +0000 Subject: [PATCH 2/7] Return version key in ``setup()`` --- python_docs_theme/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 295c1c53..3ac29d1b 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -61,6 +61,7 @@ def setup(app): app.connect("html-page-context", _html_page_context) return { + "version": "2024.12", "parallel_read_safe": True, "parallel_write_safe": True, } From 7c199faeeb8268a9c42ef31cfbba199fbcc52799 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:10:50 +0000 Subject: [PATCH 3/7] Require Sphinx 7.2+ --- README.md | 2 +- pyproject.toml | 2 +- python_docs_theme/__init__.py | 50 +------------ python_docs_theme/static/pydoctheme.css | 17 ----- python_docs_theme/static/sidebar.js_t | 95 ------------------------- 5 files changed, 3 insertions(+), 163 deletions(-) delete mode 100644 python_docs_theme/static/sidebar.js_t diff --git a/README.md b/README.md index e46dc66e..889b094c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Python Docs Sphinx Theme This is the theme for the Python documentation. -It requires Python 3.10 or newer and Sphinx 3.4 or newer. +It requires Python 3.10 or newer and Sphinx 7.2 or newer. Note that when adopting this theme, you're also borrowing an element of the trust and credibility established by the CPython core developers over the diff --git a/pyproject.toml b/pyproject.toml index d9a99b69..86244c77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ "Topic :: Software Development :: Documentation", ] dependencies = [ - "sphinx>=3.4", + "sphinx>=7.2", ] urls.Code = "https://github.com/python/python-docs-theme" diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 3ac29d1b..88ee89c2 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -1,65 +1,17 @@ from __future__ import annotations -import hashlib import os -from functools import cache from pathlib import Path -from typing import Any - -import sphinx.application -from sphinx.builders.html import StandaloneHTMLBuilder THEME_PATH = Path(__file__).parent.resolve() -@cache -def _asset_hash(path: str) -> str: - """Append a `?digest=` to an url based on the file content.""" - full_path = THEME_PATH / path.replace("_static/", "static/") - digest = hashlib.sha1(full_path.read_bytes()).hexdigest() - - return f"{path}?digest={digest}" - - -def _add_asset_hashes(static: list[str], add_digest_to: list[str]) -> None: - for asset in add_digest_to: - index = static.index(asset) - static[index].filename = _asset_hash(asset) # type: ignore[attr-defined] - - -def _html_page_context( - app: sphinx.application.Sphinx, - pagename: str, - templatename: str, - context: dict[str, Any], - doctree: Any, -) -> None: - if app.config.html_theme != "python_docs_theme": - return - - assert isinstance(app.builder, StandaloneHTMLBuilder) - - if (4,) <= sphinx.version_info < (7, 1) and "css_files" in context: - if "_static/pydoctheme.css" not in context["css_files"]: - raise ValueError( - "This documentation is not using `pydoctheme.css` as the stylesheet. " - "If you have set `html_style` in your conf.py file, remove it." - ) - - _add_asset_hashes( - context["css_files"], - ["_static/pydoctheme.css"], - ) - - def setup(app): - app.require_sphinx("3.4") + app.require_sphinx("7.2") current_dir = os.path.abspath(os.path.dirname(__file__)) app.add_html_theme("python_docs_theme", current_dir) - app.connect("html-page-context", _html_page_context) - return { "version": "2024.12", "parallel_read_safe": True, diff --git a/python_docs_theme/static/pydoctheme.css b/python_docs_theme/static/pydoctheme.css index 0f6f8d37..73ca6aa6 100644 --- a/python_docs_theme/static/pydoctheme.css +++ b/python_docs_theme/static/pydoctheme.css @@ -191,28 +191,11 @@ div.sphinxsidebar input[type='text'] { } #sidebarbutton { - /* Sphinx 4.x and earlier compat */ - height: 100%; - background-color: #CCCCCC; - margin-left: 0; - color: #444444; - font-size: 1.2em; - cursor: pointer; - padding-top: 1px; - float: right; - display: table; - /* after Sphinx 4.x and earlier is dropped, only the below is needed */ width: 12px; border-radius: 0 5px 5px 0; border-left: none; } -#sidebarbutton span { - /* Sphinx 4.x and earlier compat */ - display: table-cell; - vertical-align: middle; -} - #sidebarbutton:hover { background-color: #AAAAAA; } diff --git a/python_docs_theme/static/sidebar.js_t b/python_docs_theme/static/sidebar.js_t deleted file mode 100644 index a08aa0fd..00000000 --- a/python_docs_theme/static/sidebar.js_t +++ /dev/null @@ -1,95 +0,0 @@ -/* - * sidebar.js - * ~~~~~~~~~~ - * - * This file is functionally identical to "sidebar.js" in Sphinx 5.0. - * When support for Sphinx 4 and earlier is dropped from the theme, - * this file can be removed. - * - * This script makes the Sphinx sidebar collapsible. - * - * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds - * in .sphinxsidebar, after .sphinxsidebarwrapper, the #sidebarbutton - * used to collapse and expand the sidebar. - * - * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden - * and the width of the sidebar and the margin-left of the document - * are decreased. When the sidebar is expanded the opposite happens. - * This script saves a per-browser/per-session cookie used to - * remember the position of the sidebar among the pages. - * Once the browser is closed the cookie is deleted and the position - * reset to the default (expanded). - * - * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. - * :license: BSD, see LICENSE for details. - * - */ - -const initialiseSidebar = () => { - // global elements used by the functions. - const bodyWrapper = document.getElementsByClassName("bodywrapper")[0] - const sidebar = document.getElementsByClassName("sphinxsidebar")[0] - const sidebarWrapper = document.getElementsByClassName("sphinxsidebarwrapper")[0] - - // exit early if the document has no sidebar for some reason - if (typeof sidebar === "undefined") { - return - } - -{# Check if we need to dynamically insert the sidebar button. - # We prefer the ``sphinx_version_tuple`` variable, and if it is undefined we - # know we are running a Sphinx version older than 4.2. - # - # See: https://www.sphinx-doc.org/en/master/development/templating.html#sphinx_version_tuple - #} -{% if sphinx_version_tuple is defined and sphinx_version_tuple[0] >= 5 %} - const sidebarButton = document.getElementById("sidebarbutton") - const sidebarArrow = sidebarButton.querySelector('span') -{% else %} - // create the sidebar button element - const sidebarButton = document.createElement("div") - sidebarButton.id = "sidebarbutton" - // create the sidebar button arrow element - const sidebarArrow = document.createElement("span") - sidebarArrow.innerText = "«" - sidebarButton.appendChild(sidebarArrow) - sidebar.appendChild(sidebarButton) -{% endif %} - - const collapse_sidebar = () => { - bodyWrapper.style.marginLeft = ".8em" - sidebar.style.width = ".8em" - sidebarWrapper.style.display = "none" - sidebarArrow.innerText = "»" - sidebarButton.title = _("Expand sidebar") - window.localStorage.setItem("sidebar", "collapsed") - } - - const expand_sidebar = () => { - bodyWrapper.style.marginLeft = "" - sidebar.style.removeProperty("width") - sidebarWrapper.style.display = "" - sidebarArrow.innerText = "«" - sidebarButton.title = _("Collapse sidebar") - window.localStorage.setItem("sidebar", "expanded") - } - - sidebarButton.addEventListener("click", () => { - (sidebarWrapper.style.display === "none") ? expand_sidebar() : collapse_sidebar() - }) - - const sidebar_state = window.localStorage.getItem("sidebar") - if (sidebar_state === "collapsed") { - collapse_sidebar() - } - else if (sidebar_state === "expanded") { - expand_sidebar() - } -} - -if (document.readyState !== "loading") { - initialiseSidebar() -} -else { - document.addEventListener("DOMContentLoaded", initialiseSidebar) -} From 54c28a598446dfd569786ec35c17de9eeb07bdda Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:12:41 +0000 Subject: [PATCH 4/7] Require Sphinx 7.3+ --- README.md | 2 +- pyproject.toml | 2 +- python_docs_theme/__init__.py | 14 +++++++------ python_docs_theme/theme.conf | 37 ---------------------------------- python_docs_theme/theme.toml | 38 +++++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 45 deletions(-) delete mode 100644 python_docs_theme/theme.conf create mode 100644 python_docs_theme/theme.toml diff --git a/README.md b/README.md index 889b094c..133daa0f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Python Docs Sphinx Theme This is the theme for the Python documentation. -It requires Python 3.10 or newer and Sphinx 7.2 or newer. +It requires Python 3.10 or newer and Sphinx 7.3 or newer. Note that when adopting this theme, you're also borrowing an element of the trust and credibility established by the CPython core developers over the diff --git a/pyproject.toml b/pyproject.toml index 86244c77..00aa2d41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ "Topic :: Software Development :: Documentation", ] dependencies = [ - "sphinx>=7.2", + "sphinx>=7.3", ] urls.Code = "https://github.com/python/python-docs-theme" diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 88ee89c2..3fad2fd3 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -1,16 +1,18 @@ from __future__ import annotations -import os from pathlib import Path +from typing import TYPE_CHECKING -THEME_PATH = Path(__file__).parent.resolve() +if TYPE_CHECKING: + from sphinx.application import Sphinx + from sphinx.util.typing import ExtensionMetadata +THEME_PATH = Path(__file__).resolve().parent -def setup(app): - app.require_sphinx("7.2") - current_dir = os.path.abspath(os.path.dirname(__file__)) - app.add_html_theme("python_docs_theme", current_dir) +def setup(app: Sphinx) -> ExtensionMetadata: + app.require_sphinx("7.3") + app.add_html_theme("python_docs_theme", THEME_PATH) return { "version": "2024.12", diff --git a/python_docs_theme/theme.conf b/python_docs_theme/theme.conf deleted file mode 100644 index 5edf397a..00000000 --- a/python_docs_theme/theme.conf +++ /dev/null @@ -1,37 +0,0 @@ -[theme] -inherit = default -stylesheet = pydoctheme.css -pygments_style = default -pygments_dark_style = monokai - -[options] -bodyfont = -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif -headfont = -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif -footerbgcolor = white -footertextcolor = #555555 -relbarbgcolor = white -relbartextcolor = #666666 -relbarlinkcolor = #444444 -sidebarbgcolor = white -sidebartextcolor = #444444 -sidebarlinkcolor = #444444 -sidebarbtncolor = #cccccc -bgcolor = white -textcolor = #222222 -linkcolor = #0090c0 -visitedlinkcolor = #00608f -headtextcolor = #1a1a1a -headbgcolor = white -headlinkcolor = #aaaaaa -codebgcolor = #eeffcc -codetextcolor = #333333 - -hosted_on = -issues_url = -license_url = -root_name = Python -root_url = https://www.python.org/ -root_icon = py.svg -root_icon_alt_text = Python logo -root_include_title = True -copyright_url = diff --git a/python_docs_theme/theme.toml b/python_docs_theme/theme.toml new file mode 100644 index 00000000..ea5c042e --- /dev/null +++ b/python_docs_theme/theme.toml @@ -0,0 +1,38 @@ +[theme] +inherit = "default" +stylesheets = [ + "pydoctheme.css", +] +pygments_style = { default = "default", dark = "monokai" } + +[options] +bodyfont = "-apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif" +headfont = "-apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif" +footerbgcolor = "white" +footertextcolor = "#555555" +relbarbgcolor = "white" +relbartextcolor = "#666666" +relbarlinkcolor = "#444444" +sidebarbgcolor = "white" +sidebartextcolor = "#444444" +sidebarlinkcolor = "#444444" +sidebarbtncolor = "#cccccc" +bgcolor = "white" +textcolor = "#222222" +linkcolor = "#0090c0" +visitedlinkcolor = "#00608f" +headtextcolor = "#1a1a1a" +headbgcolor = "white" +headlinkcolor = "#aaaaaa" +codebgcolor = "#eeffcc" +codetextcolor = "#333333" + +hosted_on = "" +issues_url = "" +license_url = "" +root_name = "Python" +root_url = "https://www.python.org/" +root_icon = "py.svg" +root_icon_alt_text = "Python logo" +root_include_title = "True" +copyright_url = "" From 044d53aa91507d43da10f4622128b6407f104cec Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:18:14 +0000 Subject: [PATCH 5/7] Move @import to [[theme.stylesheets]] --- python_docs_theme/static/pydoctheme.css | 2 -- python_docs_theme/theme.toml | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/python_docs_theme/static/pydoctheme.css b/python_docs_theme/static/pydoctheme.css index 73ca6aa6..95365b1a 100644 --- a/python_docs_theme/static/pydoctheme.css +++ b/python_docs_theme/static/pydoctheme.css @@ -1,5 +1,3 @@ -@import url('classic.css'); - /* Common colours */ :root { --good-color: rgb(41 100 51); diff --git a/python_docs_theme/theme.toml b/python_docs_theme/theme.toml index ea5c042e..1d3cdbda 100644 --- a/python_docs_theme/theme.toml +++ b/python_docs_theme/theme.toml @@ -1,6 +1,7 @@ [theme] inherit = "default" stylesheets = [ + "classic.css", "pydoctheme.css", ] pygments_style = { default = "default", dark = "monokai" } From dbda1e89922b63bd5dbf7a093a6a663ea0e13b50 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:29:50 +0000 Subject: [PATCH 6/7] `tomllib` is new in Python 3.11, not 3.10 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 18e6c17c..ad829d49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ setuptools Babel Jinja2 -tomli; python_version < "3.10" +tomli; python_version < "3.11" From 427f7c58b4a5e3bb9d04e351d4e5b6184e5ed050 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:43:28 +0000 Subject: [PATCH 7/7] post-merge --- python_docs_theme/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 8472f9d8..c5b5fe79 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -15,7 +15,7 @@ def setup(app: Sphinx) -> ExtensionMetadata: app.require_sphinx("7.3") - app.add_html_theme("python_docs_theme", THEME_PATH) + app.add_html_theme("python_docs_theme", str(THEME_PATH)) return { "version": __version__,