Matthias Volk
7 years ago
5 changed files with 280 additions and 114 deletions
-
2setup.cfg
-
227setup.py
-
1setup/__init__.py
-
90setup/config.py
-
74setup/helper.py
@ -0,0 +1 @@ |
|||
# Intentionally left empty |
@ -0,0 +1,90 @@ |
|||
import configparser |
|||
import os |
|||
import multiprocessing |
|||
|
|||
|
|||
class SetupConfig: |
|||
""" |
|||
Configuration for setup. |
|||
""" |
|||
|
|||
def __init__(self): |
|||
""" |
|||
Create config with default values |
|||
""" |
|||
self.config = configparser.ConfigParser() |
|||
self.config["build_ext"] = self._default_values() |
|||
|
|||
@staticmethod |
|||
def _default_values(): |
|||
""" |
|||
Return default values for config. |
|||
|
|||
:return: Dict with default values for build settings. |
|||
""" |
|||
try: |
|||
no_jobs = multiprocessing.cpu_count() if multiprocessing.cpu_count() is not None else 1 |
|||
except NotImplementedError: |
|||
no_jobs = 1 |
|||
return { |
|||
"storm_dir": "", |
|||
"disable_dft": False, |
|||
"disable_pars": False, |
|||
"debug": False, |
|||
"jobs": str(no_jobs), |
|||
} |
|||
|
|||
def load_from_file(self, path): |
|||
""" |
|||
Load config from file. |
|||
:param path Path to config file. |
|||
""" |
|||
if os.path.isfile(path): |
|||
self.config.read(path) |
|||
if not self.config.has_section("build_ext"): |
|||
self.config["build_ext"] = self._default_values() |
|||
|
|||
def write_config(self, path): |
|||
""" |
|||
Save config with build settings. |
|||
:param path Path to config file. |
|||
""" |
|||
with open(path, 'w') as configfile: |
|||
self.config.write(configfile) |
|||
|
|||
def get_as_bool(self, name): |
|||
""" |
|||
Get the boolean value for option name. |
|||
:param name: Name of option. |
|||
|
|||
:return Value as bool. |
|||
""" |
|||
return self.config.getboolean("build_ext", name) |
|||
|
|||
def get_as_int(self, name): |
|||
""" |
|||
Get the int value for option name. |
|||
:param name: Name of option. |
|||
|
|||
:return Value as integer. |
|||
""" |
|||
return self.config.getint("build_ext", name) |
|||
|
|||
def get_as_string(self, name): |
|||
""" |
|||
Get the string value for option name. |
|||
:param name: Name of option. |
|||
|
|||
:return Value as string. |
|||
""" |
|||
return self.config.get("build_ext", name) |
|||
|
|||
def update(self, name, value): |
|||
""" |
|||
Update name with given value if value is not None. |
|||
:param name: Name of option. |
|||
:param value: New value or None |
|||
""" |
|||
if value is not None: |
|||
assert self.config.has_option("build_ext", name) |
|||
self.config.set("build_ext", name, str(value)) |
@ -0,0 +1,74 @@ |
|||
import importlib |
|||
import os |
|||
import re |
|||
import sys |
|||
|
|||
|
|||
def ensure_dir_exists(path): |
|||
""" |
|||
Check whether the directory exists and creates it if not. |
|||
""" |
|||
assert path is not None |
|||
try: |
|||
os.makedirs(path) |
|||
except FileExistsError: |
|||
pass |
|||
except OSError as exception: |
|||
if exception.errno != errno.EEXIST: |
|||
raise IOError("Cannot create directory: " + path) |
|||
except BaseException: |
|||
raise IOError("Path " + path + " seems not valid") |
|||
|
|||
|
|||
def parse_storm_version(version_string): |
|||
""" |
|||
Parses the version of storm. |
|||
|
|||
:param version_string: String containing version information. |
|||
:return: Tuple (version, commit) |
|||
""" |
|||
split = version_string.split('-') |
|||
version = split[0] |
|||
commit = "" |
|||
if len(split) > 1: |
|||
commit = split[1] |
|||
return version, commit |
|||
|
|||
|
|||
def obtain_version(): |
|||
""" |
|||
Obtains the version as specified in stormpy. |
|||
|
|||
:return: Version |
|||
""" |
|||
verstr = "unknown" |
|||
try: |
|||
verstrline = open('lib/stormpy/_version.py', "rt").read() |
|||
except EnvironmentError: |
|||
pass # Okay, there is no version file. |
|||
else: |
|||
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]" |
|||
mo = re.search(VSRE, verstrline, re.M) |
|||
if mo: |
|||
verstr = mo.group(1) |
|||
else: |
|||
raise RuntimeError("unable to find version in stormpy/_version.py") |
|||
return verstr |
|||
|
|||
|
|||
def load_cmake_config(path): |
|||
""" |
|||
Load cmake config. |
|||
:param path: Path. |
|||
:return: Configuration. |
|||
""" |
|||
if sys.version_info[1] >= 5: |
|||
# Method for Python >= 3.5 |
|||
spec = importlib.util.spec_from_file_location("genconfig", path) |
|||
conf = importlib.util.module_from_spec(spec) |
|||
spec.loader.exec_module(conf) |
|||
return conf |
|||
else: |
|||
# Deprecated method for Python <= 3.4 |
|||
from importlib.machinery import SourceFileLoader |
|||
return SourceFileLoader("genconfig", path).load_module() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue