-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
35 lines (26 loc) · 853 Bytes
/
version.py
File metadata and controls
35 lines (26 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Auto-incrementing build version.
Increments the patch number stored in ``version.txt`` on every
``import version`` (i.e. every app start). The file is co-located
with this module.
Attributes:
BUILD: Current integer build number.
VERSION: Semantic-version string in the form ``v0.3.<BUILD>``.
"""
import os
_VERSION_FILE = os.path.join(os.path.dirname(__file__), "version.txt")
def _next_version() -> int:
"""Read the current build number from disk, bump it, and persist.
Returns:
The new (incremented) build number.
"""
try:
with open(_VERSION_FILE) as f:
v = int(f.read().strip())
except (FileNotFoundError, ValueError):
v = 0
v += 1
with open(_VERSION_FILE, "w") as f:
f.write(str(v))
return v
BUILD: int = _next_version()
VERSION: str = f"v0.3.{BUILD}"