Rename load_config_from_file to more descriptive parse_config_from_file

This commit is contained in:
Debanjum Singh Solanky 2022-08-10 22:28:51 +03:00
parent 328cc00439
commit 62eb66b8ca
2 changed files with 20 additions and 5 deletions

View file

@ -4,7 +4,7 @@ import pathlib
# Internal Packages
from src.utils.helpers import resolve_absolute_path
from src.utils.yaml import load_config_from_file
from src.utils.yaml import parse_config_from_file
def cli(args=None):
@ -22,6 +22,6 @@ def cli(args=None):
if not resolve_absolute_path(args.config_file).exists():
args.config = None
else:
args.config = load_config_from_file(args.config_file)
args.config = parse_config_from_file(args.config_file)
return args

View file

@ -5,11 +5,26 @@ import yaml
from src.utils.helpers import get_absolute_path
from src.utils.rawconfig import FullConfig
def save_config_to_file(yaml_config, yaml_config_file):
"Write config to YML file"
with open(get_absolute_path(yaml_config_file), 'w', encoding='utf-8') as config_file:
yaml.dump(yaml_config, config_file, allow_unicode=True)
def load_config_from_file(yaml_config_file):
# Read Config from YML file
"Read config from YML file"
config_from_file = None
with open(get_absolute_path(yaml_config_file), 'r', encoding='utf-8') as config_file:
config_from_file = yaml.safe_load(config_file)
return config_from_file
# Parse, Validate Config in YML file
return FullConfig.parse_obj(config_from_file)
def parse_config_from_string(yaml_config):
"Parse and validate config in YML string"
return FullConfig.parse_obj(yaml_config)
def parse_config_from_file(yaml_config_file):
"Parse and validate config in YML file"
return parse_config_from_string(load_config_from_file(yaml_config_file))