Config
Handle config files in Nexus-e.
This module's purpose is to provide an easy access to the variables stored in a config file. The ConfigFile interface declare methods to load and write a dictionary from a given file. The TomlFile class implements this interface for .toml files.
To avoid having to use this dictionary directly, the module provides a Config class that can conveniently parse and be exported to a dictionary. The config variables can then be accessed via the Config class attributes.
The load(), write() and write_default_config_file() functions of this module can be used to handle a Config object with a pre-defined ConfigFile object.
Example
Write a default config file and update a config variable value:
Config
dataclass
Config(
logging: Logging = Logging(),
results: Results = Results(),
data_context: DataContext = DataContext(),
modules: Modules = Modules(),
)
Define the config variables' structure.
To add a new config variable you can add it as an attribute of an existing or a new dataclass that is itself an attribute of this Config class.
Example
Add a new config variable and a new dataclass:
The default value of the config variable is given by the default value of its corresponding dataclass attribute.
data_context
class-attribute
instance-attribute
data_context: DataContext = field(default_factory=DataContext)
parse
parse(**config: dict)
Populate the Config class with an input dictionary.
Source code in src/nexus_e/config.py
Logging
dataclass
Logging(
filename: str = "nexus-e.log",
filemode: str = "w",
format: str = "%(asctime)s %(levelname)s %(message)s",
date_format: str = "%Y-%m-%d %H:%M:%S",
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO",
)
Config section about the logger's parameters.
Results
dataclass
Represents configuration settings for simulation results management.
base_folder
class-attribute
instance-attribute
base_folder: str = 'Results'
The base directory where simulation results are stored.
create_new_simulation_results_folder
class-attribute
instance-attribute
create_new_simulation_results_folder: bool = True
Determines whether a new folder should be created for each simulation's results.
DataContext
dataclass
DataContext(
type: Literal["mysql", "sqlite"] = "mysql",
name: str = "",
host: str = "",
port: str = "",
user: str = "",
password: str = "",
)
Modules
dataclass
Modules(
commons: dict[str, Any] = (
lambda: {"resolution_in_days": 8, "single_electric_node": True}
)(),
playlist_name: str = "end_to_end_test",
)
Represents configuration settings for all modules.
commons
class-attribute
instance-attribute
commons: dict[str, Any] = field(
default_factory=lambda: {
"resolution_in_days": 8,
"single_electric_node": True,
}
)
The extra parameters passed to every Module.
playlist_name
class-attribute
instance-attribute
playlist_name: str = 'end_to_end_test'
The file defining the modules to load and their execution order.
Module
dataclass
Represents a module configuration with its name and its associated parameters.
ConfigFile
ConfigFile(file_path: str)
TomlFile
TomlFile(file_path: str)
Bases: ConfigFile
Implement the ConfigFile interface for .toml files.
Source code in src/nexus_e/config.py
load
load() -> dict