Using Pylint to check your code

Pylint (https://www.pylint.org/) is a static code checker for Python. There is a very interesting project called pylint-odoo, which provides a Pylint plugin to perform Odoo-specific checks. To install, run the following command, preferably in a virtual environment:

$ pip3 install --upgrade --pre pylint-odoo

When this is done, you can check your addon module with the following command:

$ pylint --load-plugins=pylint_odoo -rn -e epylint <path_to_the_addon_directory>

This will produce an output such as the following:

********** Module my_module
C: 1, 0: Missing ./README.rst file. Template here: https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst (missing-readme)
************* Module my_module.__manifest__
C: 2, 0: Missing author required "Odoo Community Association (OCA)" in manifest file (manifest-required-author)
C: 2, 0: Deprecated key "description" in manifest file (manifest-deprecated-key)
************* Module my_module.models.library_book
W: 14,12: The attribute string is redundant. String parameter equal to name of variable (attribute-string-redundant)

The README file on https://github.com/OCA/pylint-odoo/blob/master/README.rst of the module will give you an up-to-date list of checks performed by the tool. Then, you can use Pylint's command-line options to tune the output. For instance, if you are not interested in the missing author check, which is specific to the Odoo Community Association, you can remove the check by checking the message ID in the README (it is C8101) and passing it to the -d or --disable command-line option like this:

$ pylint --load-plugin=pylint_odoo -rn -e epylint -d C8101  <path_to_the_addon_directory>

It is possible to store the command-line options you pass to Pylint in a configuration file to ease your daily work.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.91