Skip to content
Snippets Groups Projects
Commit 18271903 authored by Jochen Sprickerhof's avatar Jochen Sprickerhof
Browse files

Update upstream source from tag 'upstream/0.6.3'

Update to upstream version '0.6.3'
with Debian dir b094160955657151c63df452ce4328ef450b923d
parents cac6afb4 be52388f
No related branches found
No related tags found
No related merge requests found
......@@ -9,13 +9,19 @@ on:
pull_request:
branches: [ master ]
defaults:
run:
shell: bash
jobs:
testCode:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
......@@ -31,9 +37,7 @@ jobs:
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --show-source --statistics
- name: Check black formatting
run: |
# stop the build if black detect any changes
......
__version__ = "0.6.2"
__version__ = "0.6.3"
......@@ -207,6 +207,7 @@ def pylsp_lint(
args.append("--strict")
overrides = settings.get("overrides", [True])
exit_status = 0
if not dmypy:
args.extend(["--incremental", "--follow-imports", "silent"])
......@@ -221,11 +222,12 @@ def pylsp_lint(
)
report = completed_process.stdout.decode()
errors = completed_process.stderr.decode()
exit_status = completed_process.returncode
else:
# mypy does not exist on path, but must exist in the env pylsp-mypy is installed in
# -> use mypy via api
log.info("executing mypy args = %s via api", args)
report, errors, _ = mypy_api.run(args)
report, errors, exit_status = mypy_api.run(args)
else:
# If dmypy daemon is non-responsive calls to run will block.
# Check daemon status, if non-zero daemon is dead or hung.
......@@ -239,20 +241,24 @@ def pylsp_lint(
completed_process = subprocess.run(
["dmypy", *apply_overrides(args, overrides)], stderr=subprocess.PIPE, **windows_flag
)
_err = completed_process.stderr.decode()
_status = completed_process.returncode
if _status != 0:
errors = completed_process.stderr.decode()
exit_status = completed_process.returncode
if exit_status != 0:
log.info(
"restarting dmypy from status: %s message: %s via path", _status, _err.strip()
"restarting dmypy from status: %s message: %s via path",
exit_status,
errors.strip(),
)
subprocess.run(["dmypy", "kill"], **windows_flag)
else:
# dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
# -> use dmypy via api
_, _err, _status = mypy_api.run_dmypy(["status"])
if _status != 0:
_, errors, exit_status = mypy_api.run_dmypy(["status"])
if exit_status != 0:
log.info(
"restarting dmypy from status: %s message: %s via api", _status, _err.strip()
"restarting dmypy from status: %s message: %s via api",
exit_status,
errors.strip(),
)
mypy_api.run_dmypy(["kill"])
......@@ -268,16 +274,33 @@ def pylsp_lint(
)
report = completed_process.stdout.decode()
errors = completed_process.stderr.decode()
exit_status = completed_process.returncode
else:
# dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
# -> use dmypy via api
log.info("dmypy run args = %s via api", args)
report, errors, _ = mypy_api.run_dmypy(args)
report, errors, exit_status = mypy_api.run_dmypy(args)
log.debug("report:\n%s", report)
log.debug("errors:\n%s", errors)
diagnostics = []
# Expose generic mypy error on the first line.
if errors:
diagnostics.append(
{
"source": "mypy",
"range": {
"start": {"line": 0, "character": 0},
# Client is supposed to clip end column to line length.
"end": {"line": 0, "character": 1000},
},
"message": errors,
"severity": 1 if exit_status != 0 else 2, # Error if exited with error or warning.
}
)
for line in report.splitlines():
log.debug("parsing: line = %r", line)
diag = parse_line(line, document)
......
[metadata]
name = pylsp-mypy
author = Tom van Ommeren, Richard Kellnberger
author = Richard Kellnberger, Tom van Ommeren
description = Mypy linter for the Python LSP Server
url = https://github.com/python-lsp/pylsp-mypy
long_description = file: README.rst
......@@ -23,6 +23,9 @@ install_requires =
mypy
toml
[flake8]
max-complexity = 20
max-line-length = 100
[options.entry_points]
pylsp = pylsp_mypy = pylsp_mypy.plugin
......
import collections
import os
import subprocess
from pathlib import Path
from typing import Dict
from unittest.mock import Mock
import pytest
......@@ -9,7 +12,7 @@ from pylsp.workspace import Document, Workspace
from pylsp_mypy import plugin
DOC_URI = __file__
DOC_URI = f"file:/{Path(__file__)}"
DOC_TYPE_ERR = """{}.append(3)
"""
TYPE_ERR_MSG = '"Dict[<nothing>, <nothing>]" has no attribute "append"'
......@@ -18,6 +21,10 @@ TEST_LINE = 'test_plugin.py:279:8: error: "Request" has no attribute "id"'
TEST_LINE_WITHOUT_COL = "test_plugin.py:279: " 'error: "Request" has no attribute "id"'
TEST_LINE_WITHOUT_LINE = "test_plugin.py: " 'error: "Request" has no attribute "id"'
windows_flag: Dict[str, int] = (
{"creationflags": subprocess.CREATE_NO_WINDOW} if os.name == "nt" else {} # type: ignore
)
@pytest.fixture
def last_diagnostics_monkeypatch(monkeypatch):
......@@ -36,7 +43,7 @@ def workspace(tmpdir):
class FakeConfig(object):
def __init__(self):
self._root_path = "C:" if os.name == "nt" else "/"
self._root_path = "C://" if os.name == "nt" else "/"
def plugin_settings(self, plugin, document_path=None):
return {}
......@@ -140,6 +147,7 @@ def test_apply_overrides():
assert plugin.apply_overrides(["1"], ["a", True, "b"]) == ["a", "1", "b"]
@pytest.mark.skipif(os.name == "nt", reason="Not working on Windows due to test design.")
def test_option_overrides(tmpdir, last_diagnostics_monkeypatch, workspace):
import sys
from stat import S_IRWXU
......@@ -196,10 +204,12 @@ def test_option_overrides_dmypy(last_diagnostics_monkeypatch, workspace):
m = Mock(wraps=lambda a, **_: Mock(returncode=0, **{"stdout.decode": lambda: ""}))
last_diagnostics_monkeypatch.setattr(plugin.subprocess, "run", m)
document = Document(DOC_URI, workspace, DOC_TYPE_ERR)
plugin.pylsp_lint(
config=FakeConfig(),
workspace=workspace,
document=Document(DOC_URI, workspace, DOC_TYPE_ERR),
document=document,
is_saved=False,
)
expected = [
......@@ -209,6 +219,6 @@ def test_option_overrides_dmypy(last_diagnostics_monkeypatch, workspace):
"--python-executable",
"/tmp/fake",
"--show-column-numbers",
__file__,
document.path,
]
m.assert_called_with(expected, stderr=-1, stdout=-1)
m.assert_called_with(expected, stderr=-1, stdout=-1, **windows_flag)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment