Friday, May 31, 2019

Wingware Blog: Using External Code Quality Checkers with Wing Pro 7

Wing Pro 7 introduced a new code warnings system with expanded built-in code inspection capabilities and improved integration with external code quality checkers. In this issue of Wing Tips, we describe how to configure Wing Pro 7 to take advantage of external code quality checkers like Pylint, pep8, and mypy.

Pylint is a powerful general-purpose code quality checker that flags a wide variety of real code errors and stylistic issues, pep8 checks compliance with the PEP 8 Style Guide for Python Code, and mypy is a type checker for Python 3 code that makes use of optional static type declarations.

Installing the External Checkers

If you need to install Pylint, pep8, or mypy, you can do this on the command line outside of Wing like this:

pip install pylint

Or if you are using Anaconda, you should use conda instead:

conda install pylint

The package name for the other two checkers are pep8 and mypy.

A quick way to see whether the checkers are properly installed is to attempt to import them in Wing's Python Shell tool:

>>> import pylint
>>> import pep8
>>> import mypy

If you need to change which Python installation Wing uses, set the Python Executable under the Environment tab in Project Properties, from the Project menu, to the value produced by import sys; print(sys.executable) in the Python interpreter that you want to use. Then restart Wing's Python Shell from its Options menu.

Configuring External Checkers

Once the checkers you plan to use are installed, you can enable them in Wing Pro's Code Warnings tool, from the Tools menu. Click on the Configuration tab, check on Enable external checkers, and then press the Configure button. This displays a dialog like this:

/images/blog/external-checkers/conf-dialog.png

Here you can check on Enable for each of the external checkers that you want to use with your project, and select some options for when and how they are run. In most cases the default configuration will work. Wing will run the checker when a file is opened and re-run it each time the file is saved. For Pylint, you can select whether Wing will display only errors, or also warnings and informational messages.

Notice that Wing avoids running the checkers on source files above the configured Maximum File Size, in order to avoid overly lengthy CPU-intensive computation.

Using the Checkers

Once this is done, Wing will interleave errors and warnings found by the enabled checkers into its own warnings in the Code Warnings tool:

/images/blog/external-checkers/warnings-tool.png

Warnings are also shown on the editor, using indicators that can be configured with the Editor > Code Warnings preferences group. Hovering the mouse over an indicator in the editor displays the warning in a tooltip:

/images/blog/external-checkers/editor-indicators.png

Filtering Out Warnings

Checkers like Pylint can produce lots of stylistic warnings that may not be relevant to your development team's coding standards. These can be a distraction, making it harder to see real problems in code.

Wing lets you quickly hide incorrect or uninteresting warnings by clicking on the red x icon that appears when you mouse over items in the Code Warnings tool.

For external checkers like Pylint and pep8, this hides all warnings of that type, by adding a rule to Removed from any file section under the Configuration tab in the Code Warnings tool:

/images/blog/external-checkers/remove-warnings.png

In this way, you should be able to drill down quickly to just the warnings that you are interested in.

You can export code warnings configurations or set the location Wing writes the configuration from the Options menu in the Code Warnings tool. This lets you share warnings configurations with other users or projects, for example by checking the configuration into revision control.

Recommendations

If you are required to write PEP 8 compatible code, enabling Wing's PEP 8 Reformatting feature may be preferable to using the pep8 code checker. This can reformat entire files or just the parts that you edit.

We encourage you to think carefully about how you use code checkers. While they do find errors early and can improve code quality, they may also lead to polishing that takes more time than it is worth. We've tried to design Wing's integration with external code checkers in a way that supports quick customization, so you can focus on the issues that you care about.



That's it for now! We'll be back next week with more Wing Tips for Wing Python IDE.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...