mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Extract code to load config from YAML file into new utils.yaml module
This commit is contained in:
@@ -2,12 +2,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from src.utils.helpers import get_absolute_path, resolve_absolute_path
|
from src.utils.helpers import resolve_absolute_path
|
||||||
from src.utils.rawconfig import FullConfig
|
from src.utils.yaml import load_config_from_file
|
||||||
|
|
||||||
|
|
||||||
def cli(args=None):
|
def cli(args=None):
|
||||||
@@ -25,12 +22,6 @@ def cli(args=None):
|
|||||||
if not resolve_absolute_path(args.config_file).exists():
|
if not resolve_absolute_path(args.config_file).exists():
|
||||||
args.config = None
|
args.config = None
|
||||||
else:
|
else:
|
||||||
# Read Config from YML file
|
args.config = load_config_from_file(args.config_file)
|
||||||
config_from_file = None
|
|
||||||
with open(get_absolute_path(args.config_file), 'r', encoding='utf-8') as config_file:
|
|
||||||
config_from_file = yaml.safe_load(config_file)
|
|
||||||
|
|
||||||
# Parse, Validate Config in YML file
|
|
||||||
args.config = FullConfig.parse_obj(config_from_file)
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
15
src/utils/yaml.py
Normal file
15
src/utils/yaml.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# External Packages
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
# Internal Packages
|
||||||
|
from src.utils.helpers import get_absolute_path
|
||||||
|
from src.utils.rawconfig import FullConfig
|
||||||
|
|
||||||
|
def load_config_from_file(yaml_config_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)
|
||||||
|
|
||||||
|
# Parse, Validate Config in YML file
|
||||||
|
return FullConfig.parse_obj(config_from_file)
|
||||||
Reference in New Issue
Block a user