Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4823212

Browse files
AA-Turnerhugovk
andauthored
Set__version__ in the runtime package (#222)
* Set ``__version__`` in the runtime package* Return the version key in ``setup()``* Add static type annotations to ``setup()``* Fix the Python version for ``tomli``* read ``__version__`` from ``__init__.py``Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parentb6a1724 commit4823212

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

‎CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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>`__

‎babel_runner.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__importannotations
44

55
importargparse
6+
importast
67
importsubprocess
78
frompathlibimportPath
89

@@ -17,6 +18,8 @@
1718
)fromie
1819

1920
PROJECT_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)
2225
DOMAIN="messages"
@@ -29,9 +32,23 @@
2932

3033
defget_project_info()->dict:
3134
"""Retrieve project's info to populate the message catalog template"""
32-
withopen(Path(PROJECT_DIR/"pyproject.toml"),"rb")asf:
33-
data=tomllib.load(f)
34-
returndata["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+
forchildinast.parse(INIT_PY.read_bytes()).body:
40+
ifnotisinstance(child,ast.Assign):
41+
continue
42+
target=child.targets[0]
43+
ifnotisinstance(target,ast.Name)ortarget.id!="__version__":
44+
continue
45+
version_node=child.value
46+
ifnotisinstance(version_node,ast.Constant):
47+
continue
48+
project_data["version"]=version_node.value
49+
break
50+
51+
returnproject_data
3552

3653

3754
defextract_messages()->None:

‎pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ requires = [
66

77
[project]
88
name ="python-docs-theme"
9-
version ="2024.12"
109
description ="The Sphinx theme for the CPython docs and related projects"
1110
readme ="README.md"
1211
license.file ="LICENSE"
@@ -28,6 +27,8 @@ classifiers = [
2827
"Topic :: Documentation",
2928
"Topic :: Software Development :: Documentation",
3029
]
30+
dynamic = ["version" ]
31+
3132
dependencies = [
3233
"sphinx>=3.4",
3334
]

‎python_docs_theme/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
from __future__importannotations
22

33
importhashlib
4-
importos
54
fromfunctoolsimportcache
65
frompathlibimportPath
7-
fromtypingimportAny
86

97
importsphinx.application
108
fromsphinx.builders.htmlimportStandaloneHTMLBuilder
119

12-
THEME_PATH=Path(__file__).parent.resolve()
10+
TYPE_CHECKING=False
11+
ifTYPE_CHECKING:
12+
fromtypingimportAny
13+
14+
fromsphinx.applicationimportSphinx
15+
fromsphinx.util.typingimportExtensionMetadata
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-
defsetup(app):
62+
defsetup(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
}

‎requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
setuptools
33
Babel
44
Jinja2
5-
tomli;python_version<"3.10"
5+
tomli;python_version<"3.11"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp