mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-04 21:29:12 +00:00
Rename load_config_from_file to more descriptive parse_config_from_file
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user