src.fairreckitlib.core.config.config_yml
This module contains the base functionality for an object's configuration.
Classes:
YmlConfig: base class configuration that is compatible with an yml format.
Functions:
format_yml_config_dict: convert dict of YmlConfig's to an yml format.
format_yml_config_dict_list: convert dict with list of YmlConfig's to an yml format.
format_yml_config_list: convert list of YmlConfig's to an yml format.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)
1"""This module contains the base functionality for an object's configuration. 2 3Classes: 4 5 YmlConfig: base class configuration that is compatible with an yml format. 6 7Functions: 8 9 format_yml_config_dict: convert dict of YmlConfig's to an yml format. 10 format_yml_config_dict_list: convert dict with list of YmlConfig's to an yml format. 11 format_yml_config_list: convert list of YmlConfig's to an yml format. 12 13This program has been developed by students from the bachelor Computer Science at 14Utrecht University within the Software Project course. 15© Copyright Utrecht University (Department of Information and Computing Sciences) 16""" 17 18from abc import ABCMeta, abstractmethod 19from dataclasses import dataclass 20from typing import Any, Dict, List 21 22 23@dataclass 24class YmlConfig(metaclass=ABCMeta): 25 """Base YML Configuration.""" 26 27 @abstractmethod 28 def to_yml_format(self) -> Dict[str, Any]: 29 """Format configuration to a yml compatible dictionary. 30 31 Returns: 32 a dictionary containing the configuration. 33 """ 34 raise NotImplementedError() 35 36 37def format_yml_config_dict(yml_configs: Dict[str, YmlConfig]) -> Dict[str, Any]: 38 """Format yml configuration dictionary. 39 40 Returns: 41 a list containing the yml configuration's. 42 """ 43 yml_format = {} 44 45 for name, config in yml_configs.items(): 46 yml_format[name] = config.to_yml_format() 47 48 return yml_format 49 50 51def format_yml_config_dict_list( 52 yml_config_lists: Dict[str, List[YmlConfig]]) -> Dict[str, List[Dict[str, Any]]]: 53 """Format yml configuration dictionary with list values. 54 55 Returns: 56 a dictionary containing the lists of yml configurations. 57 """ 58 yml_format = {} 59 60 for key_name, list_config in yml_config_lists.items(): 61 yml_format[key_name] = format_yml_config_list(list_config) 62 63 return yml_format 64 65 66def format_yml_config_list(yml_configs: List[YmlConfig]) -> List[Dict[str, Any]]: 67 """Format yml configuration list to a yml compatible list. 68 69 Returns: 70 a list containing the yml configuration's. 71 """ 72 yml_format = [] 73 74 for config in yml_configs: 75 yml_format.append(config.to_yml_format()) 76 77 return yml_format
24@dataclass 25class YmlConfig(metaclass=ABCMeta): 26 """Base YML Configuration.""" 27 28 @abstractmethod 29 def to_yml_format(self) -> Dict[str, Any]: 30 """Format configuration to a yml compatible dictionary. 31 32 Returns: 33 a dictionary containing the configuration. 34 """ 35 raise NotImplementedError()
Base YML Configuration.
28 @abstractmethod 29 def to_yml_format(self) -> Dict[str, Any]: 30 """Format configuration to a yml compatible dictionary. 31 32 Returns: 33 a dictionary containing the configuration. 34 """ 35 raise NotImplementedError()
Format configuration to a yml compatible dictionary.
Returns: a dictionary containing the configuration.
38def format_yml_config_dict(yml_configs: Dict[str, YmlConfig]) -> Dict[str, Any]: 39 """Format yml configuration dictionary. 40 41 Returns: 42 a list containing the yml configuration's. 43 """ 44 yml_format = {} 45 46 for name, config in yml_configs.items(): 47 yml_format[name] = config.to_yml_format() 48 49 return yml_format
Format yml configuration dictionary.
Returns: a list containing the yml configuration's.
52def format_yml_config_dict_list( 53 yml_config_lists: Dict[str, List[YmlConfig]]) -> Dict[str, List[Dict[str, Any]]]: 54 """Format yml configuration dictionary with list values. 55 56 Returns: 57 a dictionary containing the lists of yml configurations. 58 """ 59 yml_format = {} 60 61 for key_name, list_config in yml_config_lists.items(): 62 yml_format[key_name] = format_yml_config_list(list_config) 63 64 return yml_format
Format yml configuration dictionary with list values.
Returns: a dictionary containing the lists of yml configurations.
67def format_yml_config_list(yml_configs: List[YmlConfig]) -> List[Dict[str, Any]]: 68 """Format yml configuration list to a yml compatible list. 69 70 Returns: 71 a list containing the yml configuration's. 72 """ 73 yml_format = [] 74 75 for config in yml_configs: 76 yml_format.append(config.to_yml_format()) 77 78 return yml_format
Format yml configuration list to a yml compatible list.
Returns: a list containing the yml configuration's.