Tuning Python analysis

Tuning allows you to make Python analysis respect specifics of the project and bring it closer to the project context. You can tune your python analysis by giving the parameters to the engine, so it can produce better analysis results about your code system.

The tuning mechanism is implemented by passing arguments to a particular <checker>. Every Python category section has a list of parameters that are supported by related checkers. You can define these parameters and import it into your project configuration.

Adding parameters and importing them into Klocwork involves the following steps:

  • Find the documentation of the checker that you want to tune.

  • Find the documentation of the relevant checker category; there is a list of parameters that can be tuned. If there are no parameters listed, then the checker cannot be tuned.

  • Create a '.pconf' checker configuration file and add parameters for the checker section that matches a category name. The parameter should be named with the arg- prefix.

  • Import the '.pconf' file into the project.


Let's tune the checker 'PY3.R0903':

1. The checker category is 'Design'. The 'Design' category has a number of parameters you can tune. Let's take the following two parameters and tune them:

  • exclude-too-few-public-methods (default: )
  • min-public-methods (default: 2)

2. Next, create 'python.pconf', with the above parameters included, and add your custom values ('abs.*' and '5'), as seen in the example below:

<?xml version="1.0" encoding="UTF-8"?>
<errors language="Python" version="1.4">
    <checker id="PY3.DESIGN">
        <parameter name="arg-exclude-too-few-public-methods" value="abs.*"/>
        <parameter name="arg-min-public-methods" value="5"/>

3. Import 'python.pconf' into your project. For example, using the kwadmin import-config command:

kwadmin import-config myProject C:\Klocwork\python.pconf