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 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 @@ -32,6 +32,7 @@ dynamic = [ "version" ]
3232dependencies = [
3333 " sphinx>=3.4" ,
3434]
35+
3536urls.Code = " https://github.com/python/python-docs-theme"
3637urls.Download = " https://pypi.org/project/python-docs-theme/"
3738urls.Homepage = " https://github.com/python/python-docs-theme/"
You can’t perform that action at this time.
0 commit comments