8000 New release - 1.0 by carlio · Pull Request #261 · prospector-dev/prospector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

New release - 1.0 #261

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

Merged
merged 33 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1794318
Added mypy to installed packages
chocoelho Aug 12, 2017
3d4e34e
Added mypy reference to documentation
chocoelho Aug 12, 2017
53154c8
Started mypy prospector tool support
chocoelho Aug 12, 2017
8d48a3d
Added @chocoelho entry to CONTRIBUTORS
chocoelho Aug 12, 2017
74fb45b
Format mypy messages into proper prospector messages
chocoelho Aug 12, 2017
932ce4b
Removed unneeded vars
chocoelho Aug 12, 2017
587ecb7
Added support for mypy cmd options
chocoelho Aug 12, 2017
839c63d
Added .nodeids to gitignore
chocoelho Aug 12, 2017
3d96e05
Refactored list options for mypy
chocoelho Aug 12, 2017
e6a17be
Fixed star unpacking to be Python 2 compatible
chocoelho Aug 12, 2017
f47fdb7
Made mypy an optional
chocoelho Aug 12, 2017
a83a06b
Using MYPY_OPTIONS instead of LIST_OPTIONS
chocoelho Aug 12, 2017
8000
fe30c8a
Fixed mypy doc text
chocoelho Aug 12, 2017
56afa91
Add mypy support only if Python version is higher or equals 3.3
chocoelho Aug 15, 2017
1fc10d2
Added support for python-version and platform mypy arguments
chocoelho Aug 15, 2017
1451b1b
Add ability to set pylint config file path on prospector config file
chocoelho Apr 20, 2018
1f63bf7
Flag --pylint-config-file has priority over config_file set inside pr…
chocoelho Apr 20, 2018
6d24642
Ignore VS Code files
chocoelho Apr 20, 2018
421d534
Add custom type for output options
chocoelho Apr 20, 2018
4a099de
command line output format should use custom datatype
chocoelho Apr 20, 2018
7512e2d
Integrate new report format into output format
chocoelho Apr 20, 2018
f0aa24b
Provide default values for output_report
chocoelho Apr 20, 2018
037b7c9
Merge remote-tracking branch 'origin/develop' into mypy-support
chocoelho May 28, 2018
2631f76
Update mypy dependency
chocoelho May 28, 2018
30a6f1e
Merge remote-tracking branch 'origin/develop' into mypy-support
chocoelho May 28, 2018
2455f10
Merge pull request #249 from vintasoftware/pylint-config
carlio Jul 22, 2018
f219943
Merge pull request #228 from vintasoftware/mypy-support
carlio Jul 22, 2018
232db3d
Merge pull request #250 from vintasoftware/feature-write-to-file
carlio Jul 22, 2018
f6a8a9c
Removing support for deprecated python 3.3 and bumping requirements-d…
Jul 22, 2018
910db9e
Attempting to make python versions match with supported pylint veresions
Jul 22, 2018
c7f3fc2
Attempting to make python versions match with supported pylint veresions
Jul 22, 2018
13214a0
Hanlding quiet flag in backwards compatible wy
Jul 22, 2018
b2b7e05
Finally thinking this might actually be stable enough :-)
Jul 22, 2018
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pip-log.txt
.coverage
.tox
nosetests.xml
.noseids

# Translations
*.mo
Expand All @@ -31,9 +32,13 @@ nosetests.xml
.project
.pydevproject
.idea
.vscode

# Sphinx
docs/_build

# Mypy
.mypy_cache

# emacs
TAGS
6 changes: 6 additions & 0 deletions .prospector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ frosted:
pyroma:
run: true

mypy:
run: true
options:
ignore-missing-imports: true
follow-imports: skip

pylint:
disable:
- bad-builtin
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ language: python
sudo: false
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.6-dev"
- "3.7-dev"
install:
- "pip install nose coverage coveralls mock"
Expand Down
29 changes: 21 additions & 8 deletions docs/supported_tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Prospector will run with defaults enabled and optional extras disabled unless co

To specify an exact list of tools to run, for example, only pylint and pep8::

prospector --tool pylint --tool pep8
prospector --tool pylint --tool pep8

Note that this command line option will override values set in :doc:`profiles<profiles>`.

Expand All @@ -35,11 +35,11 @@ and is the source of most messages that prospector outputs.
`pep8.py <https://pep8.readthedocs.io/>`_
```````````````````````````````````````````````````

``pep8.py`` is a simple tool to warn about violations of the
``pep8.py`` is a simple tool to warn about violations of the
`PEP8 style guide <https://www.python.org/dev/peps/pep-0008/>`_. It produces
messages for any divergence from the style guide.

Prospector's concept of :doc:`strictness <profiles>` turns off various warnings
Prospector's concept of :doc:`strictness <profiles>` turns off various warnings
depending on the strictness level. By default, several PEP8 errors will be
supressed. To adjust this without adjusting the strictness of other tools, you have
some options::
Expand All @@ -50,7 +50,7 @@ some options::
# turn on complete pep8 checking:
prospector --full-pep8

# change the maximum line length allowed
# change the maximum line length allowed
# (the default varies by strictness):
prospector --max-line-length 120

Expand All @@ -75,7 +75,7 @@ methods.
```````````````````````````````````````````````

Dodgy is a very simple tool designed to find 'dodgy' things which should
not be in a public project, such as secret keys, passwords, AWS tokens or
not be in a public project, such as secret keys, passwords, AWS tokens or
source control diffs.

`pydocstyle <https://github.com/PyCQA/pydocstyle>`_
Expand Down Expand Up @@ -109,7 +109,7 @@ Optional Extras
These extras are integrated into prospector but are not activated by default.
This is because their output is not necessarily useful for all projects.

They are also not installed by default. The instructions for installing each tool is in the tool
They are also not installed by default. The instructions for installing each tool is in the tool
section below. To install all extras at the same time, install prospector using the ``with_everything`` option::

pip install prospector[with_everything]
Expand All @@ -118,7 +118,7 @@ section below. To install all extras at the same time, install prospector using
`Pyroma <https://github.com/regebro/pyroma>`_
````````````````````````````````````````````````
Pyroma is a tool to check your `setup.py` to ensure it is following best practices
of the Python packaging ecosystem. It will warn you if you are missing any package
of the Python packaging ecosystem. It will warn you if you are missing any package
metadata which would improve the quality of your package. This is recommended if you
intend to publish your code on PyPI.

Expand All @@ -133,7 +133,7 @@ To install and use::

Vulture finds unused classes, functions and variables in your code. This could
be useful if your project is an application rather than a library, however, if
you do a lot of dynamic access or metaprogramming, Vulture will likely warn
you do a lot of dynamic access or metaprogramming, Vulture will likely warn
about unused code that is in fact used.

To install and use::
Expand All @@ -153,3 +153,16 @@ To install and use::

pip install prospector[with_frosted]
prospector --with-tool frosted


`mypy <https://github.com/python/mypy>`_
``````````````````````````````````````````````````````
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 9E81 power and convenience of Python with a powerful type system and
compile-time type checking.

To install and use::

pip install prospector[with_mypy]
prospector --with-tool mypy
2 changes: 1 addition & 1 deletion prospector/__pkginfo__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
__version_info__ = (0, 12, 11)
__version_info__ = (1, 0)
__version__ = '.'.join(map(str, __version_info__))
12 changes: 6 additions & 6 deletions prospector/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ def get_tools(self, found_files):
runners.append(tool)
return runners

def get_output_format(self):
def get_output_report(self):
# Get the output formatter
if self.config.output_format is not None:
output_format = self.config.output_format
output_report = self.config.output_format
else:
output_format = self.profile.output_format
output_report = [(self.profile.output_format, self.profile.output_target or [])]

if output_format is None:
output_format = 'grouped'
if not all(output_report):
output_report = [('grouped', [])]

return output_format
return output_report

def _configure_prospector(self):
# first we will configure prospector as a whole
Expand Down
5 changes: 3 additions & 2 deletions prospector/config/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import setoptconf as soc
from prospector.__pkginfo__ import __version__
from prospector.config.datatype import OutputChoice
from prospector.formatters import FORMATTERS
from prospector.tools import DEFAULT_TOOLS, TOOLS

Expand Down Expand Up @@ -29,9 +30,9 @@ def build_manager():

manager.add(soc.BooleanSetting('messages_only', default=False))
manager.add(soc.BooleanSetting('summary_only', default=False))
manager.add(soc.ChoiceSetting(
manager.add(soc.ListSetting(
'output_format',
sorted(FORMATTERS.keys()),
OutputChoice(sorted(FORMATTERS.keys())),
default=None,
))
manager.add(soc.BooleanSetting('absolute_paths', default=False))
Expand Down
11 changes: 11 additions & 0 deletions prospector/config/datatype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from os import pathsep

from setoptconf.datatype import Choice


class OutputChoice(Choice):
def sanitize(self, value):
splitted_value = value.split(pathsep)
output_format, output_targets = splitted_value[0], splitted_value[1:]
validated_format = super(OutputChoice, self).sanitize(output_format)
return (output_format, output_targets)
2 changes: 2 additions & 0 deletions prospector/profiles/profile.py 10000
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, name, profile_dict, inherit_order):
)

self.output_format = profile_dict.get('output-format')
self.output_target = profile_dict.get('output-target')
self.autodetect = profile_dict.get('autodetect')
self.uses = [uses for uses in _ensure_list(profile_dict.get('uses', []))
if uses in ('django', 'celery', 'flask')]
Expand Down Expand Up @@ -92,6 +93,7 @@ def as_dict(self):
'ignore-paths': self.ignore_paths,
'ignore-patterns': self.ignore_patterns,
'output-format': self.output_format,
'output-file': self.output_file,
'autodetect': self.autodetect,
'uses': self.uses,
'max-line-length': self.max_line_length,
Expand Down
26 changes: 17 additions & 9 deletions prospector/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,28 @@ def get_summary(self):
def get_messages(self):
return self.messages

def print_messages(self, write_to=None):
write_to = write_to or sys.stdout

output_format = self.config.get_output_format()
self.summary['formatter'] = output_format
formatter = FORMATTERS[output_format](self.summary, self.messages, self.config.profile)

def print_messages(self):
output_reports = self.config.get_output_report()

for report in output_reports:
output_format, output_files = report
self.summary['formatter'] = output_format
formatter = FORMATTERS[output_format](self.summary, self.messages, self.config.profile)
if not output_files:
self.write_to(formatter, sys.stdout)
for output_file in output_files:
with open(output_file, 'w+') as target:
self.write_to(formatter, target)

def write_to(self, formatter, target):
# Produce the output
write_to.write(formatter.render(
target.write(formatter.render(
summary=not self.config.messages_only,
messages=not self.config.summary_only,
profile=self.config.show_profile
))
write_to.write('\n')
target.write('\n')



def get_parser():
Expand Down
1 change: 1 addition & 0 deletions prospector/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,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'),
}


Expand Down
91 changes: 91 additions & 0 deletions prospector/tools/mypy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
from itertools import islice
from mypy import api

from prospector.message import Location, Message
from prospector.tools import ToolBase


__all__ = (
'MypyTool',
)


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
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)
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)

if ignore_missing_imports:
self.options.append('--ignore-missing-imports')

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')

for list_option in MYPY_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()]
paths.extend(self.options)
result = self.checker.run(paths)
report, _ = result[0], result[1:]
messages = []

for message in report.splitlines():
iter_message = iter(message.split(':'))
(path, line, char, err_type), err_msg = islice(iter_message, 4), list(message)
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
6 changes: 5 additions & 1 deletion prospector/tools/pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ def configure(self, prospector_config, found_files):
linter = ProspectorLinter(found_files)
if prospector_config.use_external_config('pylint'):
# try to find a .pylintrc
pylintrc = prospector_config.external_config_location('pylint')
pylint_options = prospector_config.tool_options('pylint')
pylintrc = pylint_options.get('config_file')
external_config = prospector_config.external_config_location('pylint')
if pylintrc is None or external_config:
pylintrc = external_config
if pylintrc is None:
pylintrc = find_pylintrc()
if pylintrc is None:
Expand Down
10 changes: 8 additions & 2 deletions prospector/tools/pylint/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def __init__(self, found_files, *args, **kwargs):
def config_from_file(self, config_file=None):
"""Will return `True` if plugins have been loaded. For pylint>=1.5. Else `False`."""
if PYLINT_VERSION >= (1, 5):
self.read_config_file(config_file)
if PYLINT_VERSION >= (2, 0):
self.read_config_file(config_file, quiet=True)
else:
self.read_config_file(config_file)
if self.cfgfile_parser.has_option('MASTER', 'load-plugins'):
# pylint: disable=protected-access
plugins = _splitstrip(self.cfgfile_parser.get('MASTER', 'load-plugins'))
Expand All @@ -35,7 +38,10 @@ def reset_options(self):
# for example, we want to re-initialise the OptionsManagerMixin
# to supress the config error warning
# pylint: disable=non-parent-init-called
OptionsManagerMixIn.__init__(self, usage=PyLinter.__doc__, quiet=True)
if PYLINT_VERSION >= (2, 0):
OptionsManagerMixIn.__init__(self, usage=PyLinter.__doc__)
else:
OptionsManagerMixIn.__init__(self, usage=PyLinter.__doc__, quiet=True)

def expand_files(self, modules):
expanded = PyLinter.expand_files(self, modules)
Expand Down
Loading
0