-
Notifications
You must be signed in to change notification settings - Fork 34
/
version.py
40 lines (38 loc) · 1.35 KB
/
version.py
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
import os
import subprocess
from sys import stdout
try:
with open(os.devnull, "w") as devnull:
v = (
subprocess.check_output(["git", "describe", "--tags", "--dirty", "--abbrev"], stderr=stdout)
.decode()
.strip()
)
if "-" in v:
bv = v[: v.index("-")]
bv = bv[: bv.rindex(".") + 1] + str(int(bv[bv.rindex(".") + 1 :]) + 1)
sempre = "dirty" if v.endswith("-dirty") else "commit"
pippre = "alpha" if v.endswith("-dirty") else "pre"
build = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode().strip()
number_since = (
subprocess.check_output(["git", "rev-list", v[: v.index("-")] + "..HEAD", "--count"]).decode().strip()
)
semver = bv + "-" + sempre + "+" + build
pipver = bv + pippre + number_since
winver = v[: v.index("-")] + "." + number_since
else:
semver = v
pipver = v
winver = v + ".0"
with open("version", "w") as f:
print("Semantic version is " + semver)
f.write(semver)
with open("pip_version", "w") as f:
print("PIP version is " + pipver)
f.write(pipver)
with open("win_version", "w") as f:
print("Windows version is " + winver)
f.write(winver)
except Exception as e:
print("Error calling git")
print(e)