Repository navigation
Expand file tree
/
Copy pathfloat_config.py
More file actions
executable file
·66 lines (53 loc) · 1.76 KB
/
Copy pathfloat_config.py
File metadata and controls
executable file
·66 lines (53 loc) · 1.76 KB
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
#!/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"}
_SUPPORTED_KWARGS = _REQUIRED_KWARGS.union(
{
"job-prefix",
"base-image",
"cpu",
"mem",
"max-cpu-factor",
"max-mem-factor",
"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
def max_cpu_factor(self):
return (
float(self._parameters["max-cpu-factor"])
if "max-cpu-factor" in self._parameters
else 4.0
)
def max_mem_factor(self):
return (
float(self._parameters["max-mem-factor"])
if "max-mem-factor" in self._parameters
else 4.0
)