File tree Expand file tree Collapse file tree 5 files changed +37
-12
lines changed Expand file tree Collapse file tree 5 files changed +37
-12
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ How to release
22--------------
33
44- Update ``CHANGELOG.rst ``
5- - Bump version (YYYY.MM) in ``pyproject.toml ``
5+ - Bump version (YYYY.MM) in ``python_docs_theme/__init__.py ``
66- Commit
77- Push to check tests pass on
88 `GitHub Actions <https://github.com/python/python-docs-theme/actions >`__
Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55import argparse
6+ import ast
67import subprocess
78from pathlib import Path
89
1718 ) from ie
1819
1920PROJECT_DIR = Path (__file__ ).resolve ().parent
21+ PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml"
22+ INIT_PY = PROJECT_DIR / "python_docs_theme" / "__init__.py"
2023
2124# Global variables used by pybabel below (paths relative to PROJECT_DIR)
2225DOMAIN = "messages"
2932
3033def get_project_info () -> dict :
3134 """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
3552
3653
3754def extract_messages () -> None :
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ requires = [
66
77[project ]
88name = " python-docs-theme"
9- version = " 2024.12"
109description = " The Sphinx theme for the CPython docs and related projects"
1110readme = " README.md"
1211license.file = " LICENSE"
@@ -28,6 +27,8 @@ classifiers = [
2827 " Topic :: Documentation" ,
2928 " Topic :: Software Development :: Documentation" ,
3029]
30+ dynamic = [ " version" ]
31+
3132dependencies = [
3233 " sphinx>=3.4" ,
3334]
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import hashlib
4- import os
54from functools import cache
65from pathlib import Path
7- from typing import Any
86
97import sphinx .application
108from sphinx .builders .html import StandaloneHTMLBuilder
119
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
1320
1421
1522@cache
@@ -52,15 +59,15 @@ def _html_page_context(
5259 )
5360
5461
55- def setup (app ) :
62+ def setup (app : Sphinx ) -> ExtensionMetadata :
5663 app .require_sphinx ("3.4" )
5764
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 ))
6066
6167 app .connect ("html-page-context" , _html_page_context )
6268
6369 return {
70+ "version" : __version__ ,
6471 "parallel_read_safe" : True ,
6572 "parallel_write_safe" : True ,
6673 }
Original file line number Diff line number Diff line change 22setuptools
33Babel
44Jinja2
5- tomli ; python_version < "3.10 "
5+ tomli ; python_version < "3.11 "
You can’t perform that action at this time.
0 commit comments