Tune Python analysis

This section explains how to tune Python analysis.

Give the parameters to the analysis engine so that it can produce better analysis results about your code system.

The tuning mechanism is implemented by passing arguments to a specific <error>. Each Python checker has a list of supported parameters. You can define these parameters, then import the definitions into your project configuration.

  1. To add parameters and import them into Klocwork, find the documentation for the relevant checker that you want to tune. There is a list of parameters that can be tuned. If there are no parameters listed, the checker cannot be tuned.
  2. Create a checker configuration (PCONF) file and add parameters for the checker section that matches a category name. The parameter should be named with the arg- prefix.

  3. Import the PCONF file into the project.

Example: Tune Python analysis

This example tunes the checker PY3.R0903.

  1. The category for the checker PY3.R0903 is Design, which includes the following parameters to tune:

    • exclude-too-few-public-methods (default: )
    • min-public-methods (default: 2)
  2. Create a python.pconf file and add the parameters above. Add the custom values abs.* and 5, as follows:

  3. <?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"/>
    	</checker>
    </errors>
  4. Import python.pconf into your project (for example, by using the kwadmin import-config command):

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

Example: Tune a disabled checker

To tune a disabled checker, import two PCONF files:

  • One to enable the error ID
  • One to provide the checker arguments

If the checker PY3.R0903 is disabled, follow these steps to tune it.

  1. Create two configuration files, for example:

    • enable_error_id.pconf:

    • <?xml version="1.0" encoding="UTF-8"?>
      <errors language="Python" version="1.4">
          <error enabled="true" id="PY3.R0903"/>
      </errors>
    • checker_params.pconf:

      <?xml version="1.0" encoding="UTF-8"?>
      <errors language="Python" version="1.4">
          <checker id="PY3.R0903">
              <parameter name="arg-exclude-too-few-public-methods" value="abs.*"/>
              <parameter name="arg-min-public-methods" value="5"/>
          </checker>
      </errors>
  2. To merge the two PCONF files, run the import command with the --merge-config option:

    kwadmin import-config <project-name> enable_error_id.pconf					
    kwadmin import-config <project-name> checker_params.pconf --merge-config