node_deployer.config
Config
Bases: SimpleNamespace
Source code in src/node_deployer/config.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 | class Config(SimpleNamespace):
def __init__(self, config_label: ConfigLabel, **kwargs) -> None:
"""Initialises the configuration object
Args:
config_label (ConfigLabel): The configuration to initialise with
**kwargs: Additional keyword arguments to become attributes
"""
self.__dict__.update(self.get_config(config_label))
self.update_config()
_kwargs = {
"CLIENT": CLIENT,
"MAX_PORT": MAX_PORT,
"PROJECT_ROOT": PROJECT_ROOT,
}
_kwargs.update(kwargs)
super().__init__(**_kwargs)
@staticmethod
def get_config(config_label: ConfigLabel = "default") -> dict:
"""Gets the specified configuration from config.toml
Args:
config_label (ConfigLabel, optional):
The label of the configuration to get.
Defaults to "default".
Returns:
dict: The specified configuration
"""
if isinstance(config_label, str):
config_label = [config_label]
with open(PROJECT_ROOT / "config.toml", "rb") as f:
configs: dict = tomllib.load(f)
out_config: dict = {}
for c in config_label:
out_config.update(configs[c])
return out_config
def finalise_config(self, config: dict) -> None:
"""Finalises the configuration by converting paths to Path objects and
appropriately setting secondary parameters such as relative paths
Args:
config (dict): The configuration to finalise
"""
# First, convert base paths to Path objects
for k, v in config.items():
match k:
case "SRC_DIR" | "BUILD_DIR":
config[k] = Path(PROJECT_ROOT / v).absolute()
case "CWD_MOUNTDIR":
config[k] = Path(v)
# Then, get required paths from config or globals if not present
build_dir = Path(config.get("BUILD_DIR", self.BUILD_DIR)).absolute()
cwd_mountdir = Path(config.get("CWD_MOUNTDIR", self.CWD_MOUNTDIR))
src_dir = Path(config.get("SRC_DIR", self.SRC_DIR)).absolute()
# Finally, construct the secondary parameters
config["FUELIGNITION_BUILD_DIR"] = build_dir / config.get(
"FUELIGNITION_BUILD_DIR", self.FUELIGNITION_BUILD_DIR
)
config["DOCKERFILE_DIR"] = src_dir / config.get("DOCKERFILE_DIR", self.DOCKERFILE_DIR)
# I really wish docker-py had typeshed stubs
config["CWD_MOUNT"] = docker.types.Mount( # type: ignore
target=str(cwd_mountdir),
source=str(PROJECT_ROOT),
type="bind",
)
def apply_config(self, config: dict) -> None:
"""Applies the specified configuration to this object's attributes
Args:
config (dict): The configuration to apply
"""
self.finalise_config(config)
self.__dict__.update(config)
def update_config(self, config_label: ConfigLabel = "default") -> None:
"""Updates the configuration to the specified configuration
Args:
config_label (ConfigLabel, optional):
The label of the configuration to update to.
Defaults to "default".
"""
self.apply_config(self.get_config(config_label))
|
__init__(config_label, **kwargs)
Initialises the configuration object
Parameters:
| Name |
Type |
Description |
Default |
config_label |
ConfigLabel
|
The configuration to initialise with
|
required
|
**kwargs |
|
Additional keyword arguments to become attributes
|
{}
|
Source code in src/node_deployer/config.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 | def __init__(self, config_label: ConfigLabel, **kwargs) -> None:
"""Initialises the configuration object
Args:
config_label (ConfigLabel): The configuration to initialise with
**kwargs: Additional keyword arguments to become attributes
"""
self.__dict__.update(self.get_config(config_label))
self.update_config()
_kwargs = {
"CLIENT": CLIENT,
"MAX_PORT": MAX_PORT,
"PROJECT_ROOT": PROJECT_ROOT,
}
_kwargs.update(kwargs)
super().__init__(**_kwargs)
|
apply_config(config)
Applies the specified configuration to this object's attributes
Parameters:
| Name |
Type |
Description |
Default |
config |
dict
|
The configuration to apply
|
required
|
Source code in src/node_deployer/config.py
| def apply_config(self, config: dict) -> None:
"""Applies the specified configuration to this object's attributes
Args:
config (dict): The configuration to apply
"""
self.finalise_config(config)
self.__dict__.update(config)
|
finalise_config(config)
Finalises the configuration by converting paths to Path objects and
appropriately setting secondary parameters such as relative paths
Parameters:
| Name |
Type |
Description |
Default |
config |
dict
|
The configuration to finalise
|
required
|
Source code in src/node_deployer/config.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 | def finalise_config(self, config: dict) -> None:
"""Finalises the configuration by converting paths to Path objects and
appropriately setting secondary parameters such as relative paths
Args:
config (dict): The configuration to finalise
"""
# First, convert base paths to Path objects
for k, v in config.items():
match k:
case "SRC_DIR" | "BUILD_DIR":
config[k] = Path(PROJECT_ROOT / v).absolute()
case "CWD_MOUNTDIR":
config[k] = Path(v)
# Then, get required paths from config or globals if not present
build_dir = Path(config.get("BUILD_DIR", self.BUILD_DIR)).absolute()
cwd_mountdir = Path(config.get("CWD_MOUNTDIR", self.CWD_MOUNTDIR))
src_dir = Path(config.get("SRC_DIR", self.SRC_DIR)).absolute()
# Finally, construct the secondary parameters
config["FUELIGNITION_BUILD_DIR"] = build_dir / config.get(
"FUELIGNITION_BUILD_DIR", self.FUELIGNITION_BUILD_DIR
)
config["DOCKERFILE_DIR"] = src_dir / config.get("DOCKERFILE_DIR", self.DOCKERFILE_DIR)
# I really wish docker-py had typeshed stubs
config["CWD_MOUNT"] = docker.types.Mount( # type: ignore
target=str(cwd_mountdir),
source=str(PROJECT_ROOT),
type="bind",
)
|
get_config(config_label='default')
staticmethod
Gets the specified configuration from config.toml
Parameters:
| Name |
Type |
Description |
Default |
config_label |
ConfigLabel
|
The label of the configuration to get.
Defaults to "default".
|
'default'
|
Returns:
| Name | Type |
Description |
dict |
dict
|
The specified configuration
|
Source code in src/node_deployer/config.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 | @staticmethod
def get_config(config_label: ConfigLabel = "default") -> dict:
"""Gets the specified configuration from config.toml
Args:
config_label (ConfigLabel, optional):
The label of the configuration to get.
Defaults to "default".
Returns:
dict: The specified configuration
"""
if isinstance(config_label, str):
config_label = [config_label]
with open(PROJECT_ROOT / "config.toml", "rb") as f:
configs: dict = tomllib.load(f)
out_config: dict = {}
for c in config_label:
out_config.update(configs[c])
return out_config
|
update_config(config_label='default')
Updates the configuration to the specified configuration
Parameters:
| Name |
Type |
Description |
Default |
config_label |
ConfigLabel
|
The label of the configuration to update to.
Defaults to "default".
|
'default'
|
Source code in src/node_deployer/config.py
102
103
104
105
106
107
108
109
110 | def update_config(self, config_label: ConfigLabel = "default") -> None:
"""Updates the configuration to the specified configuration
Args:
config_label (ConfigLabel, optional):
The label of the configuration to update to.
Defaults to "default".
"""
self.apply_config(self.get_config(config_label))
|
Last update:
November 7, 2023
Created:
November 7, 2023