Use pkgutil.ImpLoader instead of a custom loader for cubes import redirection
It just works fine (same implementation of load_module method as _CubesLoader
introduced in d404fd8499dd) and is complete w.r.t. PEP 302 (all methods
implemented).
Related to #13001466.
--- a/cubicweb/__init__.py Tue Sep 13 10:16:00 2016 +0200
+++ b/cubicweb/__init__.py Thu Sep 15 21:22:53 2016 +0200
@@ -24,6 +24,7 @@
import logging
import os
import pickle
+import pkgutil
import sys
import warnings
import zlib
@@ -304,18 +305,4 @@
except ImportError:
return None
else:
- return _CubesLoader(modinfo)
-
-
-class _CubesLoader(object):
- """Module loader handling redirection of import of "cubes.<name>"
- to "cubicweb_<name>".
- """
-
- def __init__(self, modinfo):
- self.modinfo = modinfo
-
- def load_module(self, fullname):
- if fullname not in sys.modules: # Otherwise, it's a reload.
- sys.modules[fullname] = imp.load_module(fullname, *self.modinfo)
- return sys.modules[fullname]
+ return pkgutil.ImpLoader(fullname, *modinfo)