Feat: rename get_config
This commit is contained in:
parent
01a0f9db17
commit
8c20ff8e4a
@ -6,6 +6,7 @@ Producing then compiling templates
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from bopytex.scheduler import Scheduler
|
from bopytex.scheduler import Scheduler
|
||||||
from bopytex import default_config
|
from bopytex import default_config
|
||||||
@ -51,18 +52,27 @@ def clean_vars_keys(
|
|||||||
return new_dict
|
return new_dict
|
||||||
|
|
||||||
|
|
||||||
def get_config(options: dict) -> dict:
|
def config_from_file(filename: str) -> dict:
|
||||||
""" Look for options["configfile"] to load it with default_config and options """
|
if Path(filename).exists():
|
||||||
try:
|
local_config = vars(load_module(filename))
|
||||||
options["configfile"]
|
return clean_vars_keys(local_config)
|
||||||
except KeyError:
|
|
||||||
local_config = {}
|
|
||||||
else:
|
else:
|
||||||
if Path(options["configfile"]).exists():
|
return {}
|
||||||
local_config = vars(load_module(options["configfile"]))
|
|
||||||
local_config = clean_vars_keys(local_config)
|
|
||||||
else:
|
def build_config(options: dict) -> dict:
|
||||||
local_config = {}
|
"""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 = clean_vars_keys(vars(default_config))
|
||||||
config.update(local_config)
|
config.update(local_config)
|
||||||
@ -72,7 +82,7 @@ def get_config(options: dict) -> dict:
|
|||||||
|
|
||||||
def main(**options):
|
def main(**options):
|
||||||
|
|
||||||
config = get_config(options)
|
config = build_config(options)
|
||||||
|
|
||||||
orcherstre = orcherstrator(
|
orcherstre = orcherstrator(
|
||||||
config, planner=default_config.planner, dispatcher=default_config.dispatcher
|
config, planner=default_config.planner, dispatcher=default_config.dispatcher
|
||||||
|
@ -2,7 +2,7 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from bopytex.planner import fake_planner
|
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.tasks import Task
|
||||||
from bopytex.worker import Dispatcher
|
from bopytex.worker import Dispatcher
|
||||||
from .fakes.workers import fake_worker
|
from .fakes.workers import fake_worker
|
||||||
@ -40,7 +40,7 @@ jinja2 = {
|
|||||||
|
|
||||||
def test_get_config_with_configfile(config_file, tmp_path):
|
def test_get_config_with_configfile(config_file, tmp_path):
|
||||||
os.chdir(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 type(config) == dict
|
||||||
assert set(config.keys()) == {
|
assert set(config.keys()) == {
|
||||||
"generate",
|
"generate",
|
||||||
|
Loading…
Reference in New Issue
Block a user