Skip to content

Commit c890d1a

Browse files
committed
Auto preload installed modules
1 parent b0174b7 commit c890d1a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pyls/workspace.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import re
6+
import pkg_resources
67

78
import jedi
89

@@ -116,6 +117,7 @@ def _create_document(self, doc_uri, source=None, version=None):
116117

117118

118119
class Document(object):
120+
DO_NOT_PRELOAD_MODULES = ['attrs', 'backcall', 'bleach', 'certifi', 'chardet', 'cycler', 'decorator', 'defusedxml', 'docopt', 'entrypoints', 'idna', 'importlib-metadata', 'ipykernel', 'ipython-genutils', 'ipython', 'ipywidgets', 'jedi', 'jinja2', 'joblib', 'jsonschema', 'jupyter-client', 'jupyter-core', 'markupsafe', 'mistune', 'nbconvert', 'nbformat', 'notebook', 'packaging', 'pandocfilters', 'parso', 'pexpect', 'pickleshare', 'pip', 'pipreqs', 'pluggy', 'prometheus-client', 'prompt-toolkit', 'ptyprocess', 'pygments', 'pyparsing', 'pyrsistent', 'python-dateutil', 'python-jsonrpc-server', 'python-language-server', 'pytz', 'pyzmq', 'send2trash', 'setuptools', 'six', 'terminado', 'testpath', 'threadpoolctl', 'tornado', 'traitlets', 'ujson', 'wcwidth', 'webencodings', 'wheel', 'widgetsnbextension', 'yarg', 'zipp']
119121

120122
def __init__(self, uri, workspace, source=None, version=None, local=True, extra_sys_path=None,
121123
rope_project_builder=None):
@@ -133,7 +135,14 @@ def __init__(self, uri, workspace, source=None, version=None, local=True, extra_
133135

134136
jedi.settings.cache_directory = '.cache/jedi/'
135137
jedi.settings.use_filesystem_cache = True
136-
jedi.settings.auto_import_modules = ['numpy', 'pandas', 'scipy', 'matplotlib', 'scikit-learn', 'requests' ]
138+
jedi.settings.auto_import_modules = self._get_auto_import_modules()
139+
140+
def _get_auto_import_modules(self):
141+
installed_packages = pkg_resources.working_set
142+
installed_packages_list = [i.key for i in installed_packages]
143+
144+
auto_import_modules = list(filter(lambda x: x not in self.DO_NOT_PRELOAD_MODULES, installed_packages_list))
145+
return auto_import_modules
137146

138147
def __str__(self):
139148
return str(self.uri)

0 commit comments

Comments
 (0)