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.

131 lines
4.9 KiB

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