-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
73 lines (55 loc) · 1.9 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
def __getattribute__(self, key):
try:
return dict.__getattribute__(self, key)
except:
return AttrDict()
# load the important modules`
import os
__config__ = ['RSDFIT_BIN', 'RSDFIT', 'RSDFIT_FITS', 'RSDFIT_DATA', 'RSDFIT_MODELS', 'RSDFIT_BATCH']
# default values are `None`
for c in __config__:
globals()[c] = None
def _load_from_rc():
"""
Load the configuration variables from a ``rsdfitrc`` file
"""
filename = os.path.join(os.environ['HOME'], '.rsdfit', 'rsdfitrc')
# if the config rc file exists, load values into globals()
if os.path.isfile(filename):
with open(filename) as f:
code = compile(f.read(), filename, 'exec')
exec(code, globals())
def _load_from_env():
"""
Load the configuration variables from the environment
"""
g = globals()
for c in __config__:
if g[c] is None and c in os.environ:
g[c] = os.environ[c]
def _check_missing():
"""
Crash if any of the configuration variables are `None`
"""
g = globals()
missing = []
for c in __config__:
if g[c] is None:
missing.append(c)
if len(missing):
filename = os.path.join(os.environ['HOME'], '.rsdfit', 'rsdfitrc')
msg = "please define the following variables via environment "
msg += "variables or in the file '%s': %s" %(filename, str(missing))
raise ValueError(msg)
# load the config variables
_load_from_rc()
_load_from_env()
_check_missing()
from .theory.base import BaseTheoryParams
from .data import PkmuDataParams, PoleDataParams
from .driver import DriverParams
from .runner import RSDFitRunner