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.

127 lines
4.7 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. for ext in self.extensions:
  42. if ext.name == "dft":
  43. if self.have_storm_dft:
  44. self.build_extension(ext)
  45. else:
  46. print("WARNING: storm-dft not found. No support for DFTs will be built.")
  47. else:
  48. self.build_extension(ext)
  49. def initialize_options(self):
  50. build_ext.initialize_options(self)
  51. self.storm_dir = None
  52. def finalize_options(self):
  53. if self.storm_dir is not None:
  54. print('The custom storm directory', self.storm_dir)
  55. build_ext.finalize_options(self)
  56. def build_extension(self, ext):
  57. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  58. print(extdir)
  59. cmake_args = ['-DSTORMPY_LIB_DIR=' + extdir,
  60. '-DPYTHON_EXECUTABLE=' + sys.executable]
  61. cfg = 'Release' # if self.debug else 'Release'
  62. build_args = ['--config', cfg]
  63. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  64. build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)]
  65. if self.storm_dir is not None:
  66. cmake_args += ['-Dstorm_DIR=' + self.storm_dir]
  67. if self.have_storm_dft:
  68. cmake_args += ['-DHAVE_STORM_DFT=ON']
  69. env = os.environ.copy()
  70. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  71. self.distribution.get_version())
  72. if not os.path.exists(self.build_temp):
  73. os.makedirs(self.build_temp)
  74. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  75. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  76. class PyTest(test):
  77. def run_tests(self):
  78. #import here, cause outside the eggs aren't loaded
  79. import pytest
  80. errno = pytest.main(['tests'])
  81. sys.exit(errno)
  82. setup(
  83. name="stormpy",
  84. version="0.9",
  85. author="M. Volk",
  86. author_email="matthias.volk@cs.rwth-aachen.de",
  87. maintainer="S. Junges",
  88. maintainer_email="sebastian.junges@cs.rwth-aachen.de",
  89. url="http://moves.rwth-aachen.de",
  90. description="stormpy - Python Bindings for Storm",
  91. packages=['stormpy', 'stormpy.info', 'stormpy.expressions', 'stormpy.logic', 'stormpy.storage', 'stormpy.utility', 'stormpy.dft'],
  92. package_dir={'': 'lib'},
  93. ext_package='stormpy',
  94. ext_modules=[CMakeExtension('core', subdir=''),
  95. CMakeExtension('info', subdir='info'),
  96. CMakeExtension('expressions', subdir='expressions'),
  97. CMakeExtension('logic', subdir='logic'),
  98. CMakeExtension('storage', subdir='storage'),
  99. CMakeExtension('utility', subdir='utility'),
  100. CMakeExtension('dft', subdir='dft')
  101. ],
  102. cmdclass={'build_ext': CMakeBuild, 'test': PyTest},
  103. zip_safe=False,
  104. install_requires=['pycarl>=1.2.0'],
  105. tests_require=['pytest'],
  106. )