From dedac0898707819b4ac465b0edf1ccf42676d26b Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sat, 15 Oct 2016 18:45:32 +0200 Subject: [PATCH] Added mypy for python. --- TODO | 6 +++--- golden-files/results/mypy-hi3_py | 0 golden-files/results/mypy-hi_py | 2 ++ tools.py | 9 ++++++++- tools_test.py | 4 ++++ 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 golden-files/results/mypy-hi3_py create mode 100644 golden-files/results/mypy-hi_py diff --git a/TODO b/TODO index 4a575b5..a3521dc 100644 --- a/TODO +++ b/TODO @@ -164,6 +164,8 @@ Done - Recognize python test files like: test_*.py - Only show the 'keys' in the help page, and only show the command line usage on the command line. +- Can mypy be a tool? + <- Yes, but wait for it to be included in python, or until it is an ubuntu package. A-syntax, B-tests, C-auto docs, D-lint, E-coverage, F-profile, G-tidy, H-import deps A B C D E F G H @@ -210,7 +212,7 @@ Ideas contents of compressed archives, pdf2text, doc2text, html2text, ebook2text, csv file? - Check these tools: astyle, indent, uncrustify, xmlindent, csstidy, flake8, - frosted, pep257, pyroma, dodgy, jedi, pep8-naming, graphite, propector, mypy, vmprof, pytype + frosted, pep257, pyroma, dodgy, jedi, pep8-naming, graphite, propector, vmprof, pytype - eslint for javascript? - epydoc for python - readelf @@ -267,8 +269,6 @@ Ideas - Have command line options for more things? timeout? worker's nice priority level? editor? pygment syntax theme? Compress the cache? Ignore which paths? Log to disk? The cache path? -- Can mypy be a tool? - <- Yes, but wait for it to be included in python, or until it is an ubuntu package. - Have a command-line option to create workers that run remotely. diff --git a/golden-files/results/mypy-hi3_py b/golden-files/results/mypy-hi3_py new file mode 100644 index 0000000..e69de29 diff --git a/golden-files/results/mypy-hi_py b/golden-files/results/mypy-hi_py new file mode 100644 index 0000000..a7cbe2b --- /dev/null +++ b/golden-files/results/mypy-hi_py @@ -0,0 +1,2 @@ +input/hi.py: note: In function "hi": +input/hi.py:4: error: Parse error before string literal \ No newline at end of file diff --git a/tools.py b/tools.py index 0a482fc..1fde8cf 100644 --- a/tools.py +++ b/tools.py @@ -325,6 +325,13 @@ def pydoc(path): pydoc.dependencies = {"python", "python3"} +def mypy(path): + stdout, stderr, returncode = _do_command(["mypy", path], timeout=TIMEOUT) + status = Status.ok if returncode == 0 else Status.normal + return status, fill3.Text(stdout) +mypy.dependencies = {"mypy"} + + def _colorize_coverage_report(text): line_color = {"> ": termstr.Color.green, "! ": termstr.Color.red, " ": None} @@ -672,7 +679,7 @@ def _generic_tools(): def _tools_for_extension(): return { - "py": [python_syntax, python_unittests, pydoc, python_coverage, + "py": [python_syntax, python_unittests, pydoc, mypy, python_coverage, python_profile, pep8, pyflakes, pylint, python_gut, python_modulefinder, python_mccabe], "pyc": [disassemble_pyc], diff --git a/tools_test.py b/tools_test.py index eb8c77e..7627fcb 100755 --- a/tools_test.py +++ b/tools_test.py @@ -88,6 +88,10 @@ class ToolsTestCase(unittest.TestCase): def test_pydoc(self): self._test_tool(tools.pydoc, self.HI_NORMAL) + def test_mypy(self): + self._test_tool(tools.mypy, [("hi3.py", tools.Status.ok), + ("hi.py", tools.Status.normal)]) + def test_python_coverage(self): self._test_tool(tools.python_coverage, self.HI_NORMAL)