diff --git a/configurations/importer.py b/configurations/importer.py index e3573f4..499eab6 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -1,4 +1,5 @@ -import imp +import importlib.util +from importlib.machinery import PathFinder import logging import os import sys @@ -126,25 +127,30 @@ def stylize(text): self.name)) self.logger.debug(stylize(message)) - def find_module(self, fullname, path=None): + def find_spec(self, fullname, path=None, target=None): if fullname is not None and fullname == self.module: - module = fullname.rsplit('.', 1)[-1] - return ConfigurationLoader(self.name, - imp.find_module(module, path)) + spec = PathFinder.find_spec(fullname, path) + if spec is not None: + return importlib.machinery.ModuleSpec(spec.name, + ConfigurationLoader(self.name, spec), + origin=spec.origin) return None class ConfigurationLoader: - def __init__(self, name, location): + def __init__(self, name, spec): self.name = name - self.location = location + self.spec = spec def load_module(self, fullname): if fullname in sys.modules: mod = sys.modules[fullname] # pragma: no cover else: - mod = imp.load_module(fullname, *self.location) + mod = importlib.util.module_from_spec(self.spec) + sys.modules[fullname] = mod + self.spec.loader.exec_module(mod) + cls_path = '{0}.{1}'.format(mod.__name__, self.name) try: