diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-08-17 19:21:19 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-08-17 19:21:19 -0400 |
commit | 681ee8131c1997e5ad5c72a39268c6793c6b1180 (patch) | |
tree | cb00b11e8293502fcd15597a48e4843a7217fe21 | |
parent | 14d2a90db984c1a0360727c4d9b8337a689fccec (diff) | |
parent | 07e538d58978e29556c77e1e7bccb18c6d0af60b (diff) | |
download | rneovim-681ee8131c1997e5ad5c72a39268c6793c6b1180.tar.gz rneovim-681ee8131c1997e5ad5c72a39268c6793c6b1180.tar.bz2 rneovim-681ee8131c1997e5ad5c72a39268c6793c6b1180.zip |
Merge pull request #2910 from blueyed/python-fix-path_hook
Python: fixes for sys.path_hooks handler
-rw-r--r-- | runtime/autoload/provider/script_host.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/runtime/autoload/provider/script_host.py b/runtime/autoload/provider/script_host.py index 0a7eb53a0e..96d70e0330 100644 --- a/runtime/autoload/provider/script_host.py +++ b/runtime/autoload/provider/script_host.py @@ -17,6 +17,9 @@ IS_PYTHON3 = sys.version_info >= (3, 0) if IS_PYTHON3: basestring = str + if sys.version_info >= (3, 4): + from importlib.machinery import PathFinder + @neovim.plugin class ScriptHost(object): @@ -190,31 +193,35 @@ def path_hook(nvim): name = oldtail[:idx] tail = oldtail[idx+1:] fmr = imp.find_module(name, path) - module = imp.load_module(fullname[:-len(oldtail)] + name, *fmr) + module = imp.find_module(fullname[:-len(oldtail)] + name, *fmr) return _find_module(fullname, tail, module.__path__) else: - fmr = imp.find_module(fullname, path) - return imp.load_module(fullname, *fmr) + return imp.find_module(fullname, path) class VimModuleLoader(object): def __init__(self, module): self.module = module def load_module(self, fullname, path=None): - return self.module + # Check sys.modules, required for reload (see PEP302). + if fullname in sys.modules: + return sys.modules[fullname] + return imp.load_module(fullname, *self.module) class VimPathFinder(object): - @classmethod - def find_module(cls, fullname, path=None): + @staticmethod + def find_module(fullname, path=None): + "Method for Python 2.7 and 3.3." try: return VimModuleLoader( _find_module(fullname, fullname, path or _get_paths())) except ImportError: return None - @classmethod - def load_module(cls, fullname, path=None): - return _find_module(fullname, fullname, path or _get_paths()) + @staticmethod + def find_spec(fullname, path=None, target=None): + "Method for Python 3.4+." + return PathFinder.find_spec(fullname, path or _get_paths(), target) def hook(path): if path == nvim.VIM_SPECIAL_PATH: |