From e691e935ebcea25b5478b98f93f1857f6505e660 Mon Sep 17 00:00:00 2001
From: Matthew Pitkin <matthew.pitkin@ligo.org>
Date: Wed, 10 Oct 2018 16:48:51 +0100
Subject: [PATCH] Apply Gregs patch

---
 bilby/__init__.py   |  2 +-
 bilby/core/utils.py | 16 +++++++++++-----
 setup.py            |  8 +-------
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/bilby/__init__.py b/bilby/__init__.py
index e6c17560e..57073bbee 100644
--- a/bilby/__init__.py
+++ b/bilby/__init__.py
@@ -24,4 +24,4 @@ from .core import utils, likelihood, prior, result, sampler
 from .core.sampler import run_sampler
 from .core.likelihood import Likelihood
 
-__version__ = '0.3.1'
+__version__ = utils.get_version_information()
diff --git a/bilby/core/utils.py b/bilby/core/utils.py
index bf88828d9..020c63138 100644
--- a/bilby/core/utils.py
+++ b/bilby/core/utils.py
@@ -348,15 +348,21 @@ def setup_logger(outdir=None, label=None, log_level='INFO', print_version=False)
     for handler in logger.handlers:
         handler.setLevel(level)
 
-    version_file = os.path.join(
-        os.path.dirname(os.path.dirname(__file__)), '.version')
-    with open(version_file, 'r') as f:
-        version = f.readline().rstrip()
-
     if print_version:
+        version = get_version_information()
         logger.info('Running bilby version: {}'.format(version))
 
 
+def get_version_information():
+    version_file = os.path.join(
+        os.path.dirname(os.path.dirname(__file__)), '.version')
+    try:
+        with open(version_file, 'r') as f:
+            return f.readline().rstrip()
+    except: # noqa
+        return "No version information"
+
+
 def get_progress_bar(module='tqdm'):
     """
     TODO: Write proper docstring
diff --git a/setup.py b/setup.py
index e8c23c6eb..48307212e 100644
--- a/setup.py
+++ b/setup.py
@@ -58,13 +58,7 @@ def readfile(filename):
     return filecontents
 
 
-VERSION_REGEX = re.compile(r"__version__ = \'(.*?)\'")
-CONTENTS = readfile(os.path.join(
-    os.path.dirname(os.path.abspath(__file__)),
-    "bilby", "__init__.py"))
-VERSION = VERSION_REGEX.findall(CONTENTS)[0]
-
-
+VERSION = '0.3.1'
 version_file = write_version_file(VERSION)
 long_description = get_long_description()
 
-- 
GitLab