diff --git a/gaip/version.py b/gaip/version.py index d486288..aa4b2ee 100755 --- a/gaip/version.py +++ b/gaip/version.py @@ -19,6 +19,7 @@ from __future__ import absolute_import, print_function import re +import os from os.path import dirname, isdir, join, exists from subprocess import CalledProcessError, check_output @@ -43,23 +44,33 @@ def get_version(): # (eg. "gaip-0.0.0-651-gcf335a9-dirty") cmd = [ 'git', - '--git-dir', git_dir, 'describe', '--tags', '--match', '[0-9]*', '--dirty' ] - try: - git_version = check_output(cmd).decode().strip() - except CalledProcessError: - raise RuntimeError('Unable to get version number from git tags') - components = git_version.split('-') - version = components.pop(0) - - # Any other suffixes imply this is not a release: Append an internal build number - if components: - # .. - version += '+' + '.'.join(components) + with remember_cwd(): + os.chdir(package_dir) + try: + git_version = check_output(cmd).decode().strip() + except CalledProcessError: + raise RuntimeError('Unable to get version number from git tags') + + components = git_version.split('-') + version = components.pop(0) + + # Any other suffixes imply this is not a release: Append an internal build number + if components: + # .. + version += '+' + '.'.join(components) return version +def remember_cwd(): + current_dir = os.getcwd() + try: + yield + finally: + os.chdir(current_dir) + + if __name__ == '__main__': print(get_version()) diff --git a/workflow/nbar.py b/workflow/nbar.py index 78d927c..4c729b6 100755 --- a/workflow/nbar.py +++ b/workflow/nbar.py @@ -1723,7 +1723,6 @@ def run(self): # TODO (a) retrieve software version from git once deployed algorithm = {} algorithm['algorithm_version'] = 2.0 # hardcode for now see TODO (a) - algorithm['software_version'] = gaip.get_version() algorithm['software_repository'] = ('https://github.com/' 'GeoscienceAustralia/' 'ga-neo-landsat-processor.git')