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.

97 lines
3.5 KiB

  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import subprocess
  5. from setuptools import setup, Extension
  6. from setuptools.command.build_ext import build_ext
  7. from setuptools.command.test import test
  8. if sys.version_info[0] == 2:
  9. sys.exit('Sorry, Python 2.x is not supported')
  10. class CMakeExtension(Extension):
  11. def __init__(self, name, sourcedir='', subdir=''):
  12. Extension.__init__(self, name, sources=[])
  13. self.sourcedir = os.path.abspath(sourcedir)
  14. self.subdir = subdir
  15. class CMakeBuild(build_ext):
  16. user_options = build_ext.user_options + [
  17. ('storm-dir=', None, 'Path to storm root (binary) location')
  18. ]
  19. def run(self):
  20. try:
  21. _ = subprocess.check_output(['cmake', '--version'])
  22. except OSError:
  23. raise RuntimeError("CMake must be installed to build the following extensions: " +
  24. ", ".join(e.name for e in self.extensions))
  25. for ext in self.extensions:
  26. self.build_extension(ext)
  27. def initialize_options(self):
  28. build_ext.initialize_options(self)
  29. self.storm_dir = None
  30. def finalize_options(self):
  31. if self.storm_dir is not None:
  32. print('The custom storm directory', self.storm_dir)
  33. build_ext.finalize_options(self)
  34. def build_extension(self, ext):
  35. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  36. print(extdir)
  37. cmake_args = ['-DSTORMPY_LIB_DIR=' + extdir,
  38. '-DPYTHON_EXECUTABLE=' + sys.executable]
  39. cfg = 'Release' # if self.debug else 'Release'
  40. build_args = ['--config', cfg]
  41. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  42. build_args += ['--', '-j{}'.format(os.cpu_count() if os.cpu_count() is not None else 2)]
  43. if self.storm_dir is not None:
  44. cmake_args += ['-Dstorm_DIR=' + self.storm_dir]
  45. env = os.environ.copy()
  46. env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
  47. self.distribution.get_version())
  48. if not os.path.exists(self.build_temp):
  49. os.makedirs(self.build_temp)
  50. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
  51. subprocess.check_call(['cmake', '--build', '.', '--target', ext.name] + build_args, cwd=self.build_temp)
  52. class PyTest(test):
  53. def run_tests(self):
  54. #import here, cause outside the eggs aren't loaded
  55. import pytest
  56. errno = pytest.main(['tests'])
  57. sys.exit(errno)
  58. setup(
  59. name="stormpy",
  60. version="0.9",
  61. author="M. Volk",
  62. author_email="matthias.volk@cs.rwth-aachen.de",
  63. maintainer="S. Junges",
  64. maintainer_email="sebastian.junges@cs.rwth-aachen.de",
  65. url="http://moves.rwth-aachen.de",
  66. description="stormpy - Python Bindings for Storm",
  67. packages=['stormpy', 'stormpy.info', 'stormpy.expressions', 'stormpy.logic', 'stormpy.storage', 'stormpy.utility'],
  68. package_dir={'': 'lib'},
  69. ext_package='stormpy',
  70. ext_modules=[CMakeExtension('core', subdir=''),
  71. CMakeExtension('info', subdir='info'),
  72. CMakeExtension('expressions', subdir='expressions'),
  73. CMakeExtension('logic', subdir='logic'),
  74. CMakeExtension('storage', subdir='storage'),
  75. CMakeExtension('utility', subdir='utility')
  76. ],
  77. cmdclass=dict(build_ext=CMakeBuild, test=PyTest),
  78. zip_safe=False,
  79. tests_require=['pytest'],
  80. )