/
version.py
73 lines (57 loc) · 1.84 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""PODPAC Version
Attributes
----------
VERSION : OrderedDict
dict of podpac version {('MAJOR': int), ('MINOR': int), ('HOTFIX': int)}
VERSION_INFO : tuple of int
(MAJOR, MINOR, HOTFIX)
"""
import subprocess
import os
from collections import OrderedDict
##############
## UPDATE VERSION HERE
##############
MAJOR = 3
MINOR = 1
HOTFIX = 1
##############
VERSION_INFO = OrderedDict([("MAJOR", MAJOR), ("MINOR", MINOR), ("HOTFIX", HOTFIX)])
VERSION = (VERSION_INFO["MAJOR"], VERSION_INFO["MINOR"], VERSION_INFO["HOTFIX"])
def semver():
"""Return semantic version of current PODPAC installation
Returns
-------
str
Semantic version of the current PODPAC installation
"""
return ".".join([str(v) for v in VERSION])
def version():
"""Retrieve PODPAC semantic version as string
Returns
-------
str
Semantic version if outside git repository
Returns `git describe --always` if inside the git repository
"""
version_full = semver()
CWD = os.path.dirname(__file__)
got_git = os.path.exists(os.path.join(os.path.dirname(__file__), "..", ".git"))
if not got_git:
return version_full
try:
# determine git binary
git = "git"
try:
subprocess.check_output([git, "--version"])
except Exception:
git = "/usr/bin/git"
try:
subprocess.check_output([git, "--version"])
except Exception as e:
return version_full
version_full = subprocess.check_output([git, "describe", "--always", "--tags"], cwd=CWD).strip().decode("ascii")
version_full = version_full.replace("-", "+", 1).replace("-", ".") # Make this consistent with PEP440
except Exception as e:
print("Could not determine PODPAC version from git repo.\n" + str(e))
return version_full