|
@ -3,6 +3,7 @@ import os |
|
|
import sys |
|
|
import sys |
|
|
import subprocess |
|
|
import subprocess |
|
|
import re |
|
|
import re |
|
|
|
|
|
import datetime |
|
|
|
|
|
|
|
|
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 |
|
@ -12,6 +13,9 @@ if sys.version_info[0] == 2: |
|
|
sys.exit('Sorry, Python 2.x is not supported') |
|
|
sys.exit('Sorry, Python 2.x is not supported') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import importlib.util |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=[]) |
|
@ -19,12 +23,18 @@ 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') |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extdir(self, extname): |
|
|
|
|
|
return os.path.abspath(os.path.dirname(self.get_ext_fullpath(extname))) |
|
|
|
|
|
|
|
|
def run(self): |
|
|
def run(self): |
|
|
|
|
|
self.conf = None |
|
|
try: |
|
|
try: |
|
|
_ = subprocess.check_output(['cmake', '--version']) |
|
|
_ = subprocess.check_output(['cmake', '--version']) |
|
|
except OSError: |
|
|
except OSError: |
|
@ -40,28 +50,33 @@ 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) |
|
|
output = output.decode('ascii') |
|
|
|
|
|
match = re.search(r"STORM-DIR: (.*)", output) |
|
|
|
|
|
assert(match) |
|
|
|
|
|
storm_dir = match.group(1) |
|
|
|
|
|
match = re.search(r"HAVE-STORM-DFT: (.*)", output) |
|
|
|
|
|
assert(match) |
|
|
|
|
|
self.have_storm_dft = True if match.group(1) == "TRUE" else False |
|
|
|
|
|
# Set variable in _config.py |
|
|
|
|
|
with open(os.path.join("lib", "stormpy", "dft", "_config.py"), "w") as f: |
|
|
|
|
|
f.write("# Generated from setup.py\n") |
|
|
|
|
|
f.write("has_storm_dft = {}".format(self.have_storm_dft)) |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
print(self.conf.HAVE_STORM_DFT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ext in self.extensions: |
|
|
for ext in self.extensions: |
|
|
if ext.name == "dft": |
|
|
|
|
|
if self.have_storm_dft: |
|
|
|
|
|
self.build_extension(ext) |
|
|
|
|
|
else: |
|
|
|
|
|
|
|
|
if 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_cln_ea = {}\n".format(self.conf.STORM_CLN_EA)) |
|
|
|
|
|
f.write("storm_cln_rf = {}".format(self.conf.STORM_CLN_RF)) |
|
|
|
|
|
elif ext.name == "dft": |
|
|
|
|
|
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: |
|
|
print("WARNING: storm-dft not found. No support for DFTs will be built.") |
|
|
print("WARNING: storm-dft not found. No support for DFTs will be built.") |
|
|
else: |
|
|
|
|
|
|
|
|
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 |
|
@ -72,7 +87,7 @@ class CMakeBuild(build_ext): |
|
|
build_ext.finalize_options(self) |
|
|
build_ext.finalize_options(self) |
|
|
|
|
|
|
|
|
def build_extension(self, ext): |
|
|
def build_extension(self, ext): |
|
|
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) |
|
|
|
|
|
|
|
|
extdir = self.extdir(ext.name) |
|
|
print(extdir) |
|
|
print(extdir) |
|
|
cmake_args = ['-DSTORMPY_LIB_DIR=' + extdir, |
|
|
cmake_args = ['-DSTORMPY_LIB_DIR=' + extdir, |
|
|
'-DPYTHON_EXECUTABLE=' + sys.executable] |
|
|
'-DPYTHON_EXECUTABLE=' + sys.executable] |
|
@ -82,9 +97,9 @@ class CMakeBuild(build_ext): |
|
|
|
|
|
|
|
|
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
|
|
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
|
|
build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)] |
|
|
build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)] |
|
|
if self.storm_dir is not None: |
|
|
|
|
|
cmake_args += ['-Dstorm_DIR=' + self.storm_dir] |
|
|
|
|
|
if self.have_storm_dft: |
|
|
|
|
|
|
|
|
if self.conf.STORM_DIR is not None: |
|
|
|
|
|
cmake_args += ['-Dstorm_DIR=' + self.conf.STORM_DIR] |
|
|
|
|
|
if self.conf.HAVE_STORM_DFT: |
|
|
cmake_args += ['-DHAVE_STORM_DFT=ON'] |
|
|
cmake_args += ['-DHAVE_STORM_DFT=ON'] |
|
|
|
|
|
|
|
|
env = os.environ.copy() |
|
|
env = os.environ.copy() |
|
|