mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Move the module name searching to the subprocess
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import sys
|
||||
import os
|
||||
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 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
|
||||
|
||||
|
||||
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):
|
||||
"""
|
||||
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``).
|
||||
"""
|
||||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
|
||||
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
|
||||
and not names defined in the files.
|
||||
"""
|
||||
|
||||
sub = self._evaluator.compiled_subprocess
|
||||
names = []
|
||||
# add builtin module names
|
||||
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:
|
||||
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))
|
||||
return names
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Test of keywords and ``jedi.keywords``
|
||||
"""
|
||||
from jedi._compatibility import is_py3
|
||||
|
||||
|
||||
def test_goto_assignments_keyword(Script):
|
||||
@@ -13,13 +12,13 @@ def test_goto_assignments_keyword(Script):
|
||||
Script('in').goto_assignments()
|
||||
|
||||
|
||||
def test_keyword(Script):
|
||||
def test_keyword(Script, environment):
|
||||
""" github jedi-vim issue #44 """
|
||||
defs = Script("print").goto_definitions()
|
||||
if is_py3:
|
||||
assert [d.docstring() for d in defs]
|
||||
else:
|
||||
if environment.version_info.major < 3:
|
||||
assert defs == []
|
||||
else:
|
||||
assert [d.docstring() for d in defs]
|
||||
|
||||
assert Script("import").goto_assignments() == []
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@ def _check_speed(time_per_run, number=4, run_warm=True):
|
||||
reintroduced to Jedi."""
|
||||
def decorated(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper():
|
||||
def wrapper(**kwargs):
|
||||
if run_warm:
|
||||
func()
|
||||
func(**kwargs)
|
||||
first = time.time()
|
||||
for i in range(number):
|
||||
func()
|
||||
func(**kwargs)
|
||||
single_time = (time.time() - first) / number
|
||||
message = 'speed issue %s, %s' % (func, single_time)
|
||||
assert single_time < time_per_run, message
|
||||
|
||||
Reference in New Issue
Block a user