diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py index 9f594817e62affd8dd124a1a0bc6cb81795c484c..3cbeafba4d472b27c8f0d5c14c69e47aa0cd21a3 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")