-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat_config.py
executable file
·48 lines (37 loc) · 1.32 KB
/
float_config.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
#!/usr/bin/env python3
import yaml
from snakemake.common import get_container_image
from float_utils import logger
class FloatConfig:
_CONFIG_FILE = 'snakemake-float.yaml'
_REQUIRED_KWARGS = {'work-dir', 'data-volumes'}
_SUPPORTED_KWARGS = _REQUIRED_KWARGS.union({
'job-prefix',
'base-image',
'cpu',
'mem',
'submit-extra'
})
def __init__(self, config_file=_CONFIG_FILE):
self._parameters = {'base-image': get_container_image()}
try:
with open(config_file) as cf:
kwargs = yaml.safe_load(cf)
except OSError:
logger.exception('Cannot open float config file')
raise
except yaml.YAMLError:
logger.exception(f"Cannot load YAML: {self._CONFIG_FILE}")
raise
for kwarg in self._REQUIRED_KWARGS:
if kwarg not in kwargs:
msg = f"{config_file} missing required argument: '{kwarg}'"
logger.error(msg)
raise TypeError(msg)
for kwarg in kwargs:
if kwarg not in self._SUPPORTED_KWARGS:
msg = f"{config_file} has unsupported argument: '{kwarg}'"
logger.warning(msg)
self._parameters.update(kwargs)
def parameters(self):
return self._parameters