From 061c966072f582a8b86770e0bcde878a0e991ff0 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Fri, 3 Sep 2021 14:56:18 +0200 Subject: [PATCH] [lib.domain] fix mounting domains with environment variable --- halfapi/lib/domain.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index 2a11c31..f68f61b 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -230,19 +230,19 @@ def d_domains(config) -> Dict[str, ModuleType]: dict[str, ModuleType] """ - if os.environ.get('HALFAPI_DOMAIN_NAME') and os.environ.get('HALFAPI_DOMAIN_MODULE', '.routers'): - config['domains'] = { - os.environ.get('HALFAPI_DOMAIN_NAME'): os.environ.get('HALFAPI_DOMAIN_MODULE') - } - if not 'domains' in config: - return {} + domains = {} + + if os.environ.get('HALFAPI_DOMAIN_NAME') and os.environ.get('HALFAPI_DOMAIN_MODULE', '.routers'): + domains[os.environ.get('HALFAPI_DOMAIN_NAME')] = os.environ.get('HALFAPI_DOMAIN_MODULE') + elif 'domains' in config: + domains = dict(config['domains'].items()) try: sys.path.append('.') return { domain: importlib.import_module(''.join((domain, module))) - for domain, module in config['domains'].items() + for domain, module in domains.items() } except ImportError as exc: logger.error('Could not load a domain : %s', exc)