1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-09-18 04:22:21 +00:00

New versioning

Use git to automatically fetch the version
This commit is contained in:
J. Fernando Sánchez
2017-02-17 16:13:11 +01:00
parent 7eaf303124
commit 3cea7534ef
5 changed files with 39 additions and 8 deletions

View File

@@ -1 +0,0 @@
0.7.2-dev1

View File

@@ -1,4 +1,34 @@
import os
import subprocess
import logging
with open(os.path.join(os.path.dirname(__file__), 'VERSION')) as f:
__version__ = f.read().strip()
logger = logging.getLogger(__name__)
ROOT = os.path.dirname(__file__)
DEFAULT_FILE = os.path.join(ROOT, 'VERSION')
def git_version():
try:
res = subprocess.check_output(['git', 'describe',
'--tags', '--dirty']).decode('utf-8')
return res.strip()
except subprocess.CalledProcessError:
return None
def read_version(versionfile=DEFAULT_FILE):
with open(versionfile) as f:
return f.read().strip()
def write_version(version, versionfile=DEFAULT_FILE):
version = version or git_version()
if not version:
raise ValueError('You need to provide a valid version')
with open(versionfile, 'w') as f:
f.write(version)
__version__ = git_version() or read_version()
write_version(__version__)