# HG changeset patch # User Ludovic Chabant # Date 1509416590 25200 # Node ID e7ca3c577305b1626efb08db59a91bff6546f6a2 # Parent 7fe1151595bf701c3dfd63d47edd0b26275d1236 fix: Compatibility for Python 3.4. diff -r 7fe1151595bf -r e7ca3c577305 piecrust/plugins/base.py --- a/piecrust/plugins/base.py Mon Oct 30 18:58:28 2017 -0700 +++ b/piecrust/plugins/base.py Mon Oct 30 19:23:10 2017 -0700 @@ -2,7 +2,6 @@ import sys import logging import importlib -import importlib.util logger = logging.getLogger(__name__) @@ -135,11 +134,20 @@ # Import as a loose Python file from the plugins dir. pfile = os.path.join(self.app.plugins_dir, plugin_name + '.py') if os.path.isfile(pfile): - spec = importlib.util.spec_from_file_location(plugin_name, - pfile) - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - sys.modules[mod_name] = mod + if sys.version_info[1] >= 5: + # Python 3.5+ + from importlib.util import (spec_from_file_location, + module_from_spec) + spec = spec_from_file_location(plugin_name, pfile) + mod = module_from_spec(spec) + spec.loader.exec_module(mod) + sys.modules[mod_name] = mod + else: + # Python 3.4, 3.3. + from importlib.machinery import SourceFileLoader + mod = SourceFileLoader( + plugin_name, pfile).load_module() + sys.modules[mod_name] = mod if mod is None: logger.error("Failed to load plugin '%s'." % plugin_name)