1
1
"""Legacy python/python3-vim emulation."""
2
- import imp
3
2
import io
4
3
import logging
5
4
import os
6
5
import sys
7
6
8
7
from .decorators import plugin , rpc_export
9
8
from ..api import Nvim , walk
9
+ from ..compat import IS_PYTHON3 , find_module , load_module , new_module
10
10
from ..msgpack_rpc import ErrorResponse
11
11
from ..util import format_exc_skip
12
12
16
16
logger = logging .getLogger (__name__ )
17
17
debug , info , warn = (logger .debug , logger .info , logger .warn ,)
18
18
19
- IS_PYTHON3 = sys .version_info >= (3 , 0 )
20
-
21
19
if IS_PYTHON3 :
22
20
basestring = str
23
21
@@ -38,7 +36,7 @@ def __init__(self, nvim):
38
36
"""Initialize the legacy python-vim environment."""
39
37
self .setup (nvim )
40
38
# context where all code will run
41
- self .module = imp . new_module ('__main__' )
39
+ self .module = new_module ('__main__' )
42
40
nvim .script_context = self .module
43
41
# it seems some plugins assume 'sys' is already imported, so do it now
44
42
exec ('import sys' , self .module .__dict__ )
@@ -205,7 +203,7 @@ def eval(self, expr):
205
203
return walk (num_to_str , obj )
206
204
207
205
208
- # This was copied /adapted from nvim-python help
206
+ # Copied /adapted from : help if_pyth.
209
207
def path_hook (nvim ):
210
208
def _get_paths ():
211
209
if nvim ._thread_invalid ():
@@ -217,11 +215,11 @@ def _find_module(fullname, oldtail, path):
217
215
if idx > 0 :
218
216
name = oldtail [:idx ]
219
217
tail = oldtail [idx + 1 :]
220
- fmr = imp . find_module (name , path )
221
- module = imp . find_module (fullname [:- len (oldtail )] + name , * fmr )
218
+ fmr = find_module (name , path )
219
+ module = find_module (fullname [:- len (oldtail )] + name , * fmr )
222
220
return _find_module (fullname , tail , module .__path__ )
223
221
else :
224
- return imp . find_module (fullname , path )
222
+ return find_module (fullname , path )
225
223
226
224
class VimModuleLoader (object ):
227
225
def __init__ (self , module ):
@@ -233,7 +231,7 @@ def load_module(self, fullname, path=None):
233
231
return sys .modules [fullname ]
234
232
except KeyError :
235
233
pass
236
- return imp . load_module (fullname , * self .module )
234
+ return load_module (fullname , * self .module )
237
235
238
236
class VimPathFinder (object ):
239
237
@staticmethod
0 commit comments