Overview#

Pylint provides static analysis of Python code.

Installation#

To install Pylint:

$ yum install pylint

To install Pylint GUI:

$ yum install pylint-gui

See also:

Usage#

$ pylint ``\ `` <Source directories/files ...>

For scanning the python modules using pylint the absolute path where the modules are present (the source folder path) has to be included in the PYTHONPATH variable or just by providing the absolute path of the directories or files of the python modules when executing the command.

By default, the report is printed to the console as text. But a module wise report files can be generated by using the option –files-output=y.

Eclipse#

PyDev is a plugin for Eclipse which provides a Python/ Jython/ Iron Python development environment.

Setting up PyDev#

Helpful information for writing code in a PyDev environment : Features and their Hotkeys

Configuring Pylint in PyDev#

  • Goto Window -> Preferences in Eclipse.

  • Expand PyDev option in the left side menu.

  • Click on Pylint and configure.

  • Configuring Pylint with PyDev

  • Goto Project -> Properties.

  • Click on PyDev-PYTHONPATH. Add the source folders with python code to the path.

After setting up the environment, clean the project to scan the code. All features of PyDev like Code Analysis, Code formatting etc. can be viewed by right clicking on the and selecting PyDev option.

Pylint Report#

Report
======
3491 statements analysed.
Duplication
-----------
+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |246   |246      |=          |
+-------------------------+------+---------+-----------+
|percent duplicated lines |3.406 |3.406    |=          |
``+————————-+——+———+———–+ ``
Messages by category
--------------------
+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |596    |596      |=          |
+-----------+-------+---------+-----------+
|refactor   |143    |143      |=          |
+-----------+-------+---------+-----------+
|warning    |204    |204      |=          |
+-----------+-------+---------+-----------+
|error      |270    |270      |=          |
+-----------+-------+---------+-----------+
% errors / warnings by module
-----------------------------
+---------------------------------+------+--------+---------+-----------+
|module                           |error |warning |refactor |convention |
+=================================+======+========+=========+===========+
|deployment.instance_layout       |22.59 |2.94    |0.00     |0.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.pkihelper             |12.96 |34.31   |83.92    |29.87      |
+---------------------------------+------+--------+---------+-----------+
|deployment.subsystem_layout      |11.48 |2.45    |0.00     |0.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.configuration         |9.63  |3.43    |0.70     |0.67       |
+---------------------------------+------+--------+---------+-----------+
|deployment.webapp_deployment     |8.52  |2.94    |0.00     |0.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.security_databases    |8.52  |2.45    |0.00     |0.50       |
+---------------------------------+------+--------+---------+-----------+
|deployment.initialization        |7.41  |2.94    |0.00     |0.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.finalization          |5.93  |2.94    |0.00     |0.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.infrastructure_layout |5.56  |2.94    |0.00     |1.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.slot_substitution     |4.44  |3.43    |0.00     |0.34       |
+---------------------------------+------+--------+---------+-----------+
|deployment.pkiparser             |1.48  |9.80    |2.80     |34.90      |
+---------------------------------+------+--------+---------+-----------+
|deployment.selinux_setup         |1.48  |3.43    |0.70     |4.87       |
+---------------------------------+------+--------+---------+-----------+
|                                 |0.00  |12.25   |0.70     |3.69       |
+---------------------------------+------+--------+---------+-----------+
|deployment.pkimanifest           |0.00  |7.35    |2.10     |2.52       |
+---------------------------------+------+--------+---------+-----------+
|server.upgrade                   |0.00  |2.45    |6.29     |7.05       |
+---------------------------------+------+--------+---------+-----------+
|deployment.pkilogging            |0.00  |1.96    |0.00     |0.84       |
+---------------------------------+------+--------+---------+-----------+
|deployment.pkimessages           |0.00  |0.98    |0.00     |4.53       |
+---------------------------------+------+--------+---------+-----------+
|server                           |0.00  |0.49    |1.40     |1.51       |
+---------------------------------+------+--------+---------+-----------+
|deployment.pkiconfig             |0.00  |0.49    |0.00     |5.20       |
``+———————————+——+——–+———+———–+   ``
Messages
--------
+-----------+------------+
|message id |occurrences |
+===========+============+
|E1120      |254         |
+-----------+------------+
|C0111      |176         |
+-----------+------------+
|C0323      |156         |
+-----------+------------+
|C0103      |148         |
+-----------+------------+
|C0301      |88          |
+-----------+------------+
|R0201      |72          |
+-----------+------------+
|W0403      |65          |
+-----------+------------+
|W1401      |37          |
+-----------+------------+
|R0913      |25          |
+-----------+------------+
|R0912      |20          |
+-----------+------------+
|W0232      |16          |
+-----------+------------+
|W0622      |14          |
+-----------+------------+
|E0602      |13          |
+-----------+------------+
|W0612      |12          |
+-----------+------------+
|W0201      |12          |
+-----------+------------+
|C0322      |11          |
+-----------+------------+
|W0311      |10          |
+-----------+------------+
|R0801      |8           |
+-----------+------------+
|C0321      |8           |
+-----------+------------+
|W0621      |7           |
+-----------+------------+
|C0324      |7           |
+-----------+------------+
|W0301      |6           |
+-----------+------------+
|R0903      |6           |
+-----------+------------+
|W0611      |5           |
+-----------+------------+
|W0511      |5           |
+-----------+------------+
|R0915      |5           |
+-----------+------------+
|R0914      |5           |
+-----------+------------+
|W0104      |4           |
+-----------+------------+
|W0221      |3           |
+-----------+------------+
|E1101      |3           |
+-----------+------------+
|W0402      |2           |
+-----------+------------+
|W0212      |2           |
+-----------+------------+
|C0302      |2           |
+-----------+------------+
|W0613      |1           |
+-----------+------------+
|W0602      |1           |
+-----------+------------+
|W0404      |1           |
+-----------+------------+
|W0105      |1           |
+-----------+------------+
|R0924      |1           |
+-----------+------------+
|R0902      |1           |
``+———–+————+ ``
Global evaluation
-----------------
``Your code has been rated at 3.43/10 (previous run: 3.43/10) ``
Statistics by type
------------------
+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |21     |21         |=          |0.00        |4.76     |
+---------+-------+-----------+-----------+------------+---------+
|class    |36     |36         |=          |0.00        |47.22    |
+---------+-------+-----------+-----------+------------+---------+
|method   |158    |158        |=          |29.11       |3.16     |
+---------+-------+-----------+-----------+------------+---------+
|function |8      |8          |=          |12.50       |25.00    |
``+———+——-+———–+———–+————+———+ ``
`` ``
External dependencies
---------------------
``:: ``
``   deployment ``
``     -pkiconfig (deployment.selinux_setup,deployment.configuration,deployment.finalization,deployment.infrastructure_layout,deployment.instance_layout,deployment.webapp_deployment,deployment.security_databases,deployment.subsystem_layout,deployment.pkimanifest,deployment.pkihelper,deployment.initialization,deployment.pkiparser,deployment.slot_substitution)``
``     | -pki_master_dict (deployment.configuration,deployment.finalization,deployment.infrastructure_layout,deployment.instance_layout,deployment.webapp_deployment,deployment.security_databases,deployment.subsystem_layout,deployment.selinux_setup,deployment.pkihelper,deployment.initialization,deployment.slot_substitution)``
``     | -pki_selinux_config_ports (deployment.pkihelper,deployment.selinux_setup)``
``     | -pki_slots_dict (deployment.pkihelper,deployment.slot_substitution)``
``     -pkihelper (deployment.configuration,deployment.finalization,deployment.infrastructure_layout,deployment.instance_layout,deployment.webapp_deployment,deployment.security_databases,deployment.subsystem_layout,deployment.selinux_setup,deployment.initialization,deployment.slot_substitution)``
``     -pkilogging (deployment.pkiparser)``
``     -pkimanifest (deployment.finalization,deployment.pkihelper)``
``     -pkimessages (deployment.selinux_setup,deployment.configuration,deployment.finalization,deployment.infrastructure_layout,deployment.instance_layout,deployment.webapp_deployment,deployment.security_databases,deployment.subsystem_layout,deployment.pkimanifest,deployment.pkihelper,deployment.initialization,deployment.pkiparser,deployment.slot_substitution)``
``     -pkiparser ``
``     | -PKIConfigParser (deployment.pkihelper)``
``     -pkiscriptlet (deployment.configuration,deployment.finalization,deployment.infrastructure_layout,deployment.instance_layout,deployment.webapp_deployment,deployment.security_databases,deployment.subsystem_layout,deployment.selinux_setup,deployment.initialization,deployment.slot_substitution)``
``   ldap (deployment.pkiparser)``
``   pki (server.upgrade,deployment.pkiparser,server)``
``     -account (deployment.pkiparser,deployment.pkihelper)``
``     -client (deployment.pkiparser,deployment.pkihelper)``
``     -encoder (deployment.configuration)``
``     -server (server.upgrade)``
``     -system (deployment.configuration,deployment.pkiparser,deployment.pkihelper)``
``     -upgrade (server.upgrade,deployment.pkiparser)``
``       -verbose (server.upgrade)``
``   requests (deployment.pkiparser,deployment.pkihelper)``
``   selinux (deployment.pkihelper,deployment.selinux_setup)``
``   seobject (deployment.pkihelper,deployment.selinux_setup)``
``  ``
Raw metrics
-----------
+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |4925   |73.45 |4925     |=          |
+----------+-------+------+---------+-----------+
|docstring |446    |6.65  |446      |=          |
+----------+-------+------+---------+-----------+
|comment   |854    |12.74 |854      |=          |
+----------+-------+------+---------+-----------+
|empty     |480    |7.16  |480      |=          |
+----------+-------+------+---------+-----------+

Pylint Messages#

To list all messages:

$ pylint --list-msgs

To display a specific message:

``$ pylint –help-msg ``

See also:

Ignoring Pylint Warnings/Errors#

from six.moves import input   # pylint: disable=W0622,F0401

References#