diff options
author | Rasmus Andersson <rasmus@notion.se> | 2018-09-04 00:19:38 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2018-09-04 00:19:38 +0300 |
commit | fa601adc318a268e124080f5f798a8a462c1ccb1 (patch) | |
tree | 379db4a785b23314e94e23e17440cd9e12463f15 /misc/tools/common.py | |
parent | c66641b76b03dc228b46d01949aadf0959606ed3 (diff) | |
download | inter-fa601adc318a268e124080f5f798a8a462c1ccb1.tar.xz |
minor tooling refactor
Diffstat (limited to 'misc/tools/common.py')
-rw-r--r-- | misc/tools/common.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/misc/tools/common.py b/misc/tools/common.py new file mode 100644 index 000000000..c38ef817b --- /dev/null +++ b/misc/tools/common.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +from __future__ import print_function +import sys, os +from os.path import dirname, abspath, join as pjoin +import subprocess + +# patch PYTHONPATH to include $BASEDIR/build/venv/python/site-packages +BASEDIR = abspath(pjoin(dirname(__file__), os.pardir, os.pardir)) +VENVDIR = pjoin(BASEDIR, 'build', 'venv') +sys.path.append(pjoin(VENVDIR, 'lib', 'python', 'site-packages')) + + +_gitHash = None +def getGitHash(): + global _gitHash + if _gitHash is None: + _gitHash = '' + try: + _gitHash = subprocess.check_output( + ['git', '-C', BASEDIR, 'rev-parse', '--short', 'HEAD'], + shell=False + ).strip() + except: + pass + return _gitHash + + +_version = None +def getVersion(): + global _version + if _version is None: + with open(pjoin(BASEDIR, 'version.txt'), 'r') as f: + _version = f.read().strip() + return _version + + +# update environment to include $VENVDIR/bin +os.environ['PATH'] = os.path.join(VENVDIR, 'bin') + ':' + os.environ['PATH'] |