From 7563100bcc4a1517fb0fbd63c69f60a5a96f15bb Mon Sep 17 00:00:00 2001
From: karnem <mikhail.karnevskiy@desy.de>
Date: Fri, 12 Jul 2019 14:29:41 +0200
Subject: [PATCH] take version from git

---
 xfel_calibrate/calibrate.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py
index 9f594817e..3cbeafba4 100755
--- a/xfel_calibrate/calibrate.py
+++ b/xfel_calibrate/calibrate.py
@@ -9,6 +9,7 @@ from nbparameterise import (
     extract_parameters, replace_definitions, parameter_values
 )
 import os
+from os import chdir
 import pprint
 import re
 from subprocess import Popen, PIPE, check_output
@@ -115,18 +116,23 @@ def deconsolize_args(args):
 
 
 def extract_title_author_version(nb):
-    """ Tries to extract title, author and versions from markdown """
+    """ Tries to extract title, author from markdown.
+
+    Version is taken from git.
+    """
 
     first_md = first_markdown_cell(nb)
     source = first_md["source"]
     title = re.findall(r'\#+\s*(.*)\s*\#+', source)
     author = re.findall(
         r'author[\s]*[:][\s]*(.*?)\s*(?:[,?]|version)', source, flags=re.IGNORECASE)
-    version = re.findall(r'version[\s]*:\s*(.*)', source, flags=re.IGNORECASE)
 
     title = title[0] if len(title) else None
     author = author[0] if len(author) else None
-    version = version[0] if len(version) else None
+
+    chdir(os.path.dirname(__file__))
+    version = check_output(["git", 'describe', '--tag']).decode('utf8')
+    version = version.replace("\n", "")
     return title, author, version
 
 
@@ -567,8 +573,6 @@ def run():
         notebook = os.path.abspath(
             "{}/{}".format(os.path.dirname(__file__), notebook))
         concurrency = notebooks[detector][caltype].get("concurrency", None)
-        version = notebooks[detector][caltype].get("version", "NA")
-        author = notebooks[detector][caltype].get("author", "anonymous")
 
     except KeyError:
         print("Not one of the known calibrations or detectors")
-- 
GitLab