Skip to content

Commit

Permalink
Fix jazzband#190 DeprecationWarning on import imp
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloxnet committed Oct 27, 2021
1 parent 9f38e87 commit dfc088d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions configurations/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import imp
import importlib.util
import logging
import os
import sys
Expand Down Expand Up @@ -130,21 +130,23 @@ def find_module(self, fullname, path=None):
if fullname is not None and fullname == self.module:
module = fullname.rsplit('.', 1)[-1]
return ConfigurationLoader(self.name,
imp.find_module(module, path))
importlib.util.spec_from_file_location(module, path))
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:
Expand Down

0 comments on commit dfc088d

Please sign in to comment.