Skip to content

Commit 58fb66b

Browse files
committed
Fix plugin loading mechanism
1 parent c97f665 commit 58fb66b

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

tableschema/helpers.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
import requests
1313
from copy import deepcopy
14-
from importlib import import_module
14+
from importlib.util import find_spec
1515
from . import exceptions
1616
from . import config
1717

@@ -128,27 +128,10 @@ def register(self):
128128
if self not in sys.meta_path:
129129
sys.meta_path.append(self)
130130

131-
def find_module(self, fullname, path=None):
131+
def find_spec(self, fullname, path=None, target=None):
132132
if fullname.startswith(self.virtual):
133-
return self
133+
# Transform the module name
134+
transformed_name = fullname.replace(self.virtual, self.actual)
135+
return find_spec(transformed_name)
134136
return None
135137

136-
def find_spec(self, fullname, path=None, target=None):
137-
return self.find_module(fullname, path)
138-
139-
def load_module(self, fullname):
140-
if fullname in sys.modules:
141-
return sys.modules[fullname]
142-
if not fullname.startswith(self.virtual):
143-
raise ImportError(fullname)
144-
realname = fullname.replace(self.virtual, self.actual)
145-
try:
146-
module = import_module(realname)
147-
except ImportError:
148-
message = 'Plugin "%s" is not installed. '
149-
message += 'Run "pip install %s" to install.'
150-
message = message % (fullname, realname.replace('_', '-'))
151-
raise ImportError(message)
152-
sys.modules[realname] = module
153-
sys.modules[fullname] = module
154-
return module

0 commit comments

Comments
 (0)