-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
42 lines (32 loc) · 1.16 KB
/
version.py
File metadata and controls
42 lines (32 loc) · 1.16 KB
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
36
37
38
39
40
41
42
"""Auto-incrementing build version.
In local mode the patch number stored in ``version.txt`` is
incremented on every ``import version`` (i.e. every app start/reload).
In Databricks App mode the committed value is used as-is so the
displayed version reliably reflects the deployed code.
Attributes:
BUILD: Current integer build number.
VERSION: Semantic-version string in the form ``v0.4.<BUILD>``.
"""
import os
_VERSION_FILE = os.path.join(os.path.dirname(__file__), "version.txt")
_IS_APP = bool(os.getenv("DATABRICKS_CLIENT_SECRET"))
def _next_version() -> int:
"""Read the current build number from disk, bump it, and persist.
In Databricks App mode the file is read-only (no increment) so the
version matches the committed value exactly.
Returns:
The current (App mode) or new (local mode) build number.
"""
try:
with open(_VERSION_FILE) as f:
v = int(f.read().strip())
except (FileNotFoundError, ValueError):
v = 0
if _IS_APP:
return v
v += 1
with open(_VERSION_FILE, "w") as f:
f.write(str(v))
return v
BUILD: int = _next_version()
VERSION: str = f"v0.4.{BUILD}"