Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyls/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ def _binary_stdio():
PY3K = sys.version_info >= (3, 0)

if PY3K:
# pylint: disable=no-member
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
else:
# Python 2 on Windows opens sys.stdin in text mode, and
# binary data that read from it becomes corrupted on \r\n
if sys.platform == "win32":
# set sys.stdin to binary mode
# pylint: disable=no-member,import-error
import os
import msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
Expand Down
6 changes: 3 additions & 3 deletions pyls/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def find_parents(root, path, names):


def list_to_string(value):
return ",".join(value) if type(value) == list else value
return ",".join(value) if isinstance(value, list) else value


def merge_dicts(dict_a, dict_b):
Expand Down Expand Up @@ -122,7 +122,7 @@ def format_docstring(contents):
Until we can find a fast enough way of discovering and parsing each format,
we can do a little better by at least preserving indentation.
"""
contents = contents.replace('\t', '\u00A0' * 4)
contents = contents.replace(' ', '\u00A0' * 2)
contents = contents.replace('\t', u'\u00A0' * 4)
contents = contents.replace(' ', u'\u00A0' * 2)
contents = contents.replace('*', '\\*')
return contents
2 changes: 1 addition & 1 deletion pyls/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# pylint: skip-file
# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by githubs download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
Expand Down
5 changes: 2 additions & 3 deletions pyls/config/flake8_conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
import os
from .source import ConfigSource
from pyls._utils import find_parents
from .source import ConfigSource

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -33,8 +33,7 @@ def user_config(self):
def _user_config_file(self):
if self.is_windows:
return os.path.expanduser('~\\.flake8')
else:
return os.path.join(self.xdg_home, 'flake8')
return os.path.join(self.xdg_home, 'flake8')

def project_config(self, document_path):
files = find_parents(self.root_path, document_path, PROJECT_CONFIGS)
Expand Down
2 changes: 1 addition & 1 deletion pyls/config/pycodestyle_conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017 Palantir Technologies, Inc.
import pycodestyle
from .source import ConfigSource
from pyls._utils import find_parents
from .source import ConfigSource


CONFIG_KEY = 'pycodestyle'
Expand Down
5 changes: 3 additions & 2 deletions pyls/language_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):

def setup(self):
super(_StreamHandlerWrapper, self).setup()
# pylint: disable=no-member
self.delegate = self.DELEGATE_CLASS(self.rfile, self.wfile)

def handle(self):
Expand Down Expand Up @@ -62,7 +63,7 @@ def __getitem__(self, item):
def wrapped(*args, **kwargs):
try:
return func(*args, **kwargs)
except: # pylint: disable=bare-except
except:
log.exception("CAUGHT")
raise
return wrapped
Expand All @@ -77,7 +78,7 @@ class LanguageServer(MethodJSONRPCServer):
root_uri = None
init_opts = None

def capabilities(self):
def capabilities(self): # pylint: disable=no-self-use
return {}

def initialize(self, root_uri, init_opts, process_id):
Expand Down
44 changes: 22 additions & 22 deletions pyls/plugins/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def pyls_format_document(document):


@hookimpl
def pyls_format_range(document, range):
def pyls_format_range(document, range): # pylint: disable=redefined-builtin
# First we 'round' the range up/down to full lines only
range['start']['character'] = 0
range['end']['line'] += 1
Expand All @@ -32,25 +32,25 @@ def pyls_format_range(document, range):


def _format(document, lines=None):
new_source, changed = FormatCode(
document.source,
lines=lines,
filename=document.filename,
style_config=file_resources.GetDefaultStyleForDir(
os.path.dirname(document.filename)
)
new_source, changed = FormatCode(
document.source,
lines=lines,
filename=document.filename,
style_config=file_resources.GetDefaultStyleForDir(
os.path.dirname(document.filename)
)

if not changed:
return []

# I'm too lazy at the moment to parse diffs into TextEdit items
# So let's just return the entire file...
return [{
'range': {
'start': {'line': 0, 'character': 0},
# End char 0 of the line after our document
'end': {'line': len(document.lines), 'character': 0}
},
'newText': new_source
}]
)

if not changed:
return []

# I'm too lazy at the moment to parse diffs into TextEdit items
# So let's just return the entire file...
return [{
'range': {
'start': {'line': 0, 'character': 0},
# End char 0 of the line after our document
'end': {'line': len(document.lines), 'character': 0}
},
'newText': new_source
}]
2 changes: 1 addition & 1 deletion pyls/plugins/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def pyls_hover(document, position):
# Find an exact match for a completion
definitions = [d for d in definitions if d.name == word]

if len(definitions) == 0:
if not definitions:
# :(
return {'contents': ''}

Expand Down
11 changes: 6 additions & 5 deletions pyls/plugins/pycodestyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,24 @@ def __init__(self, options=None):
self.diagnostics = []
super(PyCodeStyleDiagnosticReport, self).__init__(options=options)

def error(self, lineno, offset, text, check):
def error(self, line_number, offset, text, check):
# PyCodeStyle will sometimes give you an error the line after the end of the file
# e.g. no newline at end of file
# In that case, the end offset should just be some number ~100
# (because why not? There's nothing to underline anyways)
range = {
'start': {'line': lineno - 1, 'character': offset},
err_range = {
'start': {'line': line_number - 1, 'character': offset},
'end': {
# FIXME: It's a little naiive to mark until the end of the line, can we not easily do better?
'line': lineno - 1, 'character': 100 if lineno > len(self.lines) else len(self.lines[lineno - 1])
'line': line_number - 1,
'character': 100 if line_number > len(self.lines) else len(self.lines[line_number - 1])
},
}
code, _message = text.split(" ", 1)

self.diagnostics.append({
'source': 'pycodestyle',
'range': range,
'range': err_range,
'message': text,
'code': code,
# Are style errors really ever errors?
Expand Down
10 changes: 5 additions & 5 deletions pyls/plugins/pyflakes_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ def __init__(self, lines):
def unexpectedError(self, filename, msg): # pragma: no cover
pass

def syntaxError(self, filename, msg, lineno, offset, text):
range = {
def syntaxError(self, _filename, msg, lineno, offset, text):
err_range = {
'start': {'line': lineno - 1, 'character': offset},
'end': {'line': lineno - 1, 'character': offset + len(text)},
}
self.diagnostics.append({
'source': 'pyflakes',
'range': range,
'range': err_range,
'message': msg,
'severity': lsp.DiagnosticSeverity.Error,
})

def flake(self, message):
""" Get message like <filename>:<lineno>: <msg> """
range = {
err_range = {
'start': {'line': message.lineno - 1, 'character': message.col},
'end': {'line': message.lineno - 1, 'character': len(self.lines[message.lineno - 1])},
}
self.diagnostics.append({
'source': 'pyflakes',
'range': range,
'range': err_range,
'message': message.message % message.message_args,
'severity': lsp.DiagnosticSeverity.Warning
})
10 changes: 5 additions & 5 deletions pyls/plugins/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

log = logging.getLogger(__name__)

SPHINX = re.compile("\s*:param\s+(?P<param>\w+):\s*(?P<doc>[^\\n]+)")
EPYDOC = re.compile("\s*@param\s+(?P<param>\w+):\s*(?P<doc>[^\\n]+)")
GOOGLE = re.compile("\s*(?P<param>\w+).*:\s*(?P<doc>[^\\n]+)")
SPHINX = re.compile(r"\s*:param\s+(?P<param>\w+):\s*(?P<doc>[^\n]+)")
EPYDOC = re.compile(r"\s*@param\s+(?P<param>\w+):\s*(?P<doc>[^\n]+)")
GOOGLE = re.compile(r"\s*(?P<param>\w+).*:\s*(?P<doc>[^\n]+)")

DOC_REGEX = [SPHINX, EPYDOC, GOOGLE]

Expand All @@ -16,7 +16,7 @@
def pyls_signature_help(document, position):
signatures = document.jedi_script(position).call_signatures()

if len(signatures) == 0:
if not signatures:
return {'signatures': []}

s = signatures[0]
Expand All @@ -26,7 +26,7 @@ def pyls_signature_help(document, position):
}

# If there are params, add those
if len(s.params) > 0:
if s.params:
sig['parameters'] = [{
'label': p.name,
'documentation': _param_docs(s.docstring(), p.name)
Expand Down
2 changes: 1 addition & 1 deletion pyls/plugins/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _container(definition):
# as children of the module.
if parent.parent():
return parent.name
except:
except: # pylint: disable=bare-except
pass


Expand Down
5 changes: 3 additions & 2 deletions pyls/python_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


class PythonLanguageServer(LanguageServer):
# pylint: disable=too-many-public-methods,redefined-builtin

workspace = None
config = None
Expand Down Expand Up @@ -148,14 +149,14 @@ def m_text_document__hover(self, textDocument=None, position=None, **_kwargs):
def m_text_document__document_symbol(self, textDocument=None, **_kwargs):
return self.document_symbols(textDocument['uri'])

def m_text_document__formatting(self, textDocument=None, options=None, **_kwargs):
def m_text_document__formatting(self, textDocument=None, _options=None, **_kwargs):
# For now we're ignoring formatting options.
return self.format_document(textDocument['uri'])

def m_text_document__rename(self, textDocument=None, position=None, newName=None, **_kwargs):
return self.rename(textDocument['uri'], position, newName)

def m_text_document__range_formatting(self, textDocument=None, range=None, options=None, **_kwargs):
def m_text_document__range_formatting(self, textDocument=None, range=None, _options=None, **_kwargs):
# Again, we'll ignore formatting options for now.
return self.format_range(textDocument['uri'], range)

Expand Down
2 changes: 1 addition & 1 deletion pyls/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def handle(self):
on_result(msg['result'])
elif 'error' in msg and on_error:
on_error(msg['error'])
except Exception:
except: # pylint: disable=bare-except
log.exception("Language server exiting due to uncaught exception")
break

Expand Down
8 changes: 4 additions & 4 deletions pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@

def get_submodules(mod):
"""Get all submodules of a given module"""
def catch_exceptions(module):
def catch_exceptions(_module):
pass

try:
m = __import__(mod)
submodules = [mod]
submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.',
catch_exceptions)
submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.', catch_exceptions)
for sm in submods:
sm_name = sm[1]
submodules.append(sm_name)
except ImportError:
return []
except Exception:
except: # pylint: disable=bare-except
return [mod]
return submodules

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ deps =
pytest
coverage
pytest-cov
pylint

[testenv:lint]
commands =
pylint pyls
pycodestyle pyls
pyflakes pyls