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.

122 lines
4.2 KiB

  1. from setuptools import setup, find_packages
  2. from setuptools.command.install import install
  3. from setuptools.command.develop import develop
  4. from setuptools.command.egg_info import egg_info
  5. from subprocess import call, STDOUT
  6. import distutils.sysconfig
  7. import os
  8. import os.path
  9. import tempfile
  10. import glob
  11. import shutil
  12. import distutils
  13. import multiprocessing
  14. print(os.getcwd())
  15. PYTHONINC = distutils.sysconfig.get_python_inc()
  16. PYTHONLIB = distutils.sysconfig.get_python_lib(plat_specific=True, standard_lib=True)
  17. PYTHONLIBDIR = distutils.sysconfig.get_config_var("LIBDIR")
  18. PYTHONLIBS = glob.glob(os.path.join(PYTHONLIBDIR, "*.dylib"))
  19. PYTHONLIBS.extend(glob.glob(os.path.join(PYTHONLIBDIR, "*.so")))
  20. PYTHONLIB = PYTHONLIBS[0]
  21. NO_COMPILE_CORES = multiprocessing.cpu_count()
  22. #print(os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)))
  23. #print(PYTHONINC)
  24. #print(PYTHONLIB)
  25. d = "setuppy_build"
  26. PROJECT_PYTHON_DIR = "stormpy"
  27. PROJECT_PYTHON_FILES = os.path.join(os.path.dirname(os.path.realpath(__file__)), PROJECT_PYTHON_DIR)
  28. PROJECT_PYTHON_TMP_DESTINATION = os.path.join(os.path.realpath(d), PROJECT_PYTHON_DIR)
  29. print(d)
  30. if not os.path.exists(d):
  31. os.makedirs(d)
  32. class MyEggInfo(egg_info):
  33. def run(self):
  34. try:
  35. src = PROJECT_PYTHON_FILES
  36. print(src)
  37. dst = PROJECT_PYTHON_TMP_DESTINATION
  38. print(dst)
  39. distutils.dir_util.copy_tree(src, dst)
  40. egg_info.run(self)
  41. except:
  42. print("Exception occurred")
  43. egg_info.run(self)
  44. class MyInstall(install):
  45. user_options = install.user_options + [
  46. ('cmake=', None, 'Additional cmake arguments'),
  47. ('make=', None, 'Additional make arguments'),
  48. ]
  49. def initialize_options(self):
  50. install.initialize_options(self)
  51. self.cmake = ""
  52. self.make = ""
  53. def run(self):
  54. # Call cmake
  55. cmake_args = ["cmake", "-DSTORM_PYTHON=ON", "-DUSE_BOOST_STATIC_LIBRARIES=OFF", "-DPYTHON_LIBRARY="+PYTHONLIB, "-DPYTHON_INCLUDE_DIR="+PYTHONINC]
  56. cmake_args.extend(self.cmake.split())
  57. cmake_args.append(os.path.abspath(os.path.dirname(os.path.realpath(__file__))))
  58. ret = call(cmake_args, cwd=d)
  59. if ret != 0:
  60. raise RuntimeError("Cmake exited with return code {}".format(ret))
  61. # Call make
  62. make_args = ["make", "stormpy", "-j"+str(NO_COMPILE_CORES)]
  63. make_args.extend(self.make.split())
  64. ret = call(make_args, cwd=d)
  65. if ret != 0:
  66. raise RuntimeError("Make exited with return code {}".format(ret))
  67. install.run(self)
  68. class MyDevelop(develop):
  69. user_options = develop.user_options + [
  70. ('cmake=', None, 'Additional cmake arguments'),
  71. ('make=', None, 'Additional make arguments'),
  72. ]
  73. def initialize_options(self):
  74. develop.initialize_options(self)
  75. self.cmake = ""
  76. self.make = ""
  77. def run(self):
  78. # Call cmake
  79. cmake_args = ["cmake", "-DSTORM_PYTHON=ON", "-DUSE_BOOST_STATIC_LIBRARIES=OFF", "-DPYTHON_LIBRARY="+PYTHONLIB, "-DPYTHON_INCLUDE_DIR="+PYTHONINC]
  80. cmake_args.extend(self.cmake.split())
  81. cmake_args.append(os.path.abspath(os.path.dirname(os.path.realpath(__file__))))
  82. ret = call(cmake_args, cwd=d)
  83. if ret != 0:
  84. raise RuntimeError("Cmake exited with return code {}".format(ret))
  85. # Call make
  86. make_args = ["make", "stormpy", "-j"+str(NO_COMPILE_CORES)]
  87. make_args.extend(self.make.split())
  88. ret = call(make_args, cwd=d)
  89. if ret != 0:
  90. raise RuntimeError("Make exited with return code {}".format(ret))
  91. develop.run(self)
  92. setup(cmdclass={'install': MyInstall, 'develop': MyDevelop, 'egg_info': MyEggInfo},
  93. name="stormpy",
  94. version="0.2",
  95. description="Stormpy - Python Bindings for Storm",
  96. package_dir={'':d},
  97. packages=['stormpy', 'stormpy.core', 'stormpy.info', 'stormpy.logic', 'stormpy.expressions'],
  98. package_data={'stormpy.core': ['_core.so'],
  99. 'stormpy.logic': ['_logic.so'],
  100. 'stormpy.info' : ['_info.so'] ,
  101. 'stormpy.expressions' : ['_expressions.so'],
  102. 'stormpy': ['*.so', '*.dylib', '*.a']},
  103. include_package_data=True)