forked from VimPlug/jedi
Move the module name searching to the subprocess
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import imp
|
import imp
|
||||||
|
import pkgutil
|
||||||
|
|
||||||
from jedi._compatibility import find_module, cast_path
|
from jedi._compatibility import find_module, cast_path, force_unicode
|
||||||
from jedi.evaluate.compiled import access
|
from jedi.evaluate.compiled import access
|
||||||
from jedi import parser_utils
|
from jedi import parser_utils
|
||||||
|
|
||||||
@@ -54,6 +55,17 @@ def get_module_info(evaluator, sys_path=None, full_name=None, **kwargs):
|
|||||||
return code, cast_path(module_path), is_pkg
|
return code, cast_path(module_path), is_pkg
|
||||||
|
|
||||||
|
|
||||||
|
def list_module_names(evaluator, search_path):
|
||||||
|
return [
|
||||||
|
name
|
||||||
|
for module_loader, name, is_pkg in pkgutil.iter_modules(search_path)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def get_builtin_module_names(evaluator):
|
||||||
|
return list(map(force_unicode, sys.builtin_module_names))
|
||||||
|
|
||||||
|
|
||||||
def _get_init_path(directory_path):
|
def _get_init_path(directory_path):
|
||||||
"""
|
"""
|
||||||
The __init__ file can be searched in a directory. If found return it, else
|
The __init__ file can be searched in a directory. If found return it, else
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ This module also supports import autocompletion, which means to complete
|
|||||||
statements like ``from datetim`` (curser at the end would return ``datetime``).
|
statements like ``from datetim`` (curser at the end would return ``datetime``).
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import pkgutil
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from parso.python import tree
|
from parso.python import tree
|
||||||
@@ -383,15 +382,16 @@ class Importer(object):
|
|||||||
Get the names of all modules in the search_path. This means file names
|
Get the names of all modules in the search_path. This means file names
|
||||||
and not names defined in the files.
|
and not names defined in the files.
|
||||||
"""
|
"""
|
||||||
|
sub = self._evaluator.compiled_subprocess
|
||||||
names = []
|
names = []
|
||||||
# add builtin module names
|
# add builtin module names
|
||||||
if search_path is None and in_module is None:
|
if search_path is None and in_module is None:
|
||||||
names += [self._generate_name(name) for name in sys.builtin_module_names]
|
names += [self._generate_name(name) for name in sub.get_builtin_module_names()]
|
||||||
|
|
||||||
if search_path is None:
|
if search_path is None:
|
||||||
search_path = self.sys_path_with_modifications()
|
search_path = self.sys_path_with_modifications()
|
||||||
for module_loader, name, is_pkg in pkgutil.iter_modules(search_path):
|
|
||||||
|
for name in sub.list_module_names(search_path):
|
||||||
names.append(self._generate_name(name, in_module=in_module))
|
names.append(self._generate_name(name, in_module=in_module))
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
Test of keywords and ``jedi.keywords``
|
Test of keywords and ``jedi.keywords``
|
||||||
"""
|
"""
|
||||||
from jedi._compatibility import is_py3
|
|
||||||
|
|
||||||
|
|
||||||
def test_goto_assignments_keyword(Script):
|
def test_goto_assignments_keyword(Script):
|
||||||
@@ -13,13 +12,13 @@ def test_goto_assignments_keyword(Script):
|
|||||||
Script('in').goto_assignments()
|
Script('in').goto_assignments()
|
||||||
|
|
||||||
|
|
||||||
def test_keyword(Script):
|
def test_keyword(Script, environment):
|
||||||
""" github jedi-vim issue #44 """
|
""" github jedi-vim issue #44 """
|
||||||
defs = Script("print").goto_definitions()
|
defs = Script("print").goto_definitions()
|
||||||
if is_py3:
|
if environment.version_info.major < 3:
|
||||||
assert [d.docstring() for d in defs]
|
|
||||||
else:
|
|
||||||
assert defs == []
|
assert defs == []
|
||||||
|
else:
|
||||||
|
assert [d.docstring() for d in defs]
|
||||||
|
|
||||||
assert Script("import").goto_assignments() == []
|
assert Script("import").goto_assignments() == []
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ def _check_speed(time_per_run, number=4, run_warm=True):
|
|||||||
reintroduced to Jedi."""
|
reintroduced to Jedi."""
|
||||||
def decorated(func):
|
def decorated(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper():
|
def wrapper(**kwargs):
|
||||||
if run_warm:
|
if run_warm:
|
||||||
func()
|
func(**kwargs)
|
||||||
first = time.time()
|
first = time.time()
|
||||||
for i in range(number):
|
for i in range(number):
|
||||||
func()
|
func(**kwargs)
|
||||||
single_time = (time.time() - first) / number
|
single_time = (time.time() - first) / number
|
||||||
message = 'speed issue %s, %s' % (func, single_time)
|
message = 'speed issue %s, %s' % (func, single_time)
|
||||||
assert single_time < time_per_run, message
|
assert single_time < time_per_run, message
|
||||||
|
|||||||
Reference in New Issue
Block a user