Browse Source

Get stormpy version similar to pycarl

refactoring
Matthias Volk 7 years ago
parent
commit
3fda6ba227
  1. 10
      lib/stormpy/__init__.py
  2. 0
      lib/stormpy/_version.py
  3. 41
      setup.py

10
lib/stormpy/__init__.py

@ -2,12 +2,17 @@ from . import core
from .core import * from .core import *
from . import storage from . import storage
from .storage import * from .storage import *
from .version import __version__
from ._config import * from ._config import *
from .logic import * from .logic import *
from pycarl import Variable # needed for building parametric models 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("") core._set_up("")
@ -57,6 +62,7 @@ def build_parametric_model(program, properties=None):
else: else:
raise RuntimeError("Not supported parametric model constructed") raise RuntimeError("Not supported parametric model constructed")
def build_model_from_drn(file): def build_model_from_drn(file):
""" """
Build a model from the explicit DRN representation. Build a model from the explicit DRN representation.
@ -78,6 +84,7 @@ def build_model_from_drn(file):
else: else:
raise RuntimeError("Not supported non-parametric model constructed") raise RuntimeError("Not supported non-parametric model constructed")
def build_parametric_model_from_drn(file): def build_parametric_model_from_drn(file):
""" """
Build a parametric model from the explicit DRN representation. Build a parametric model from the explicit DRN representation.
@ -99,6 +106,7 @@ def build_parametric_model_from_drn(file):
else: else:
raise RuntimeError("Not supported parametric model constructed") raise RuntimeError("Not supported parametric model constructed")
def perform_bisimulation(model, properties, bisimulation_type): def perform_bisimulation(model, properties, bisimulation_type):
formulae = [prop.raw_formula for prop in properties] formulae = [prop.raw_formula for prop in properties]
if model.supports_parameters: if model.supports_parameters:

0
lib/stormpy/version.py → lib/stormpy/_version.py

41
setup.py

@ -4,6 +4,7 @@ import multiprocessing
import sys import sys
import subprocess import subprocess
import datetime import datetime
import re
from setuptools import setup, Extension from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
@ -17,14 +18,42 @@ if sys.version_info[0] == 2:
def check_storm_compatible(storm_v_major, storm_v_minor, storm_v_patch): 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): 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): def parse_storm_version(version_string):
"""
Parses the version of storm.
:param version_string:
:return: Version as three-tuple.
"""
elems = version_string.split(".") elems = version_string.split(".")
if len(elems) != 3: if len(elems) != 3:
sys.exit('Storm version string is ill-formed: "{}"'.format(version_string)) 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): class CMakeExtension(Extension):
def __init__(self, name, sourcedir='', subdir=''): def __init__(self, name, sourcedir='', subdir=''):
Extension.__init__(self, name, sources=[]) Extension.__init__(self, name, sources=[])
@ -32,7 +61,6 @@ class CMakeExtension(Extension):
self.subdir = subdir self.subdir = subdir
class CMakeBuild(build_ext): class CMakeBuild(build_ext):
user_options = build_ext.user_options + [ user_options = build_ext.user_options + [
('storm-dir=', None, 'Path to storm root (binary) location'), ('storm-dir=', None, 'Path to storm root (binary) location'),
@ -40,7 +68,6 @@ class CMakeBuild(build_ext):
('debug', None, 'Build in Debug mode'), ('debug', None, 'Build in Debug mode'),
] ]
def extdir(self, extname): def extdir(self, extname):
return os.path.abspath(os.path.dirname(self.get_ext_fullpath(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: if self.storm_dir is not None:
cmake_args = ['-Dstorm_DIR=' + self.storm_dir] cmake_args = ['-Dstorm_DIR=' + self.storm_dir]
output = subprocess.check_output(['cmake', os.path.abspath("cmake")] + cmake_args, cwd=build_temp_version) 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) self.conf = importlib.util.module_from_spec(spec)
spec.loader.exec_module(self.conf) spec.loader.exec_module(self.conf)
@ -103,7 +131,7 @@ class CMakeBuild(build_ext):
elif ext.name == "info": elif ext.name == "info":
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("# 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_ea = {}\n".format(self.conf.STORM_CLN_EA))
f.write("storm_cln_rf = {}".format(self.conf.STORM_CLN_RF)) f.write("storm_cln_rf = {}".format(self.conf.STORM_CLN_RF))
elif ext.name == "pars": elif ext.name == "pars":
@ -122,7 +150,6 @@ class CMakeBuild(build_ext):
continue continue
self.build_extension(ext) self.build_extension(ext)
def initialize_options(self): def initialize_options(self):
build_ext.initialize_options(self) build_ext.initialize_options(self)
self.storm_dir = None self.storm_dir = None
@ -174,7 +201,7 @@ class PyTest(test):
setup( setup(
name="stormpy", name="stormpy",
version="0.9.1",
version=obtain_version(),
author="M. Volk", author="M. Volk",
author_email="matthias.volk@cs.rwth-aachen.de", author_email="matthias.volk@cs.rwth-aachen.de",
maintainer="S. Junges", maintainer="S. Junges",

Loading…
Cancel
Save