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.

74 lines
1.9 KiB

2 months ago
  1. import importlib
  2. import os
  3. import re
  4. import sys
  5. def ensure_dir_exists(path):
  6. """
  7. Check whether the directory exists and creates it if not.
  8. """
  9. assert path is not None
  10. try:
  11. os.makedirs(path)
  12. except FileExistsError:
  13. pass
  14. except OSError as exception:
  15. if exception.errno != errno.EEXIST:
  16. raise IOError("Cannot create directory: " + path)
  17. except BaseException:
  18. raise IOError("Path " + path + " seems not valid")
  19. def parse_storm_version(version_string):
  20. """
  21. Parses the version of storm.
  22. :param version_string: String containing version information.
  23. :return: Tuple (version, commit)
  24. """
  25. split = version_string.split('-')
  26. version = split[0]
  27. commit = ""
  28. if len(split) > 1:
  29. commit = split[1]
  30. return version, commit
  31. def obtain_version():
  32. """
  33. Obtains the version as specified in stormpy.
  34. :return: Version
  35. """
  36. verstr = "unknown"
  37. try:
  38. verstrline = open('lib/stormpy/_version.py', "rt").read()
  39. except EnvironmentError:
  40. pass # Okay, there is no version file.
  41. else:
  42. VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
  43. mo = re.search(VSRE, verstrline, re.M)
  44. if mo:
  45. verstr = mo.group(1)
  46. else:
  47. raise RuntimeError("unable to find version in stormpy/_version.py")
  48. return verstr
  49. def load_cmake_config(path):
  50. """
  51. Load cmake config.
  52. :param path: Path.
  53. :return: Configuration.
  54. """
  55. if sys.version_info[1] >= 5:
  56. # Method for Python >= 3.5
  57. spec = importlib.util.spec_from_file_location("genconfig", path)
  58. conf = importlib.util.module_from_spec(spec)
  59. spec.loader.exec_module(conf)
  60. return conf
  61. else:
  62. # Deprecated method for Python <= 3.4
  63. from importlib.machinery import SourceFileLoader
  64. return SourceFileLoader("genconfig", path).load_module()