Feat: rename get_config

This commit is contained in:
2022-07-19 15:15:06 +02:00
parent 01a0f9db17
commit 8c20ff8e4a
2 changed files with 24 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ Producing then compiling templates
"""
import importlib.util
import os
from pathlib import Path
from bopytex.scheduler import Scheduler
from bopytex import default_config
@@ -51,18 +52,27 @@ def clean_vars_keys(
return new_dict
def get_config(options: dict) -> dict:
""" Look for options["configfile"] to load it with default_config and options """
try:
options["configfile"]
except KeyError:
local_config = {}
def config_from_file(filename: str) -> dict:
if Path(filename).exists():
local_config = vars(load_module(filename))
return clean_vars_keys(local_config)
else:
if Path(options["configfile"]).exists():
local_config = vars(load_module(options["configfile"]))
local_config = clean_vars_keys(local_config)
else:
local_config = {}
return {}
def build_config(options: dict) -> dict:
"""Look for options["configfile"] to load it with default_config and options"""
configfile = ""
try:
configfile = options["configfile"]
except KeyError:
pass
try:
configfile = os.environ["BOPYTEXCONFIG"]
except KeyError:
pass
local_config = config_from_file(configfile)
config = clean_vars_keys(vars(default_config))
config.update(local_config)
@@ -72,7 +82,7 @@ def get_config(options: dict) -> dict:
def main(**options):
config = get_config(options)
config = build_config(options)
orcherstre = orcherstrator(
config, planner=default_config.planner, dispatcher=default_config.dispatcher