# HG changeset patch # User Denis Laxalde # Date 1473967373 -7200 # Node ID f765b1b16a2c8ff3c28165109f670f4ce15ff576 # Parent bc04039acd2eafa98d4ecc64d436130f78f75352 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. diff -r bc04039acd2e -r f765b1b16a2c cubicweb/__init__.py --- 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." - to "cubicweb_". - """ - - 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)