File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 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
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
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 @@ -32,6 +32,7 @@ dynamic = [ "version" ]
32
32
dependencies = [
33
33
" sphinx>=3.4" ,
34
34
]
35
+
35
36
urls.Code = " https://github.com/python/python-docs-theme"
36
37
urls.Download = " https://pypi.org/project/python-docs-theme/"
37
38
urls.Homepage = " https://github.com/python/python-docs-theme/"
You can’t perform that action at this time.
0 commit comments