From 928367686ce281d22a5f5dc5e5f1b4ca981169cc Mon Sep 17 00:00:00 2001 From: ver228 Date: Wed, 13 Apr 2016 20:07:40 +0100 Subject: [PATCH] fix trackProvenance if there is no git file --- MWTracker/__init__.py | 18 +----------------- MWTracker/helperFunctions/trackProvenance.py | 15 +++++++++------ MWTracker/version.py | 2 ++ setup.py | 4 +++- 4 files changed, 15 insertions(+), 24 deletions(-) create mode 100755 MWTracker/version.py diff --git a/MWTracker/__init__.py b/MWTracker/__init__.py index 49024191..91e7883b 100755 --- a/MWTracker/__init__.py +++ b/MWTracker/__init__.py @@ -5,20 +5,4 @@ # @author: ajaver # """ -# import os -# import sys - -# curr_script_dir = os.path.dirname(os.path.realpath(__file__)) -# movement_validation_dir = os.path.join(curr_script_dir, '..', '..', 'open-worm-analysis-toolbox') -# movement_validation_dir = os.path.abspath(movement_validation_dir) -# if not os.path.exists(movement_validation_dir): -# raise FileNotFoundError('%s does not exists. Introduce a valid path in the variable movement_validation_dir of the file config_param.py. \ -# The path must point to the openWorm movement_validation repository.' % movement_validation_dir) - - -# sys.path.append(movement_validation_dir) - -# try: -# import open_worm_analysis_toolbox -# except ImportError: -# raise ImportError('No module open_worm_analysis_toolbox in %s\nTake a look into MWTracker __init__ path' % movement_validation_dir) \ No newline at end of file +from .version import __version__ \ No newline at end of file diff --git a/MWTracker/helperFunctions/trackProvenance.py b/MWTracker/helperFunctions/trackProvenance.py index 1528f393..3170827f 100755 --- a/MWTracker/helperFunctions/trackProvenance.py +++ b/MWTracker/helperFunctions/trackProvenance.py @@ -3,19 +3,22 @@ import tables from git import Repo -def getGitVersion(main_package): +def getVersion(main_package): git_file = os.path.join((os.sep).join((main_package.__file__).split(os.sep)[0:-2]), '.git') - assert os.path.exists(git_file) - repo = Repo(git_file) - return repo.commit('HEAD').hexsha + try: + repo = Repo(git_file) + return repo.commit('HEAD').hexsha + except git.exc.NoSuchPathError: + return main_package.__version__ + def getGitCommitHash(): import MWTracker import open_worm_analysis_toolbox - commits_hash = {'MWTracker':getGitVersion(MWTracker), - 'open_worm_analysis_toolbox':getGitVersion(open_worm_analysis_toolbox)} + commits_hash = {'MWTracker':getVersion(MWTracker), + 'open_worm_analysis_toolbox':getVersion(open_worm_analysis_toolbox)} return commits_hash diff --git a/MWTracker/version.py b/MWTracker/version.py new file mode 100755 index 00000000..1f220239 --- /dev/null +++ b/MWTracker/version.py @@ -0,0 +1,2 @@ +# # -*- coding: utf-8 -*- +__version__='0.1a0' \ No newline at end of file diff --git a/setup.py b/setup.py index 33176e12..45e3f95e 100755 --- a/setup.py +++ b/setup.py @@ -2,8 +2,10 @@ from setuptools import setup + +exec(open('MWTracker/version.py').read()) setup(name='MWTracker', - version='1.0', + version=__version__, description='Multiworm Tracker', author='Avelino Javer', author_email='avelino.javer@imperial.ac.uk',