You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.4 KiB

8 years ago
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import subprocess
  5. import re
  6. import datetime
  7. from setuptools import setup, Extension
  8. from setuptools.command.build_ext import build_ext
  9. from setuptools.command.test import test
  10. if sys.version_info[0] == 2:
  11. sys.exit('Sorry, Python 2.x is not supported')
  12. import importlib.util
  13. class CMakeExtension(Extension):
  14. def __init__(self, name, sourcedir='', subdir=''):
  15. Extension.__init__(self, name, sources=[])
  16. self.sourcedir = os.path.abspath(sourcedir)
  17. self.subdir = subdir
  18. class CMakeBuild(build_ext):
  19. user_options = build_ext.user_options + [
  20. ('storm-dir=', None, 'Path to storm root (binary) location')
  21. ]
  22. def extdir(self, extname):
  23. return os.path.abspath(os.path.dirname(self.get_ext_fullpath(extname)))
  24. def run(self):
  25. self.conf = None
  26. try:
  27. _ = subprocess.check_output(['cmake', '--version'])
  28. except OSError:
  29. raise RuntimeError("CMake must be installed to build the following extensions: " +
  30. ", ".join(e.name for e in self.extensions))
  31. build_temp_version = self.build_temp + "-version"
  32. if not os.path.exists(build_temp_version):
  33. os.makedirs(build_temp_version)
  34. # Check cmake variable values
  35. cmake_args = []
  36. if self.storm_dir is not None:
  37. cmake_args = ['-Dstorm_DIR=' + self.storm_dir]
  38. output = subprocess.check_output(['cmake', os.path.abspath("cmake")] + cmake_args, cwd=build_temp_version)
  39. spec = importlib.util.spec_from_file_location("genconfig", os.path.join(build_temp_version, 'generated/config.py'))
  40. self.conf = importlib.util.module_from_spec(spec)
  41. spec.loader.exec_module(self.conf)
  42. print(self.conf.HAVE_STORM_DFT)
  43. for ext in self.extensions:
  44. if ext.name == "info":
  45. with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f:
  46. f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now()))
  47. f.write("storm_cln_ea = {}\n".format(self.conf.STORM_CLN_EA))
  48. f.write("storm_cln_rf = {}".format(self.conf.STORM_CLN_RF))
  49. elif ext.name == "dft":
  50. with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f:
  51. f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now()))
  52. f.write("has_storm_dft = {}".format(self.conf.HAVE_STORM_DFT))
  53. if not self.conf.HAVE_STORM_DFT:
  54. print("WARNING: storm-dft not found. No support for DFTs will be built.")
  55. continue
  56. self.build_extension(ext)
  57. def initialize_options(self):
  58. build_ext.initialize_options(self)
  59. self.storm_dir = None
  60. def finalize_options(self):
  61. if self.storm_dir is not None:
  62. print('The custom storm directory', self.storm_dir)
  63. build_ext.finalize_options(self)
  64. def build_extension(self, ext):
  65. extdir = self.extdir(ext.name)
  66. print(extdir)
  67. cmake_args = ['-DSTORMPY_LIB_DIR=' + extdir,
  68. '-DPYTHON_EXECUTABLE=' + sys.executable]
  69. cfg = 'Release' # if self.debug else 'Release'
  70. build_args = ['--config', cfg]
  71. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  72. build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)]
  73. if self.conf.STORM_DIR is not None:
  74. cmake_args += ['-Dstorm_DIR=' + self.conf.STORM_DIR]
  75. if self.conf.HAVE_STORM_DFT:
  76. cmake_args += ['-DHAVE_STORM_DFT=ON']
  77. env = os.environ.copy()
  78. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  79. self.distribution.get_version())
  80. if not os.path.exists(self.build_temp):
  81. os.makedirs(self.build_temp)
  82. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  83. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  84. class PyTest(test):
  85. def run_tests(self):
  86. #import here, cause outside the eggs aren't loaded
  87. import pytest
  88. errno = pytest.main(['tests'])
  89. sys.exit(errno)
  90. setup(
  91. name="stormpy",
  92. version="0.9",
  93. author="M. Volk",
  94. author_email="matthias.volk@cs.rwth-aachen.de",
  95. maintainer="S. Junges",
  96. maintainer_email="sebastian.junges@cs.rwth-aachen.de",
  97. url="http://moves.rwth-aachen.de",
  98. description="stormpy - Python Bindings for Storm",
  99. packages=['stormpy', 'stormpy.info', 'stormpy.expressions', 'stormpy.logic', 'stormpy.storage', 'stormpy.utility', 'stormpy.dft'],
  100. package_dir={'': 'lib'},
  101. ext_package='stormpy',
  102. ext_modules=[CMakeExtension('core', subdir=''),
  103. CMakeExtension('info', subdir='info'),
  104. CMakeExtension('expressions', subdir='expressions'),
  105. CMakeExtension('logic', subdir='logic'),
  106. CMakeExtension('storage', subdir='storage'),
  107. CMakeExtension('utility', subdir='utility'),
  108. CMakeExtension('dft', subdir='dft')
  109. ],
  110. cmdclass={'build_ext': CMakeBuild, 'test': PyTest},
  111. zip_safe=False,
  112. install_requires=['pycarl>=1.2.0'],
  113. tests_require=['pytest'],
  114. )