Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Update Jedi requirement to 0.17 and Parso to 0.7 #12792

Merged
merged 13 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ if [ "$USE_CONDA" = "true" ]; then
fi

# Install main dependencies
conda install python=$PYTHON_VERSION --file requirements/conda.txt -q -y
if [ "$PYTHON_VERSION" = "2.7" ]; then
conda install python=$PYTHON_VERSION --file requirements/conda-2.7.txt -q -y
else
conda install python=$PYTHON_VERSION --file requirements/conda.txt -q -y
fi

# Install test ones
conda install python=$PYTHON_VERSION --file requirements/tests.txt -c spyder-ide -q -y
Expand Down Expand Up @@ -45,13 +49,17 @@ else

# Remove packages we have subrepos for
pip uninstall spyder-kernels -q -y
pip uninstall python-language-server -q -y
if [ "$PYTHON_VERSION" != "2.7" ]; then
pip uninstall python-language-server -q -y
fi
fi

# Install python-language-server from our subrepo
pushd external-deps/python-language-server
pip install --no-deps -q -e .
popd
if [ "$PYTHON_VERSION" != "2.7" ]; then
pushd external-deps/python-language-server
pip install --no-deps -q -e .
popd
fi

# To check our manifest
pip install check-manifest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- INSTALL_TYPE: 'pip'
PYTHON_VERSION: '2.7'
TEST_TYPE: 'slow'
- INSTALL_TYPE: 'conda'
PYTHON_VERSION: '2.7'
TEST_TYPE: 'slow'
steps:
- name: Checkout Pull Requests
if: github.event_name == 'pull_request'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
INSTALL_TYPE: ['conda']
PYTHON_VERSION: ['3.7', '2.7']
TEST_TYPE: ['fast', 'slow']
exclude:
- INSTALL_TYPE: 'conda'
PYTHON_VERSION: '2.7'
TEST_TYPE: 'slow'
steps:
- name: Checkout Pull Requests
if: github.event_name == 'pull_request'
Expand Down
6 changes: 4 additions & 2 deletions .pep8speaks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# File : .pep8speaks.yml

scanner:
diff_only: True # Errors caused by only the patch are shown
linter: pycodestyle

pycodestyle:
exclude: external-deps
4 changes: 2 additions & 2 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ dependencies:
- diff-match-patch >=20181111
- intervaltree
- ipython >=4.0
- jedi =0.15.2
- jedi =0.17.0
- keyring
- nbconvert >=4.0
- numpydoc >=0.6.0
- paramiko >=2.4.0
- parso =0.5.2
- parso =0.7.0
- pexpect >=4.4.0
- pickleshare >=0.4
- psutil >=5.3
Expand Down
4 changes: 2 additions & 2 deletions external-deps/python-language-server/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

python3-test:
docker:
- image: "python:3.5-stretch"
- image: "python:3.6-stretch"
steps:
- checkout
# To test Jedi environments
Expand All @@ -35,7 +35,7 @@ jobs:

publish:
docker:
- image: "python:3.5-stretch"
- image: "python:3.6-stretch"
steps:
- checkout
- run: ./scripts/circle/pypi.sh
Expand Down
4 changes: 2 additions & 2 deletions external-deps/python-language-server/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/palantir/python-language-server.git
branch = develop
commit = fdb8b3dbc5df7d12729d135932bf2264e0883061
parent = 0798ff6e51f6d1c353b8278469a32adab54b874f
commit = 9b5cb2197405b2290161deb2abd8e2b139a53691
parent = dbb0398cd7e309e6de7a7740c57a03ecbb26ac11
method = merge
cmdver = 0.4.1
4 changes: 4 additions & 0 deletions external-deps/python-language-server/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ To enable pydocstyle for linting docstrings add the following setting in your LS
"pyls.plugins.pydocstyle.enabled": true
```

See `vscode-client/package.json`_ for the full set of supported configuration options.

.. _vscode-client/package.json: vscode-client/package.json

Language Server Features
------------------------

Expand Down
4 changes: 2 additions & 2 deletions external-deps/python-language-server/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ environment:
PYTHON_VERSION: "2.7.15"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python35"
PYTHON_VERSION: "3.5.7"
- PYTHON: "C:\\Python36"
PYTHON_VERSION: "3.6.8"
PYTHON_ARCH: "64"

matrix:
Expand Down
25 changes: 20 additions & 5 deletions external-deps/python-language-server/pyls/_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright 2017 Palantir Technologies, Inc.
from distutils.version import LooseVersion
import functools
import inspect
import logging
Expand Down Expand Up @@ -140,18 +139,34 @@ def format_docstring(contents):
"""
contents = contents.replace('\t', u'\u00A0' * 4)
contents = contents.replace(' ', u'\u00A0' * 2)
if LooseVersion(JEDI_VERSION) < LooseVersion('0.15.0'):
contents = contents.replace('*', '\\*')
return contents


def clip_column(column, lines, line_number):
# Normalise the position as per the LSP that accepts character positions > line length
# https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#position
"""
Normalise the position as per the LSP that accepts character positions > line length

https://microsoft.github.io/language-server-protocol/specification#position
"""
max_column = len(lines[line_number].rstrip('\r\n')) if len(lines) > line_number else 0
return min(column, max_column)


def position_to_jedi_linecolumn(document, position):
"""
Convert the LSP format 'line', 'character' to Jedi's 'line', 'column'

https://microsoft.github.io/language-server-protocol/specification#position
"""
code_position = {}
if position:
code_position = {'line': position['line'] + 1,
'column': clip_column(position['character'],
document.lines,
position['line'])}
return code_position


if os.name == 'nt':
import ctypes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
('ignore', 'plugins.pycodestyle.ignore', list),
('max-line-length', 'plugins.pycodestyle.maxLineLength', int),
('select', 'plugins.pycodestyle.select', list),
('aggressive', 'plugins.pycodestyle.aggressive', int),
]


Expand Down
7 changes: 7 additions & 0 deletions external-deps/python-language-server/pyls/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class CompletionItemKind(object):
Color = 16
File = 17
Reference = 18
Folder = 19
EnumMember = 20
Constant = 21
Struct = 22
Event = 23
Operator = 24
TypeParameter = 25


class DocumentHighlightKind(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _autopep8_config(config):
'ignore': settings.get('ignore'),
'max_line_length': settings.get('maxLineLength'),
'select': settings.get('select'),
'aggressive': settings.get('aggressive'),
}

# Filter out null options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
from pyls import hookimpl, uris
from pyls import hookimpl, uris, _utils

log = logging.getLogger(__name__)


@hookimpl
def pyls_definitions(config, document, position):
settings = config.plugin_settings('jedi_definition')
definitions = document.jedi_script(position).goto_assignments(
code_position = _utils.position_to_jedi_linecolumn(document, position)
definitions = document.jedi_script().goto(
follow_imports=settings.get('follow_imports', True),
follow_builtin_imports=settings.get('follow_builtin_imports', True))
follow_builtin_imports=settings.get('follow_builtin_imports', True),
**code_position)

return [
{
Expand Down
17 changes: 11 additions & 6 deletions external-deps/python-language-server/pyls/plugins/flake8_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ def run_flake8(args):
cmd = ['python', '-m', 'flake8']
cmd.extend(args)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
stderr = p.stderr.read().decode()
(stdout, stderr) = p.communicate()
if stderr:
log.error("Error while running flake8 '%s'", stderr)
stdout = p.stdout
return stdout.read().decode()
log.error("Error while running flake8 '%s'", stderr.decode())
return stdout.decode()


def build_args(options, doc_path):
Expand Down Expand Up @@ -119,10 +118,16 @@ def parse_stdout(document, stdout):
diagnostics = []
lines = stdout.splitlines()
for raw_line in lines:
parsed_line = re.match(r'(.*):(\d*):(\d*): (\w*) (.*)', raw_line).groups()
if not parsed_line or len(parsed_line) != 5:
parsed_line = re.match(r'(.*):(\d*):(\d*): (\w*) (.*)', raw_line)
if not parsed_line:
log.debug("Flake8 output parser can't parse line '%s'", raw_line)
continue

parsed_line = parsed_line.groups()
if len(parsed_line) != 5:
log.debug("Flake8 output parser can't parse line '%s'", raw_line)
continue

_, line, character, code, msg = parsed_line
line = int(line) - 1
character = int(character) - 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
from pyls import hookimpl, lsp
from pyls import hookimpl, lsp, _utils

log = logging.getLogger(__name__)


@hookimpl
def pyls_document_highlight(document, position):
usages = document.jedi_script(position).usages()
code_position = _utils.position_to_jedi_linecolumn(document, position)
usages = document.jedi_script().get_references(**code_position)

def is_valid(definition):
return definition.line is not None and definition.column is not None
Expand Down
71 changes: 34 additions & 37 deletions external-deps/python-language-server/pyls/plugins/hover.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2017 Palantir Technologies, Inc.
from distutils.version import LooseVersion

import logging

from pyls import hookimpl, _utils
Expand All @@ -9,43 +9,40 @@

@hookimpl
def pyls_hover(document, position):
definitions = document.jedi_script(position).goto_definitions()
code_position = _utils.position_to_jedi_linecolumn(document, position)
definitions = document.jedi_script().infer(**code_position)
word = document.word_at_position(position)

if LooseVersion(_utils.JEDI_VERSION) >= LooseVersion('0.15.0'):
# Find first exact matching definition
definition = next((x for x in definitions if x.name == word), None)

# Ensure a definition is used if only one is available
# even if the word doesn't match. An example of this case is 'np'
# where 'numpy' doesn't match with 'np'. Same for NumPy ufuncs
if len(definitions) == 1:
definition = definitions[0]

if not definition:
return {'contents': ''}

# raw docstring returns only doc, without signature
doc = _utils.format_docstring(definition.docstring(raw=True))

# Find first exact matching signature
signature = next((x.to_string() for x in definition.get_signatures() if x.name == word), '')

contents = []
if signature:
contents.append({
'language': 'python',
'value': signature,
})
if doc:
contents.append(doc)
if not contents:
return {'contents': ''}
return {'contents': contents}
else:
# Find an exact match for a completion
for d in definitions:
if d.name == word:
return {'contents': _utils.format_docstring(d.docstring()) or ''}
# Find first exact matching definition
definition = next((x for x in definitions if x.name == word), None)

# Ensure a definition is used if only one is available
# even if the word doesn't match. An example of this case is 'np'
# where 'numpy' doesn't match with 'np'. Same for NumPy ufuncs
if len(definitions) == 1:
definition = definitions[0]

if not definition:
return {'contents': ''}

# raw docstring returns only doc, without signature
doc = _utils.format_docstring(definition.docstring(raw=True))

# Find first exact matching signature
signature = next((x.to_string() for x in definition.get_signatures()
if x.name == word), '')

contents = []
if signature:
contents.append({
'language': 'python',
'value': signature,
})

if doc:
contents.append(doc)

if not contents:
return {'contents': ''}

return {'contents': contents}