diff --git a/ChangeLog b/ChangeLog index 0ae4163a..7dd3be0d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -44,6 +44,7 @@ Features: * :issue:`373` - Switch over to using Flake8 for PEP8 and style compliance * :pr:`375` - Redis cache handler support * :issue:`379` - Support for alternative config file extensions + * :issue:`380` - Support for Cython/Compiled Plugins * :issue:`389` - ConfigObj support for Python 3 Refactoring; diff --git a/cement/core/foundation.py b/cement/core/foundation.py index 5ac32ca4..b71514b4 100644 --- a/cement/core/foundation.py +++ b/cement/core/foundation.py @@ -15,7 +15,7 @@ from ..utils import fs # 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] >= 1: # pragma: nocover # noqa +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 diff --git a/cement/ext/ext_plugin.py b/cement/ext/ext_plugin.py index 90ab2963..f783e443 100644 --- a/cement/ext/ext_plugin.py +++ b/cement/ext/ext_plugin.py @@ -163,33 +163,31 @@ class CementPluginHandler(plugin.CementPluginHandler): """ - paths = [ - os.path.join(plugin_dir, "%s.py" % plugin_name), - os.path.join(plugin_dir, plugin_name, "__init__.py") - ] + # 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 - for path in paths: - LOG.debug("attempting to load '%s' from '%s'" % (plugin_name, - path)) - if os.path.exists(path): - # We don't catch this because it would make debugging a - # nightmare - # - # FIX ME: `imp` is deprecated in Python 3.4 and will be - # going away... need to update forward compatibility for - # ``importlib``. - # - # See: https://github.com/datafolklabs/cement/issues/386 - f, path, desc = imp.find_module(plugin_name, [plugin_dir]) - mod = imp.load_module(plugin_name, f, path, desc) - if mod and hasattr(mod, 'load'): - mod.load(self.app) - return True + LOG.debug("attempting to load '%s' from '%s'" % (plugin_name, + plugin_dir)) - LOG.debug("plugin '%s' does not exist in '%s'." % - (plugin_name, plugin_dir)) + if not os.path.exists(plugin_dir): + LOG.debug("plugin directory '%s' does not exist." % plugin_dir) + return False - return False + try: + f, path, desc = imp.find_module(plugin_name, [plugin_dir]) + except ImportError: + 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) + if mod and hasattr(mod, 'load'): + mod.load(self.app) + return True def _load_plugin_from_bootstrap(self, plugin_name, base_package): """