Resolve config_file to absolute right at start on parsing args in cli

- Assume path is absolute in yaml util module while saving, loading file
  - This follows same convention as jsonl. Which just operates on
    passed file path, assuming it is of appropriate form.
    Responsibility to put it in appropriate form is on the caller, for now
This commit is contained in:
Debanjum Singh Solanky
2022-08-12 01:34:08 +03:00
parent 44fe70513a
commit fad2f3a2e7
2 changed files with 9 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ from pathlib import Path
import yaml
# Internal Packages
from src.utils.helpers import get_absolute_path
from src.utils.helpers import get_absolute_path, resolve_absolute_path
from src.utils.rawconfig import FullConfig
# Do not emit tags when dumping to YAML
@@ -16,14 +16,14 @@ def save_config_to_file(yaml_config: dict, yaml_config_file: Path):
# Create output directory, if it doesn't exist
yaml_config_file.parent.mkdir(parents=True, exist_ok=True)
with open(get_absolute_path(yaml_config_file), 'w', encoding='utf-8') as config_file:
with open(yaml_config_file, 'w', encoding='utf-8') as config_file:
yaml.safe_dump(yaml_config, config_file, allow_unicode=True)
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:
with open(yaml_config_file, 'r', encoding='utf-8') as config_file:
config_from_file = yaml.safe_load(config_file)
return config_from_file