From 17943189ae8e04ecceec694d1154f6855ca42632 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 16:35:30 -0300 Subject: [PATCH 01/16] Added mypy to installed packages --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index fcb7fba7..f6c1baec 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,7 @@ 'with_frosted': ('frosted>=1.4.1',), 'with_vulture': ('vulture>=0.6',), 'with_pyroma': ('pyroma==2.0.2',), + 'with_mypy': ('mypy>=0.521',) } with_everything = [req for req_list in _OPTIONAL.values() for req in req_list] _OPTIONAL['with_everything'] = sorted(with_everything) From 3d4e34e77ff7f787c37085dfcf1357a5d57e71e1 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 16:36:16 -0300 Subject: [PATCH 02/16] Added mypy reference to documentation --- .gitignore | 4 ++++ docs/supported_tools.rst | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.gitignore b/.gitignore index 05403449..baf4087c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,10 @@ nosetests.xml .project .pydevproject .idea +.vscode # Sphinx docs/_build + +# Mypy +.mypy_cache \ No newline at end of file diff --git a/docs/supported_tools.rst b/docs/supported_tools.rst index 205db2df..caa6b613 100644 --- a/docs/supported_tools.rst +++ b/docs/supported_tools.rst @@ -153,3 +153,16 @@ To install and use:: pip install prospector[with_frosted] prospector --with-tool frosted + + +`mypy `_ +`````````````````````````````````````````````````````` +Frosted is a fork of pyflakes which was created with the intention of taking over +from and extending pyflakes as development had slowed. Since Prospector was originally +created, pyflakes development has started up again and frosted has stagnated, so it has +been demoted to be an optional extra. + +To install and use:: + + pip install prospector[with_mypy] + prospector --with-tool mypy From 53154c8f3ce69d10bb8395d139f786debaac4c2d Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 16:36:50 -0300 Subject: [PATCH 03/16] Started mypy prospector tool support --- .prospector.yml | 3 +++ prospector/tools/__init__.py | 2 ++ prospector/tools/mypy/__init__.py | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 prospector/tools/mypy/__init__.py diff --git a/.prospector.yml b/.prospector.yml index a2b27a97..20e3f6f2 100644 --- a/.prospector.yml +++ b/.prospector.yml @@ -14,6 +14,9 @@ frosted: pyroma: run: true +mypy: + run: true + pylint: disable: - bad-builtin diff --git a/prospector/tools/__init__.py b/prospector/tools/__init__.py index e1b2a670..1e3ae655 100644 --- a/prospector/tools/__init__.py +++ b/prospector/tools/__init__.py @@ -2,6 +2,7 @@ from prospector.exceptions import FatalProspectorException from prospector.tools.base import ToolBase from prospector.tools.dodgy import DodgyTool +from prospector.tools.mypy import MypyTool from prospector.tools.pep8 import Pep8Tool from prospector.tools.pyflakes import PyFlakesTool from prospector.tools.pylint import PylintTool @@ -38,6 +39,7 @@ def _optional_tool(name, package_name=None, tool_class_name=None, install_option TOOLS = { 'dodgy': DodgyTool, 'mccabe': McCabeTool, + 'mypy': MypyTool, 'pyflakes': PyFlakesTool, 'pep8': Pep8Tool, 'pylint': PylintTool, diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py new file mode 100644 index 00000000..74a689d5 --- /dev/null +++ b/prospector/tools/mypy/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +from mypy import api + +from prospector.tools import ToolBase + + +__all__ = ( + 'MypyTool', +) + + +class MypyTool(ToolBase): + + def __init__(self, *args, **kwargs): + super(MypyTool, self).__init__(*args, **kwargs) + self.checker = api + + def run(self, found_files): + import pdb ; pdb.set_trace() + mypy = self.checker.run(found_files) \ No newline at end of file From 8d48a3d745c0ba4b0a8a247c0c02cafef52f9e89 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 16:37:09 -0300 Subject: [PATCH 04/16] Added @chocoelho entry to CONTRIBUTORS --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 685452fe..b74f3c2c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -6,3 +6,4 @@ Contributors * Jeff Quast ([@jquast](https://github.com/jquast)) * Sam Spilsbury ([@smspillaz](https://github.com/smspillaz)) * Jose Antonio Perdiguero ([@PeRDy](https://github.com/PeRDy)) +* Carlos Coelho ([@chocoelho](https://github.com/chocoelho)) From 74fb45b53e8ab09ba3a970d36f4ade2da0053047 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 17:54:14 -0300 Subject: [PATCH 05/16] Format mypy messages into proper prospector messages --- prospector/tools/mypy/__init__.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index 74a689d5..d79e7c09 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -3,6 +3,7 @@ from mypy import api +from prospector.message import Location, Message from prospector.tools import ToolBase @@ -16,7 +17,30 @@ class MypyTool(ToolBase): def __init__(self, *args, **kwargs): super(MypyTool, self).__init__(*args, **kwargs) self.checker = api + self.options = ['--show-column-numbers'] def run(self, found_files): - import pdb ; pdb.set_trace() - mypy = self.checker.run(found_files) \ No newline at end of file + paths = [path for path in found_files.iter_module_paths()] + paths.extend(self.options) + report, err, status = self.checker.run(paths) + messages = [] + + for message in report.splitlines(): + path, line, char, err_type, *err_msg = message.split(':') + location = Location( + path=path, + module=None, + function=None, + line=line, + character=char, + absolute_path=True + ) + message = Message( + source='mypy', + code=err_type, + location=location, + message=''.join(err_msg).strip() + ) + messages.append(message) + + return messages \ No newline at end of file From 932ce4b09ef7e38c92dc3ed65bc616bfb6e153d5 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 18:39:06 -0300 Subject: [PATCH 06/16] Removed unneeded vars --- prospector/tools/mypy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index d79e7c09..0e5ed2e9 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs): def run(self, found_files): paths = [path for path in found_files.iter_module_paths()] paths.extend(self.options) - report, err, status = self.checker.run(paths) + report, *_ = self.checker.run(paths) messages = [] for message in report.splitlines(): From 587ecb7959db491792e3f536c9fd56555fb71c2b Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 18:56:56 -0300 Subject: [PATCH 07/16] Added support for mypy cmd options --- .prospector.yml | 3 ++ prospector/tools/mypy/__init__.py | 48 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/.prospector.yml b/.prospector.yml index 20e3f6f2..ba374ad0 100644 --- a/.prospector.yml +++ b/.prospector.yml @@ -16,6 +16,9 @@ pyroma: mypy: run: true + options: + ignore-missing-imports: true + follow-imports: skip pylint: disable: diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index 0e5ed2e9..f2491895 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -19,6 +19,54 @@ def __init__(self, *args, **kwargs): self.checker = api self.options = ['--show-column-numbers'] + def configure(self, prospector_config, _): + options = prospector_config.tool_options('mypy') + + follow_imports = options.get('follow-imports', 'normal') + ignore_missing_imports = options.get('ignore-missing-imports', False) + implict_optional = options.get('implict-optional', False) + python_2_mode = options.get('python-2-mode', False) + strict_optional = options.get('strict-optional', False) + + allowed_options = options.get('allow', []) + check_options = options.get('check', []) + disallowed_options = options.get('disallow', []) + no_check_options = options.get('no-check', []) + no_warn_options = options.get('no-warn', []) + warn_options = options.get('warn', []) + + self.options.append('--follow-imports=%s' % follow_imports) + + if ignore_missing_imports: + self.options.append('--ignore-missing-imports') + + if implict_optional: + self.options.append('--implict-optional') + + if python_2_mode: + self.options.append('--py2') + + if strict_optional: + self.options.append('--strict-optional') + + for entry in allowed_options: + self.options.append('--allow-%s' % entry) + + for entry in check_options: + self.options.append('--check-%s' % entry) + + for entry in disallowed_options: + self.options.append('--disallow-%s' % entry) + + for entry in no_check_options: + self.options.append('--no-check-%s' % entry) + + for entry in no_warn_options: + self.options.append('--no-warn-%s' % entry) + + for entry in warn_options: + self.options.append('--warn-%s' % entry) + def run(self, found_files): paths = [path for path in found_files.iter_module_paths()] paths.extend(self.options) From 839c63dad4b099238532176c2c789281be5b2032 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 19:00:06 -0300 Subject: [PATCH 08/16] Added .nodeids to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index baf4087c..f96f5f26 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ pip-log.txt .coverage .tox nosetests.xml +.noseids # Translations *.mo From 3d96e052dd0fbc6bfa4abc2c0705b75c50ac3f2a Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 19:28:22 -0300 Subject: [PATCH 09/16] Refactored list options for mypy --- prospector/tools/mypy/__init__.py | 35 ++++++++++--------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index f2491895..1d282d13 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -13,6 +13,14 @@ class MypyTool(ToolBase): + LIST_OPTIONS = [ + 'allow', + 'check', + 'disallow', + 'no-check', + 'no-warn', + 'warn' + ] def __init__(self, *args, **kwargs): super(MypyTool, self).__init__(*args, **kwargs) @@ -28,13 +36,6 @@ def configure(self, prospector_config, _): python_2_mode = options.get('python-2-mode', False) strict_optional = options.get('strict-optional', False) - allowed_options = options.get('allow', []) - check_options = options.get('check', []) - disallowed_options = options.get('disallow', []) - no_check_options = options.get('no-check', []) - no_warn_options = options.get('no-warn', []) - warn_options = options.get('warn', []) - self.options.append('--follow-imports=%s' % follow_imports) if ignore_missing_imports: @@ -49,23 +50,9 @@ def configure(self, prospector_config, _): if strict_optional: self.options.append('--strict-optional') - for entry in allowed_options: - self.options.append('--allow-%s' % entry) - - for entry in check_options: - self.options.append('--check-%s' % entry) - - for entry in disallowed_options: - self.options.append('--disallow-%s' % entry) - - for entry in no_check_options: - self.options.append('--no-check-%s' % entry) - - for entry in no_warn_options: - self.options.append('--no-warn-%s' % entry) - - for entry in warn_options: - self.options.append('--warn-%s' % entry) + for list_option in self.LIST_OPTIONS: + for entry in options.get(list_option, []): + self.options.append('--%s-%s' % (list_option, entry)) def run(self, found_files): paths = [path for path in found_files.iter_module_paths()] From e6a17be0c0b62bb1df46d636095e2c4db6ff6be0 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 19:41:57 -0300 Subject: [PATCH 10/16] Fixed star unpacking to be Python 2 compatible --- prospector/tools/mypy/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index 1d282d13..8a0f3f99 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import - +from itertools import islice from mypy import api from prospector.message import Location, Message @@ -57,11 +56,13 @@ def configure(self, prospector_config, _): def run(self, found_files): paths = [path for path in found_files.iter_module_paths()] paths.extend(self.options) - report, *_ = self.checker.run(paths) + result = self.checker.run(paths) + report, _ = result[0], result[1:] messages = [] for message in report.splitlines(): - path, line, char, err_type, *err_msg = message.split(':') + iter_message = iter(message.split(':')) + (path, line, char, err_type), err_msg = islice(iter_message, 4), list(message) location = Location( path=path, module=None, From f47fdb7601f95a7b52a88469a303c5a35a957df0 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 19:42:21 -0300 Subject: [PATCH 11/16] Made mypy an optional --- prospector/tools/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prospector/tools/__init__.py b/prospector/tools/__init__.py index 1e3ae655..43c5c75a 100644 --- a/prospector/tools/__init__.py +++ b/prospector/tools/__init__.py @@ -2,7 +2,6 @@ from prospector.exceptions import FatalProspectorException from prospector.tools.base import ToolBase from prospector.tools.dodgy import DodgyTool -from prospector.tools.mypy import MypyTool from prospector.tools.pep8 import Pep8Tool from prospector.tools.pyflakes import PyFlakesTool from prospector.tools.pylint import PylintTool @@ -39,7 +38,6 @@ def _optional_tool(name, package_name=None, tool_class_name=None, install_option TOOLS = { 'dodgy': DodgyTool, 'mccabe': McCabeTool, - 'mypy': MypyTool, 'pyflakes': PyFlakesTool, 'pep8': Pep8Tool, 'pylint': PylintTool, @@ -48,6 +46,7 @@ def _optional_tool(name, package_name=None, tool_class_name=None, install_option 'frosted': _optional_tool('frosted'), 'vulture': _optional_tool('vulture'), 'pyroma': _optional_tool('pyroma'), + 'mypy': _optional_tool('mypy'), } From a83a06b4710c55732952b275eb7f45c9790dfe44 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 20:04:22 -0300 Subject: [PATCH 12/16] Using MYPY_OPTIONS instead of LIST_OPTIONS --- prospector/tools/mypy/__init__.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index 8a0f3f99..6d0805ad 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -11,16 +11,17 @@ ) -class MypyTool(ToolBase): - LIST_OPTIONS = [ - 'allow', - 'check', - 'disallow', - 'no-check', - 'no-warn', - 'warn' - ] +MYPY_OPTIONS = [ + 'allow', + 'check', + 'disallow', + 'no-check', + 'no-warn', + 'warn' +] + +class MypyTool(ToolBase): def __init__(self, *args, **kwargs): super(MypyTool, self).__init__(*args, **kwargs) self.checker = api @@ -49,7 +50,7 @@ def configure(self, prospector_config, _): if strict_optional: self.options.append('--strict-optional') - for list_option in self.LIST_OPTIONS: + for list_option in MYPY_OPTIONS: for entry in options.get(list_option, []): self.options.append('--%s-%s' % (list_option, entry)) From fe30c8a8786c4a21db1288b18102d325fbda3eb4 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Sat, 12 Aug 2017 20:07:18 -0300 Subject: [PATCH 13/16] Fixed mypy doc text --- docs/supported_tools.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/supported_tools.rst b/docs/supported_tools.rst index caa6b613..6c950a33 100644 --- a/docs/supported_tools.rst +++ b/docs/supported_tools.rst @@ -157,10 +157,10 @@ To install and use:: `mypy `_ `````````````````````````````````````````````````````` -Frosted is a fork of pyflakes which was created with the intention of taking over -from and extending pyflakes as development had slowed. Since Prospector was originally -created, pyflakes development has started up again and frosted has stagnated, so it has -been demoted to be an optional extra. +Mypy is an experimental optional static type checker for Python that aims to combine +the benefits of dynamic (or "duck") typing and static typing. Mypy combines the +expressive power and convenience of Python with a powerful type system and +compile-time type checking. To install and use:: From 56afa91a88de695863a686c3f2ef9051aafdd6f9 Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Tue, 15 Aug 2017 00:58:52 -0300 Subject: [PATCH 14/16] Add mypy support only if Python version is higher or equals 3.3 --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f6c1baec..9048bd76 100644 --- a/setup.py +++ b/setup.py @@ -60,9 +60,12 @@ _OPTIONAL = { 'with_frosted': ('frosted>=1.4.1',), 'with_vulture': ('vulture>=0.6',), - 'with_pyroma': ('pyroma==2.0.2',), - 'with_mypy': ('mypy>=0.521',) + 'with_pyroma': ('pyroma==2.0.2',) } + +if sys.version_info >= (3, 3): + _OPTIONAL['with_mypy'] = ('mypy>=0.521',) + with_everything = [req for req_list in _OPTIONAL.values() for req in req_list] _OPTIONAL['with_everything'] = sorted(with_everything) From 1fc10d276c26962616fc8592b93a74e8831bb9de Mon Sep 17 00:00:00 2001 From: Carlos Coelho Date: Tue, 15 Aug 2017 01:07:06 -0300 Subject: [PATCH 15/16] Added support for python-version and platform mypy arguments --- prospector/tools/mypy/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prospector/tools/mypy/__init__.py b/prospector/tools/mypy/__init__.py index 6d0805ad..520c56d0 100644 --- a/prospector/tools/mypy/__init__.py +++ b/prospector/tools/mypy/__init__.py @@ -33,7 +33,9 @@ def configure(self, prospector_config, _): follow_imports = options.get('follow-imports', 'normal') ignore_missing_imports = options.get('ignore-missing-imports', False) implict_optional = options.get('implict-optional', False) + platform = options.get('platform', None) python_2_mode = options.get('python-2-mode', False) + python_version = options.get('python-version', None) strict_optional = options.get('strict-optional', False) self.options.append('--follow-imports=%s' % follow_imports) @@ -44,9 +46,15 @@ def configure(self, prospector_config, _): if implict_optional: self.options.append('--implict-optional') + if platform: + self.options.append('--platform %s' % platform) + if python_2_mode: self.options.append('--py2') + if python_version: + self.options.append('--python-version %s' % python_version) + if strict_optional: self.options.append('--strict-optional') From 2631f76d44d4fc3576c0763f7a741c747970c2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Co=C3=AAlho?= Date: Mon, 28 May 2018 13:12:56 -0300 Subject: [PATCH 16/16] Update mypy dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Coêlho --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d01f4ce3..e364a663 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ } if sys.version_info >= (3, 3): - _OPTIONAL['with_mypy'] = ('mypy>=0.521',) + _OPTIONAL['with_mypy'] = ('mypy>=0.600',) with_everything = [req for req_list in _OPTIONAL.values() for req in req_list] _OPTIONAL['with_everything'] = sorted(with_everything)