Skip to content

Commit

Permalink
Partially Resolves Issue #386
Browse files Browse the repository at this point in the history
  • Loading branch information
derks committed Jul 12, 2016
1 parent 98b5557 commit d830412
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Features:

Refactoring;

* None
* :issue:`386` - Partially deprecated use of ``imp`` in favor of
``importlib`` on Python >= 3.1

Incompatible:

Expand Down
4 changes: 2 additions & 2 deletions cement/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
VERSION = (2, 9, 1, 'alpha', 0) # pragma: nocover

# global hooks/handlers (DEPRECATED)
__handlers__ = {} # pragma: nocover
__hooks__ = {} # pragma: nocover
__handlers__ = {} # pragma: nocover
__hooks__ = {} # pragma: nocover
3 changes: 0 additions & 3 deletions cement/core/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from ..core import exc, interface, handler
from ..utils.misc import minimal_logger

if sys.version_info[0] >= 3:
from imp import reload # pragma: no cover # noqa

LOG = minimal_logger(__name__)


Expand Down
14 changes: 11 additions & 3 deletions cement/core/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
from ..utils.misc import is_true, minimal_logger
from ..utils import fs

if sys.version_info[0] >= 3:
from imp import reload # pragma: nocover
# 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
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


LOG = minimal_logger(__name__)
if platform.system() == 'Windows':
Expand Down Expand Up @@ -803,7 +811,7 @@ def setup(self):

self._loaded_bootstrap = sys.modules[self._meta.bootstrap]
else:
reload(self._loaded_bootstrap)
reload_module(self._loaded_bootstrap)

for res in self.hook.run('pre_setup', self):
pass
Expand Down
7 changes: 7 additions & 0 deletions cement/ext/ext_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def _load_plugin_from_dir(self, plugin_name, plugin_dir):
exists.
"""

paths = [
os.path.join(plugin_dir, "%s.py" % plugin_name),
os.path.join(plugin_dir, plugin_name, "__init__.py")
Expand All @@ -173,6 +174,12 @@ def _load_plugin_from_dir(self, plugin_name, plugin_dir):
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'):
Expand Down
2 changes: 2 additions & 0 deletions tests/core/backend_tests.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Tests for cement.core.backend."""

from cement.core import backend

0 comments on commit d830412

Please sign in to comment.