Skip to content

Commit 76ae2da

Browse files
committed
Read plugins.jedi.extra_paths configuration also from files
Before this commit, plugins.jedi.extra_paths can be configured only via Language Server Protocol didChangeConfiguration method. This is inconvenient, if: - it is difficult to issue LSP didChangeConfiguration method with per-workspace configuration - such configuration should be persisted inside workspace This commit reads plugins.jedi.extra_paths configuration also from project-level configuration "setup.cfg" and "tox.ini".
1 parent 5037c16 commit 76ae2da

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

pyls/config/pyls_conf.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
OPTIONS = [
1212
('source_roots', 'source_roots', list),
13+
14+
# inter-plugins configurations
15+
('plugins.jedi.extra_paths', 'plugins.jedi.extra_paths', list),
1316
]
1417

1518
# list of (config_path, inside_only) tuples for path normalization
1619
NORMALIZED_CONFIGS = [
1720
('source_roots', True),
21+
('plugins.jedi.extra_paths', False),
1822
]
1923

2024

test/test_workspace.py

+59
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,62 @@ def test_pyls_config_readin(tmpdir, metafile):
250250
for raw_path in source_roots:
251251
full_path = os.path.normcase(os.path.join(root_path, raw_path))
252252
assert os.path.normpath(full_path) in sys_path
253+
254+
255+
@pytest.mark.parametrize('metafile', [
256+
'setup.cfg',
257+
'tox.ini',
258+
'service/foo/setup.cfg',
259+
'service/foo/tox.ini',
260+
None,
261+
])
262+
def test_jedi_extra_paths_config(tmpdir, metafile):
263+
"""Examine that plugins.jedi.extra_paths config is intentionaly read in.
264+
265+
This test also examines below for entries in plugins.jedi.extra_paths:
266+
267+
* relative path is:
268+
- treated as relative to config file location, and
269+
- normalized into absolute one
270+
"""
271+
root_path = str(tmpdir)
272+
273+
extra_paths = ['extra/foo', 'extra/bar', '/absolute/root', '../baz']
274+
doc_root = 'service/foo'
275+
276+
if metafile:
277+
dirname = os.path.dirname(metafile)
278+
if dirname:
279+
os.makedirs(os.path.join(root_path, dirname))
280+
281+
# configured by metafile at pyls startup
282+
with open(os.path.join(root_path, metafile), 'w+') as f:
283+
f.write('[pyls]\nplugins.jedi.extra_paths=\n %s\n' %
284+
',\n '.join(_make_paths_dir_relative(extra_paths, dirname)))
285+
286+
pyls = PythonLanguageServer(StringIO, StringIO)
287+
pyls.m_initialize(
288+
processId=1,
289+
rootUri=uris.from_fs_path(root_path),
290+
initializationOptions={}
291+
)
292+
293+
if not metafile:
294+
# configured by client via LSP after pyls startup
295+
pyls.m_workspace__did_change_configuration({
296+
'pyls': {'plugins': {'jedi': {'extra_paths': extra_paths}}},
297+
})
298+
299+
# put new document under ROOT/service/foo
300+
test_uri = uris.from_fs_path(os.path.join(root_path, doc_root, 'hello/test.py'))
301+
pyls.workspace.put_document(test_uri, 'assert true')
302+
test_doc = pyls.workspace.get_document(test_uri)
303+
304+
# apply os.path.normcase() on paths below, because case-sensitive
305+
# comparison on Windows causes unintentional failure for case
306+
# instability around drive letter
307+
308+
sys_path = [os.path.normcase(p) for p in test_doc.sys_path()]
309+
for raw_path in extra_paths:
310+
full_path = os.path.normcase(os.path.join(root_path, raw_path))
311+
assert os.path.normpath(full_path) in sys_path

0 commit comments

Comments
 (0)