mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Do not emit type tags when dumping config YAML to file
This commit is contained in:
parent
678fb6a3c7
commit
23e06f483d
1 changed files with 9 additions and 4 deletions
|
@ -1,3 +1,6 @@
|
|||
# Standard Packages
|
||||
from pathlib import Path
|
||||
|
||||
# External Packages
|
||||
import yaml
|
||||
|
||||
|
@ -5,14 +8,16 @@ import yaml
|
|||
from src.utils.helpers import get_absolute_path
|
||||
from src.utils.rawconfig import FullConfig
|
||||
|
||||
# Do not emit tags when dumping to YAML
|
||||
yaml.emitter.Emitter.process_tag = lambda self, *args, **kwargs: None
|
||||
|
||||
def save_config_to_file(yaml_config, yaml_config_file):
|
||||
def save_config_to_file(yaml_config: dict, yaml_config_file: Path):
|
||||
"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)
|
||||
yaml.safe_dump(yaml_config, config_file, allow_unicode=True)
|
||||
|
||||
|
||||
def load_config_from_file(yaml_config_file):
|
||||
def load_config_from_file(yaml_config_file: Path) -> dict:
|
||||
"Read config from YML file"
|
||||
config_from_file = None
|
||||
with open(get_absolute_path(yaml_config_file), 'r', encoding='utf-8') as config_file:
|
||||
|
@ -20,7 +25,7 @@ def load_config_from_file(yaml_config_file):
|
|||
return config_from_file
|
||||
|
||||
|
||||
def parse_config_from_string(yaml_config):
|
||||
def parse_config_from_string(yaml_config: dict) -> FullConfig:
|
||||
"Parse and validate config in YML string"
|
||||
return FullConfig.parse_obj(yaml_config)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue