Commit 95d06ea1 authored by Yannick Roehlly's avatar Yannick Roehlly

Use importlib.import_module for dynamic import

parent 941eecb0
......@@ -6,6 +6,7 @@ Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
@author: Yannick Roehlly <yannick.roehlly@oamp.fr>
"""
from importlib import import_module
def complete_parameters(given_parameters, parameter_list):
......@@ -175,9 +176,7 @@ def get_module(name, **kwargs):
module_name = name.split('.')[0]
try:
# TODO Find a better way to do dynamic import
import_string = 'from . import ' + module_name + ' as module'
exec import_string
module = import_module("." + module_name, 'pcigale.sed.modules')
return module.Module(name=name, **kwargs)
except ImportError:
print('Module ' + module_name + ' does not exists!')
......
......@@ -6,6 +6,7 @@ Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
@author: Yannick Roehlly <yannick.roehlly@oamp.fr>
"""
from importlib import import_module
class AnalysisModule(object):
......@@ -152,9 +153,7 @@ def get_module(module_name):
"""
try:
# TODO Find a better way to do dynamic import
import_string = 'from . import ' + module_name + ' as module'
exec import_string
module = import_module('.' + module_name, 'pcigale.stats')
return module.Module()
except ImportError:
print('Module ' + module_name + ' does not exists!')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment