diff --git a/cal_tools/cal_tools/titlepage.tmpl b/cal_tools/cal_tools/titlepage.tmpl index 0b3903af7d288b6abec66412b04ae494d4a62c7e..39c8e8ac6be4647c0df260bd00f77cd5ac4e7381 100644 --- a/cal_tools/cal_tools/titlepage.tmpl +++ b/cal_tools/cal_tools/titlepage.tmpl @@ -14,7 +14,7 @@ Based on data sample: {{ data_path }} - Release : 0.1 + Release : {{ version }} \vspace*{0mm} \today diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index cfea5e7a8b973ac043cfd0fb5db080f55fc3d170..363dd51c8a821b4f9645896887b4772a91ddcb72 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -283,13 +283,14 @@ def make_report(run_path, tmp_path, out_path, project, author, version, rmtree(tmp_path) -def make_titlepage(sphinx_path, project, data_path): +def make_titlepage(sphinx_path, project, data_path, version): """ Create title page for report using template :param sphinx_path: path to sphinx run directory :param project: title of the project :param data_path: path to input data sample used for notebook + :param version: Version of the pycalibration tool """ module_path = "{}".format(path.abspath(path.dirname(__file__))) with open('{}/titlepage.tmpl'.format(module_path)) as file_: @@ -297,7 +298,8 @@ def make_titlepage(sphinx_path, project, data_path): with open("{}/titlepage.tex.txt".format(sphinx_path), "w+") as mf: mf.write(dedent(title_tmp.render(project=project, - data_path=data_path))) + data_path=data_path, + version=version))) def finalize(joblist, finaljob, run_path, out_path, project, calibration, @@ -317,7 +319,7 @@ def finalize(joblist, finaljob, run_path, out_path, project, calibration, prepare_plots(run_path) make_timing_summary(run_path, joblist + [str(finaljob)]) sphinx_path = combine_report(run_path, calibration) - make_titlepage(sphinx_path, project, data_path) + make_titlepage(sphinx_path, project, data_path, version) make_report(sphinx_path, run_path, out_path, project, author, version, report_to) diff --git a/setup.py b/setup.py index 49d494d71b8f1dc3944c60ed0237a6fb5888e76a..391d522db505b3e17d87e34e4e37f335c12f3aee 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ -import glob from setuptools import setup from setuptools.command.install import install -from subprocess import check_call +from subprocess import check_call, check_output +from distutils.command.build import build import sys @@ -23,9 +23,18 @@ class PostInstallCommand(install): else: print("Python environment seems to not be a Karabo environment. "+ "Please install PyDetLib manually.") - - - + + +class PreInstallCommand(build): + """Pre-installation for installation mode.""" + def run(self): + version = check_output(['git', 'describe', '--tag']).decode('utf8') + version = version.replace("\n", "") + file = open('xfel_calibrate/VERSION.py', 'w') + file.write('__version__="{}"'.format(version)) + file.close() + + build.run(self) from xfel_calibrate.notebooks import notebooks @@ -47,6 +56,7 @@ setup( }, cmdclass={ + 'build' : PreInstallCommand, 'install': PostInstallCommand, }, url='', diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py index 259db8c1e19ba02b281912d3fe5f6233b82c4dde..a0bc15a0128f40508baa891a986d00507e496f9b 100755 --- a/xfel_calibrate/calibrate.py +++ b/xfel_calibrate/calibrate.py @@ -130,11 +130,22 @@ def extract_title_author_version(nb): title = title[0] if len(title) else None author = author[0] if len(author) else None - git_dir = '{}/../.git'.format(os.path.dirname(__file__)) - version = check_output(['git', - '--git-dir={}'.format(git_dir), - 'describe', '--tag']).decode('utf8') - version = version.replace("\n", "") + # Try to get version from the git + # Will work only in case of the development installation + # Suppress output errors + # In case of a standard installation a version is stored + # in the _version.py file + try: + git_dir = '{}/../.git'.format(os.path.dirname(__file__)) + FNULL = open(os.devnull, 'w') + version = check_output(['git', + '--git-dir={}'.format(git_dir), + 'describe', '--tag'], + stderr=FNULL).decode('utf8') + version = version.replace("\n", "") + except: + from .VERSION import __version__ + version = __version__ return title, author, version