File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 11import subprocess
22import sys
3- import tomllib
43
54def git_version ():
65 version = subprocess .check_output (
@@ -10,10 +9,20 @@ def git_version():
109 return version
1110
1211def pyproject_version ():
13- with open ("pyproject.toml" , "rb" ) as f :
14- pyproject_data = tomllib .load (f )
15- version = pyproject_data ["project" ]["version" ]
16- return version
12+ try :
13+ import tomllib
14+ with open ("pyproject.toml" , "rb" ) as f :
15+ pyproject_data = tomllib .load (f )
16+ version = pyproject_data ["project" ]["version" ]
17+ return version
18+ except ImportError :
19+ # primitive parsing for Python < 3.11
20+ with open ("pyproject.toml" , "r" , encoding = "utf-8" ) as f :
21+ for line in f :
22+ if line .strip ().startswith ("version =" ):
23+ version = line .split ("=" , 1 )[1 ].strip ().strip ('"' ).strip ("'" )
24+ return version
25+ raise RuntimeError ("Could not determine version from pyproject.toml" )
1726
1827if __name__ == "__main__" :
1928 assert git_version () == "v" + pyproject_version (), \
You can’t perform that action at this time.
0 commit comments