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.

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