From 3fda6ba227a7b6ebdb561b9a9a2bfd5354f0e67f Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Wed, 2 Aug 2017 17:20:48 +0200 Subject: [PATCH] Get stormpy version similar to pycarl --- lib/stormpy/__init__.py | 10 +++++- lib/stormpy/{version.py => _version.py} | 0 setup.py | 47 +++++++++++++++++++------ 3 files changed, 46 insertions(+), 11 deletions(-) rename lib/stormpy/{version.py => _version.py} (100%) diff --git a/lib/stormpy/__init__.py b/lib/stormpy/__init__.py index 17350cd..28634cd 100644 --- a/lib/stormpy/__init__.py +++ b/lib/stormpy/__init__.py @@ -2,12 +2,17 @@ from . import core from .core import * from . import storage from .storage import * -from .version import __version__ from ._config import * from .logic import * from pycarl import Variable # needed for building parametric models +__version__ = "unknown" +try: + from _version import __version__ +except ImportError: + # We're running in a tree that doesn't have a _version.py, so we don't know what our version is. + pass core._set_up("") @@ -57,6 +62,7 @@ def build_parametric_model(program, properties=None): else: raise RuntimeError("Not supported parametric model constructed") + def build_model_from_drn(file): """ Build a model from the explicit DRN representation. @@ -78,6 +84,7 @@ def build_model_from_drn(file): else: raise RuntimeError("Not supported non-parametric model constructed") + def build_parametric_model_from_drn(file): """ Build a parametric model from the explicit DRN representation. @@ -99,6 +106,7 @@ def build_parametric_model_from_drn(file): else: raise RuntimeError("Not supported parametric model constructed") + def perform_bisimulation(model, properties, bisimulation_type): formulae = [prop.raw_formula for prop in properties] if model.supports_parameters: diff --git a/lib/stormpy/version.py b/lib/stormpy/_version.py similarity index 100% rename from lib/stormpy/version.py rename to lib/stormpy/_version.py diff --git a/setup.py b/setup.py index a3c62df..72e2cb5 100755 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ import multiprocessing import sys import subprocess import datetime +import re from setuptools import setup, Extension from setuptools.command.build_ext import build_ext @@ -17,13 +18,41 @@ if sys.version_info[0] == 2: def check_storm_compatible(storm_v_major, storm_v_minor, storm_v_patch): if storm_v_major < 1 or (storm_v_major == 1 and storm_v_minor == 0 and storm_v_patch < 1): - sys.exit('Sorry, Storm version {}.{}.{} is not supported anymore!'.format(storm_v_major, storm_v_minor, storm_v_patch)) + sys.exit('Sorry, Storm version {}.{}.{} is not supported anymore!'.format(storm_v_major, storm_v_minor, + storm_v_patch)) + def parse_storm_version(version_string): + """ + Parses the version of storm. + :param version_string: + :return: Version as three-tuple. + """ elems = version_string.split(".") if len(elems) != 3: sys.exit('Storm version string is ill-formed: "{}"'.format(version_string)) - return int(elems[0]), int(elems[1]), int(elems[2]) + return int(elems[0]), int(elems[1]), int(elems[2]) + + +def obtain_version(): + """ + Obtains the version as specified in stormpy. + :return: Version of stormpy. + """ + verstr = "unknown" + try: + verstrline = open('lib/stormpy/_version.py', "rt").read() + except EnvironmentError: + pass # Okay, there is no version file. + else: + VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]" + mo = re.search(VSRE, verstrline, re.M) + if mo: + verstr = mo.group(1) + else: + raise RuntimeError("unable to find version in stormpy/_version.py") + return verstr + class CMakeExtension(Extension): def __init__(self, name, sourcedir='', subdir=''): @@ -32,7 +61,6 @@ class CMakeExtension(Extension): self.subdir = subdir - class CMakeBuild(build_ext): user_options = build_ext.user_options + [ ('storm-dir=', None, 'Path to storm root (binary) location'), @@ -40,7 +68,6 @@ class CMakeBuild(build_ext): ('debug', None, 'Build in Debug mode'), ] - def extdir(self, extname): return os.path.abspath(os.path.dirname(self.get_ext_fullpath(extname))) @@ -61,7 +88,8 @@ class CMakeBuild(build_ext): if self.storm_dir is not None: cmake_args = ['-Dstorm_DIR=' + self.storm_dir] output = subprocess.check_output(['cmake', os.path.abspath("cmake")] + cmake_args, cwd=build_temp_version) - spec = importlib.util.spec_from_file_location("genconfig", os.path.join(build_temp_version, 'generated/config.py')) + spec = importlib.util.spec_from_file_location("genconfig", + os.path.join(build_temp_version, 'generated/config.py')) self.conf = importlib.util.module_from_spec(spec) spec.loader.exec_module(self.conf) @@ -103,18 +131,18 @@ class CMakeBuild(build_ext): elif ext.name == "info": with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now())) - f.write("storm_version = {}\n".format(self.conf.STORM_VERSION)) + f.write("storm_version = \"{}\"\n".format(self.conf.STORM_VERSION)) f.write("storm_cln_ea = {}\n".format(self.conf.STORM_CLN_EA)) f.write("storm_cln_rf = {}".format(self.conf.STORM_CLN_RF)) elif ext.name == "pars": - with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: + with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now())) f.write("has_storm_pars = {}".format(self.conf.HAVE_STORM_PARS)) if not self.conf.HAVE_STORM_PARS: print("WARNING: storm-pars not found. No support for parametric analysis will be built.") continue elif ext.name == "dft": - with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: + with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now())) f.write("has_storm_dft = {}".format(self.conf.HAVE_STORM_DFT)) if not self.conf.HAVE_STORM_DFT: @@ -122,7 +150,6 @@ class CMakeBuild(build_ext): continue self.build_extension(ext) - def initialize_options(self): build_ext.initialize_options(self) self.storm_dir = None @@ -174,7 +201,7 @@ class PyTest(test): setup( name="stormpy", - version="0.9.1", + version=obtain_version(), author="M. Volk", author_email="matthias.volk@cs.rwth-aachen.de", maintainer="S. Junges",