mirror of
https://github.com/neovim/neovim.git
synced 2025-09-11 13:58:18 +00:00
Merge pull request #2910 from blueyed/python-fix-path_hook
Python: fixes for sys.path_hooks handler
This commit is contained in:
@@ -17,6 +17,9 @@ IS_PYTHON3 = sys.version_info >= (3, 0)
|
|||||||
if IS_PYTHON3:
|
if IS_PYTHON3:
|
||||||
basestring = str
|
basestring = str
|
||||||
|
|
||||||
|
if sys.version_info >= (3, 4):
|
||||||
|
from importlib.machinery import PathFinder
|
||||||
|
|
||||||
|
|
||||||
@neovim.plugin
|
@neovim.plugin
|
||||||
class ScriptHost(object):
|
class ScriptHost(object):
|
||||||
@@ -190,31 +193,35 @@ def path_hook(nvim):
|
|||||||
name = oldtail[:idx]
|
name = oldtail[:idx]
|
||||||
tail = oldtail[idx+1:]
|
tail = oldtail[idx+1:]
|
||||||
fmr = imp.find_module(name, path)
|
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__)
|
return _find_module(fullname, tail, module.__path__)
|
||||||
else:
|
else:
|
||||||
fmr = imp.find_module(fullname, path)
|
return imp.find_module(fullname, path)
|
||||||
return imp.load_module(fullname, *fmr)
|
|
||||||
|
|
||||||
class VimModuleLoader(object):
|
class VimModuleLoader(object):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
|
|
||||||
def load_module(self, fullname, path=None):
|
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):
|
class VimPathFinder(object):
|
||||||
@classmethod
|
@staticmethod
|
||||||
def find_module(cls, fullname, path=None):
|
def find_module(fullname, path=None):
|
||||||
|
"Method for Python 2.7 and 3.3."
|
||||||
try:
|
try:
|
||||||
return VimModuleLoader(
|
return VimModuleLoader(
|
||||||
_find_module(fullname, fullname, path or _get_paths()))
|
_find_module(fullname, fullname, path or _get_paths()))
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@staticmethod
|
||||||
def load_module(cls, fullname, path=None):
|
def find_spec(fullname, path=None, target=None):
|
||||||
return _find_module(fullname, fullname, path or _get_paths())
|
"Method for Python 3.4+."
|
||||||
|
return PathFinder.find_spec(fullname, path or _get_paths(), target)
|
||||||
|
|
||||||
def hook(path):
|
def hook(path):
|
||||||
if path == nvim.VIM_SPECIAL_PATH:
|
if path == nvim.VIM_SPECIAL_PATH:
|
||||||
|
Reference in New Issue
Block a user