[Core] Add dynamic versioning based on git tag (#790)

This commit is contained in:
Will 2017-06-17 20:18:08 -04:00 committed by Twentysix
parent 03791b9fbc
commit 80756ba490
2 changed files with 43 additions and 1 deletions

View File

@ -1 +1,37 @@
from core.config import Config
from subprocess import run, PIPE
from collections import namedtuple
__all__ = ["Config", "__version__"]
version_info = namedtuple("VersionInfo", "major minor patch")
BASE_VERSION = version_info(3, 0, 0)
def get_latest_version():
try:
p = run(
"git describe --abbrev=0 --tags".split(),
stdout=PIPE
)
except FileNotFoundError:
# No git
return BASE_VERSION
if p.returncode != 0:
return BASE_VERSION
stdout = p.stdout.strip().decode()
if stdout.startswith("v"):
numbers = stdout[1:].split('.')
args = [0, 0, 0]
for i in range(3):
try:
args[i] = int(numbers[i])
except (IndexError, ValueError):
args[i] = 0
return version_info(*args)
return BASE_VERSION
__version__ = get_latest_version()

View File

@ -0,0 +1,6 @@
import core
def test_version_working():
assert hasattr(core, '__version__')
assert core.__version__ >= (3, 0, 0)