Feat: rename get_config

This commit is contained in:
Bertrand Benjamin 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:
def config_from_file(filename: str) -> dict:
if Path(filename).exists():
local_config = vars(load_module(filename))
return clean_vars_keys(local_config)
else:
return {}
def build_config(options: dict) -> dict:
"""Look for options["configfile"] to load it with default_config and options"""
configfile = ""
try:
options["configfile"]
configfile = options["configfile"]
except KeyError:
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 = {}
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

View File

@ -2,7 +2,7 @@ import os
import pytest
from bopytex.planner import fake_planner
from bopytex.service import get_config, orcherstrator
from bopytex.service import build_config, orcherstrator
from bopytex.tasks import Task
from bopytex.worker import Dispatcher
from .fakes.workers import fake_worker
@ -40,7 +40,7 @@ jinja2 = {
def test_get_config_with_configfile(config_file, tmp_path):
os.chdir(tmp_path)
config = get_config({"from_option": "config", "configfile": str(config_file)})
config = build_config({"from_option": "config", "configfile": str(config_file)})
assert type(config) == dict
assert set(config.keys()) == {
"generate",