1+ """
2+ Build counter script to increment build number on each build.
3+
4+ We update the __version__ module and the version in pyproject.toml to keep them in sync.
5+ """
6+
17import re
28import subprocess
39from pathlib import Path
410
511from enum import Enum # isort: skip
612
713class VersionStatus (Enum ):
14+ """
15+ Enumeration for version status.
16+ """
817 ALPHA = "alpha"
918 BETA = "beta"
1019 RELEASE = "release"
1120
1221__major_version__ = 0
1322__minor_version__ = 26
14- __revision_version__ = 0
23+ __revision_version__ = 1
1524__author__ = "@joocer"
1625__status__ = VersionStatus .BETA
1726
1827__build__ = None
19- with open ("opteryx/__version__.py" , mode = "r" ) as v :
28+ with open ("opteryx/__version__.py" , mode = "r" , encoding = "utf-8" ) as v :
2029 vers = v .read ()
2130exec (vers ) # nosec
2231
2332if __build__ :
2433 __build__ = int (__build__ ) + 1
25- __version__ = f"{ __major_version__ } .{ __minor_version__ } .{ __revision_version__ } " + f"-{ __status__ .value } .{ __build__ } " if __status__ != VersionStatus .RELEASE else ""
34+ __version__ = f"{ __major_version__ } .{ __minor_version__ } .{ __revision_version__ } "
35+ if __status__ != VersionStatus .RELEASE :
36+ __version__ += f"-{ __status__ .value } .{ __build__ } "
2637
2738 VERSION_FILE_CONTENT = f"""# THIS FILE IS AUTOMATICALLY UPDATED DURING THE BUILD PROCESS
2839# DO NOT EDIT THIS FILE DIRECTLY
@@ -48,14 +59,14 @@ class VersionStatus(Enum):
4859print (__version__ )
4960
5061pyproject_path = Path ("pyproject.toml" )
51- pyproject_contents = pyproject_path .read_text ()
62+ pyproject_contents = pyproject_path .read_text (encoding = "utf-8" )
5263pattern = re .compile (r'^(version\s*=\s*")[^"]*(")' , re .MULTILINE )
5364updated_contents , replacements = pattern .subn (f'version = "{ __version__ } "' , pyproject_contents , count = 1 )
5465
5566if replacements == 0 :
5667 msg = "Unable to locate version field in pyproject.toml"
5768 raise ValueError (msg )
5869
59- pyproject_path .write_text (updated_contents )
70+ pyproject_path .write_text (updated_contents , encoding = "utf-8" )
6071
6172subprocess .run (["git" , "add" , "opteryx/__version__.py" , "pyproject.toml" ])
0 commit comments