| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b6a1724 commit 4823212
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ How to release | |||
| 2 | 2 | -------------- | |
| 3 | 3 | ||
| 4 | 4 | - Update ``CHANGELOG.rst`` | |
| 5 | - - Bump version (YYYY.MM) in ``pyproject.toml`` | ||
| 5 | + - Bump version (YYYY.MM) in ``python_docs_theme/__init__.py`` | ||
| 6 | 6 | - Commit | |
| 7 | 7 | - Push to check tests pass on | |
| 8 | 8 | `GitHub Actions <https://github.com/python/python-docs-theme/actions>`__ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | from __future__ import annotations | |
| 4 | 4 | ||
| 5 | 5 | import argparse | |
| 6 | + import ast | ||
| 6 | 7 | import subprocess | |
| 7 | 8 | from pathlib import Path | |
| 8 | 9 | ||
@@ -17,6 +18,8 @@ | |||
| 17 | 18 | ) from ie | |
| 18 | 19 | ||
| 19 | 20 | PROJECT_DIR = Path(__file__).resolve().parent | |
| 21 | + PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml" | ||
| 22 | + INIT_PY = PROJECT_DIR / "python_docs_theme" / "__init__.py" | ||
| 20 | 23 | ||
| 21 | 24 | # Global variables used by pybabel below (paths relative to PROJECT_DIR) | |
| 22 | 25 | DOMAIN = "messages" | |
@@ -29,9 +32,23 @@ | |||
| 29 | 32 | ||
| 30 | 33 | def get_project_info() -> dict: | |
| 31 | 34 | """Retrieve project's info to populate the message catalog template""" | |
| 32 | - with open(Path(PROJECT_DIR / "pyproject.toml"), "rb") as f: | ||
| 33 | - data = tomllib.load(f) | ||
| 34 | - return data["project"] | ||
| 35 | + pyproject_text = PYPROJECT_TOML.read_text(encoding="utf-8") | ||
| 36 | + project_data = tomllib.loads(pyproject_text)["project"] | ||
| 37 | + | ||
| 38 | + # read __version__ from __init__.py | ||
| 39 | + for child in ast.parse(INIT_PY.read_bytes()).body: | ||
| 40 | + if not isinstance(child, ast.Assign): | ||
| 41 | + continue | ||
| 42 | + target = child.targets[0] | ||
| 43 | + if not isinstance(target, ast.Name) or target.id != "__version__": | ||
| 44 | + continue | ||
| 45 | + version_node = child.value | ||
| 46 | + if not isinstance(version_node, ast.Constant): | ||
| 47 | + continue | ||
| 48 | + project_data["version"] = version_node.value | ||
| 49 | + break | ||
| 50 | + | ||
| 51 | + return project_data | ||
| 35 | 52 | ||
| 36 | 53 | ||
| 37 | 54 | def extract_messages() -> None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ requires = [ | |||
| 6 | 6 | ||
| 7 | 7 | [project] | |
| 8 | 8 | name = "python-docs-theme" | |
| 9 | - version = "2024.12" | ||
| 10 | 9 | description = "The Sphinx theme for the CPython docs and related projects" | |
| 11 | 10 | readme = "README.md" | |
| 12 | 11 | license.file = "LICENSE" | |
@@ -28,6 +27,8 @@ classifiers = [ | |||
| 28 | 27 | "Topic :: Documentation", | |
| 29 | 28 | "Topic :: Software Development :: Documentation", | |
| 30 | 29 | ] | |
| 30 | + dynamic = [ "version" ] | ||
| 31 | + | ||
| 31 | 32 | dependencies = [ | |
| 32 | 33 | "sphinx>=3.4", | |
| 33 | 34 | ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,22 @@ | |||
| 1 | 1 | from __future__ import annotations | |
| 2 | 2 | ||
| 3 | 3 | import hashlib | |
| 4 | - import os | ||
| 5 | 4 | from functools import cache | |
| 6 | 5 | from pathlib import Path | |
| 7 | - from typing import Any | ||
| 8 | 6 | ||
| 9 | 7 | import sphinx.application | |
| 10 | 8 | from sphinx.builders.html import StandaloneHTMLBuilder | |
| 11 | 9 | ||
| 12 | - THEME_PATH = Path(__file__).parent.resolve() | ||
| 10 | + TYPE_CHECKING = False | ||
| 11 | + if TYPE_CHECKING: | ||
| 12 | + from typing import Any | ||
| 13 | + | ||
| 14 | + from sphinx.application import Sphinx | ||
| 15 | + from sphinx.util.typing import ExtensionMetadata | ||
| 16 | + | ||
| 17 | + __version__ = "2024.12" | ||
| 18 | + | ||
| 19 | + THEME_PATH = Path(__file__).resolve().parent | ||
| 13 | 20 | ||
| 14 | 21 | ||
| 15 | 22 | @cache | |
@@ -52,15 +59,15 @@ def _html_page_context( | |||
| 52 | 59 | ) | |
| 53 | 60 | ||
| 54 | 61 | ||
| 55 | - def setup(app): | ||
| 62 | + def setup(app: Sphinx) -> ExtensionMetadata: | ||
| 56 | 63 | app.require_sphinx("3.4") | |
| 57 | 64 | ||
| 58 | - current_dir = os.path.abspath(os.path.dirname(__file__)) | ||
| 59 | - app.add_html_theme("python_docs_theme", current_dir) | ||
| 65 | + app.add_html_theme("python_docs_theme", str(THEME_PATH)) | ||
| 60 | 66 | ||
| 61 | 67 | app.connect("html-page-context", _html_page_context) | |
| 62 | 68 | ||
| 63 | 69 | return { | |
| 70 | + "version": __version__, | ||
| 64 | 71 | "parallel_read_safe": True, | |
| 65 | 72 | "parallel_write_safe": True, | |
| 66 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,4 +2,4 @@ | |||
| 2 | 2 | setuptools | |
| 3 | 3 | Babel | |
| 4 | 4 | Jinja2 | |
| 5 | - tomli; python_version < "3.10" | ||
| 5 | + tomli; python_version < "3.11" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments