diff --git a/cement/core/foundation.py b/cement/core/foundation.py index bf231768..3459bbfe 100644 --- a/cement/core/foundation.py +++ b/cement/core/foundation.py @@ -18,15 +18,7 @@ from ..ext.ext_argparse import ArgparseController as Controller join = os.path.join -# The `imp` module is deprecated in favor of `importlib` in 3.4, but it -# wasn't introduced until 3.1. Finally, reload is a builtin on Python < 3 -pyver = sys.version_info -if pyver[0] >= 3 and pyver[1] >= 4: # pragma: nocover # noqa - from importlib import reload as reload_module # pragma: nocover # noqa -elif pyver[0] >= 3: # pragma: nocover # noqa - from imp import reload as reload_module # pragma: nocover # noqa -else: # pragma: nocover # noqa - reload_module = reload # pragma: nocover # noqa +from importlib import reload as reload_module LOG = minimal_logger(__name__) diff --git a/cement/ext/ext_plugin.py b/cement/ext/ext_plugin.py index 8029fe95..5bf7af2f 100644 --- a/cement/ext/ext_plugin.py +++ b/cement/ext/ext_plugin.py @@ -4,7 +4,7 @@ Cement plugin extension module. import os import sys -import imp +import importlib import re from ..core import plugin, exc from ..utils.misc import is_true, minimal_logger @@ -82,12 +82,6 @@ class CementPluginHandler(plugin.PluginHandler): exists. """ - - # FIX ME: `imp` is deprecated in Python 3.4 and will be going away - # so we need to update forward compatibility for ``importlib``. - # - # See: https://github.com/datafolklabs/cement/issues/386 - LOG.debug("attempting to load '%s' from '%s'" % (plugin_name, plugin_dir)) @@ -95,16 +89,15 @@ class CementPluginHandler(plugin.PluginHandler): LOG.debug("plugin directory '%s' does not exist." % plugin_dir) return False - try: - f, path, desc = imp.find_module(plugin_name, [plugin_dir]) - except ImportError: + spec = importlib.machinery.PathFinder().find_spec(plugin_name, [plugin_dir]) + if not spec: LOG.debug("plugin '%s' does not exist in '%s'." % (plugin_name, plugin_dir)) return False # We don't catch this because it would make debugging a # nightmare - mod = imp.load_module(plugin_name, f, path, desc) + mod = spec.loader.load_module() if mod and hasattr(mod, 'load'): mod.load(self.app) return True