コード例 #1
0
def preload_module():
  logger.debug( 'received /preload_module request' )
  with jedi_lock:
    request_json = request.json
    with _CustomSettings( request_json ):
      jedi.preload_module( *request_json[ 'modules' ] )
  return _JsonResponse( True )
コード例 #2
0
 def load_plugin(self):
     """Load the Jedi introspection plugin"""
     if not programs.is_module_installed('jedi', JEDI_REQVER):
         raise ImportError('Requires Jedi %s' % JEDI_REQVER)
     jedi.settings.case_insensitive_completion = False
     for lib in ['numpy', 'matplotlib']:
         jedi.preload_module(lib)
コード例 #3
0
ファイル: jedi_plugin.py プロジェクト: AminJamalzadeh/spyder
 def load_plugin(self):
     """Load the Jedi introspection plugin"""
     if not programs.is_module_installed('jedi', JEDI_REQVER):
         raise ImportError('Requires Jedi %s' % JEDI_REQVER)
     jedi.settings.case_insensitive_completion = False
     for lib in ['numpy', 'matplotlib']:
         jedi.preload_module(lib)
コード例 #4
0
def preload_module():
    logger.debug('received /preload_module request')
    with jedi_lock:
        request_json = request.json
        with _CustomSettings(request_json):
            jedi.preload_module(*request_json['modules'])
    return _JsonResponse(True)
コード例 #5
0
def test_preload_modules():
    def check_loaded(*module_names):
        for grammar_cache in cache.parser_cache.values():
            if None in grammar_cache:
                break
        # Filter the typeshed parser cache.
        typeshed_cache_count = sum(
            1 for path in grammar_cache
            if path is not None and str(path).startswith(str(typeshed.TYPESHED_PATH))
        )
        # +1 for None module (currently used)
        assert len(grammar_cache) - typeshed_cache_count == len(module_names) + 1
        for i in module_names:
            assert [i in str(k) for k in grammar_cache.keys() if k is not None]

    old_cache = cache.parser_cache.copy()
    cache.parser_cache.clear()

    try:
        preload_module('sys')
        check_loaded()  # compiled (c_builtin) modules shouldn't be in the cache.
        preload_module('types', 'token')
        check_loaded('types', 'token')
    finally:
        cache.parser_cache.update(old_cache)
コード例 #6
0
def profile_preload(mod):
    """Preload a module into Jedi, recording time and memory used."""
    base = used_memory()
    t0 = time.time()
    jedi.preload_module(mod)
    elapsed = time.time() - t0
    used = used_memory() - base
    return elapsed, used
コード例 #7
0
ファイル: memory_check.py プロジェクト: ldong/dotfiles
def profile_preload(mod):
    """Preload a module into Jedi, recording time and memory used."""
    base = used_memory()
    t0 = time.time()
    jedi.preload_module(mod)
    elapsed = time.time() - t0
    used = used_memory() - base
    return elapsed, used
コード例 #8
0
ファイル: jedi_server.py プロジェクト: 5l1v3r1/core-3
def main(args):
    if args.mode != "daemon":
        print(run(sys.stdin.read(), args.__dict__))
        return

    jedi.preload_module("os", "sys", "math")
    try:
        server = HTTPServer(("localhost", int(args.port)), Daemon)
    except:
        sys.stderr.write("Daemon unable to listen at :%s\n" % args.port)
        sys.exit(98)
    sys.stderr.write("Daemon " + "listening at :%s\n" % args.port) # concat strings to avoid matching this string in the client
    server.serve_forever()
コード例 #9
0
def main(args):
    if args.mode != "daemon":
        print(run(sys.stdin.read(), args.__dict__))
        return

    jedi.preload_module("os", "sys", "math")
    try:
        server = HTTPServer(("localhost", int(args.port)), Daemon)
    except:
        sys.stderr.write("Daemon unable to listen at :%s\n" % args.port)
        sys.exit(98)
    sys.stderr.write("Daemon " + "listening at :%s\n" % args.port) # concat strings to avoid matching this string in the client
    server.serve_forever()
コード例 #10
0
 def run(self):
     url = "https://docs.python.org/3/py-modindex.html"
     try:
         moduleHtml = _requests.get(url)
     except _requests.exceptions.ConnectionError:
         return
     if moduleHtml.status_code != 200:
         return
     soup = _bs4.BeautifulSoup(moduleHtml.text)
     codeIndex = soup.find_all("code")
     moduleNames = [
         moduleName.text for moduleName in codeIndex
         if not moduleName.text.startswith('__')
     ]
     _jedi.preload_module(moduleNames)
コード例 #11
0
ファイル: test_api.py プロジェクト: Marslo/VimConfig
def test_preload_modules():
    def check_loaded(*modules):
        # +1 for None module (currently used)
        grammar_cache = next(iter(cache.parser_cache.values()))
        assert len(grammar_cache) == len(modules) + 1
        for i in modules:
            assert [i in k for k in grammar_cache.keys() if k is not None]

    old_cache = cache.parser_cache.copy()
    cache.parser_cache.clear()

    try:
        preload_module('sys')
        check_loaded()  # compiled (c_builtin) modules shouldn't be in the cache.
        preload_module('types', 'token')
        check_loaded('types', 'token')
    finally:
        cache.parser_cache.update(old_cache)
コード例 #12
0
    def test_preload_modules(self):
        def check_loaded(*modules):
            # + 1 for builtin, +1 for None module (currently used)
            assert len(new) == len(modules) + 2
            for i in modules + ('__builtin__',):
                assert [i in k for k in new.keys() if k is not None]

        from jedi import cache
        temp_cache, cache.parser_cache = cache.parser_cache, {}
        new = cache.parser_cache
        with common.ignored(KeyError): # performance of tests -> no reload
            new['__builtin__'] = temp_cache['__builtin__']

        jedi.preload_module('datetime')
        check_loaded('datetime')
        jedi.preload_module('json', 'token')
        check_loaded('datetime', 'json', 'token')

        cache.parser_cache = temp_cache
コード例 #13
0
ファイル: test_api.py プロジェクト: KohsukeKubota/dotfiles
def test_preload_modules():
    def check_loaded(*modules):
        # +1 for None module (currently used)
        grammar_cache = next(iter(cache.parser_cache.values()))
        assert len(grammar_cache) == len(modules) + 1
        for i in modules:
            assert [i in k for k in grammar_cache.keys() if k is not None]

    old_cache = cache.parser_cache.copy()
    cache.parser_cache.clear()

    try:
        preload_module('sys')
        check_loaded(
        )  # compiled (c_builtin) modules shouldn't be in the cache.
        preload_module('types', 'token')
        check_loaded('types', 'token')
    finally:
        cache.parser_cache.update(old_cache)
コード例 #14
0
    def test_preload_modules(self):
        def check_loaded(*modules):
            # + 1 for builtin, +1 for None module (currently used)
            assert len(new) == len(modules) + 2
            for i in modules + ('__builtin__', ):
                assert [i in k for k in new.keys() if k is not None]

        from jedi import cache
        temp_cache, cache.parser_cache = cache.parser_cache, {}
        new = cache.parser_cache
        with common.ignored(KeyError):  # performance of tests -> no reload
            new['__builtin__'] = temp_cache['__builtin__']

        jedi.preload_module('datetime')
        check_loaded('datetime')
        jedi.preload_module('json', 'token')
        check_loaded('datetime', 'json', 'token')

        cache.parser_cache = temp_cache
コード例 #15
0
ファイル: jedi_plugin.py プロジェクト: ImadBouirmane/spyder
 def preload(self):
     """Preload a list of libraries"""
     for lib in ['numpy']:
         jedi.preload_module(lib)
     self.busy = False
コード例 #16
0
ファイル: completion.py プロジェクト: ginanjarn/pythontools
from api import rpc


logger = logging.getLogger("formatting")
# logger.setLevel(logging.DEBUG)
sh = logging.StreamHandler()
sh.setFormatter(logging.Formatter("%(levelname)s\t%(module)s: %(lineno)d\t%(message)s"))
sh.setLevel(logging.DEBUG)
logger.addHandler(sh)


try:
    from jedi import Script, Project, preload_module  # type: ignore
    from jedi.api.classes import Completion  # type: ignore

    preload_module(["numpy", "tensorflow", "wx"])

    class Completions(list):
        """completion list"""

    def build_rpc(completions: List[Completion]) -> Iterator[Dict[str, Any]]:
        """build rpc content"""

        for completion in completions:
            yield rpc.CompletionItem.builder(
                label=completion.name_with_symbols, type_=completion.type
            )

    def to_rpc(completions: List[Completion]) -> List[Dict[str, Any]]:
        """convert completion results to rpc"""
コード例 #17
0
    cachePrefix = 'v'
    modulesToLoad = ''
    if len(sys.argv) > 0 and sys.argv[1] == 'preview':
        jediPath = os.path.join(os.path.dirname(__file__), 'preview')
        jediPreview = True
        if len(sys.argv) > 2:
            modulesToLoad = sys.argv[2]
    elif len(sys.argv) > 0 and sys.argv[1] == 'custom':
        jediPath = sys.argv[2]
        jediPreview = True
        cachePrefix = 'custom_v'
        if len(sys.argv) > 3:
            modulesToLoad = sys.argv[3]
    else:
        #std
        jediPath = os.path.join(os.path.dirname(__file__), 'release')
        if len(sys.argv) > 2:
            modulesToLoad = sys.argv[2]

    sys.path.insert(0, jediPath)
    import jedi
    if jediPreview:
        jedi.settings.cache_directory = os.path.join(
            jedi.settings.cache_directory,
            cachePrefix + jedi.__version__.replace('.', ''))
    # remove jedi from path after we import it so it will not be completed
    sys.path.pop(0)
    if len(modulesToLoad) > 0:
        jedi.preload_module(*modulesToLoad.split(','))
    JediCompletion().watch()
コード例 #18
0
ファイル: completion.py プロジェクト: kevyin/home-settings
            except Exception:
                sys.stderr.write(traceback.format_exc() + '\n')
                sys.stderr.flush()

if __name__ == '__main__':
    cachePrefix = 'v'
    modulesToLoad = ''
    if len(sys.argv) > 2 and sys.argv[1] == 'custom':
        jediPath = sys.argv[2]
        jediPreview = True
        cachePrefix = 'custom_v'
        if len(sys.argv) > 3:
            modulesToLoad = sys.argv[3]
    else:
        #release
        jediPath = os.path.dirname(__file__)
        if len(sys.argv) > 1:
            modulesToLoad = sys.argv[1]

    sys.path.insert(0, jediPath)
    import jedi
    if jediPreview:
        jedi.settings.cache_directory = os.path.join(
            jedi.settings.cache_directory, cachePrefix + jedi.__version__.replace('.', ''))
    # remove jedi from path after we import it so it will not be completed
    sys.path.pop(0)
    if len(modulesToLoad) > 0:
        jedi.preload_module(*modulesToLoad.split(','))
    JediCompletion().watch()
コード例 #19
0
from struct import *
import json
import jedi
import sys
import os

jedi.settings.no_completion_duplicates = True
jedi.settings.use_filesystem_cache = True

print(os.path.dirname(os.path.realpath(__file__)))
lib = os.path.dirname(os.path.realpath(__file__)) + '\\..\\' + 'Lib'
sys.path.append(lib)
modules = []
modules.append(lib + "\\machine.py")
modules.append(lib + "\\onewire.py")
jedi.preload_module(modules)

print(sys.path)


class Proc(object):
    def __init__(self, j):
        self.__dict__ = json.loads(j)


TCP_IP = '127.0.0.1'
TCP_PORT = 5005


def serialize_completions(completions):
    items = []
コード例 #20
0
ファイル: jedi_server.py プロジェクト: Wizdore/coc-jedi
def preload_module(args):
    modules = args['modules']
    jedi.preload_module(modules)
    write('ok')
コード例 #21
0
 def load(self):
     jedi.settings.case_insensitive_completion = False
     for module in ("PyQt4", "PyQt5", "numpy"):
         jedi.preload_module(module)
コード例 #22
0
    simulator,
    install,
    args,
    core,
    installer,
    _get_doc_line,
)  # pylint: disable=F401

from prompt_toolkit.shortcuts import print_formatted_text
from prompt_toolkit.formatted_text import HTML

IT = core.core.IT
# for auto-completion data
# also, jedi and parso hooks need to be available
# for autoc-completion to work with pyinstaller build
jedi.preload_module("_sdk")


def get_doc(root_module, level=0, size=4):
    """get a formatted docstring from a module
    this will loop over __all__self.

    :param root_module: root module
    :type root_module: module
    :param level: spacing level, defaults to 0
    :type level: int, optional
    :param level: spacing size, defaults to 4
    :type level: int, optional
    :return: docstring
    :rtype: str
    """
コード例 #23
0
    cachePrefix = "v"
    modulesToLoad = ""

    if len(sys.argv) > 2 and sys.argv[1] == "custom":
        jediPath = sys.argv[2]
        jediPreview = True
        cachePrefix = "custom_v"
        if len(sys.argv) > 3:
            modulesToLoad = sys.argv[3]
    else:
        # release
        jediPath = os.path.join(os.path.dirname(__file__), "lib", "python")
        if len(sys.argv) > 1:
            modulesToLoad = sys.argv[1]

    sys.path.insert(0, jediPath)
    import jedi

    if jediPreview:
        jedi.settings.cache_directory = os.path.join(
            jedi.settings.cache_directory,
            cachePrefix + jedi.__version__.replace(".", ""),
        )
    # remove jedi from path after we import it so it will not be completed
    sys.path.pop(0)

    if len(modulesToLoad) > 0:
        jedi.preload_module(*modulesToLoad.split(","))
    JediCompletion().watch()
コード例 #24
0
ファイル: jedi_plugin.py プロジェクト: jessebrizzi/spyderDark
 def preload(self):
     """Preload a list of libraries"""
     for lib in ['numpy']:
         jedi.preload_module(lib)
     self.busy = False