Configuring pylint

It is possible to incorporate pylint results in the TICS output for files. pylint is a static analyzer for Python.

Prerequisites

For a successful pylint integration, the following prerequisites must be met:

Basic configuration

As of TICS 2019.3, both Python 2 and 3 are supported. Specifically the following packages are tested with TICS: Python 2.7 pylint 1.6 and Python 3.6 pylint 2.3.

By default, TICS attempts to find pylint on the PATH. Alternatively, a specific Python interpreter and/or a specific pylint instance can be used.

The configuration for pylint can be added to either the SERVER.yaml to apply them for all projects, or in PROJECTS.yaml to enable project-specific settings. If the properties are declared in the SERVER file and also in the PROJECT file, the project-specific properties will override the global properties.

Syntax

The following properties can (optionally) be declared, either on SERVER or PROJECT level:

TOOLS:
  pylint:
    INTERPRETER: '/path/to/python'
    INSTALLDIR: '/path/to/directory'
    PYTHONPATH: ['/some/path/to/include', '/another/path']

Specifying a Python interpreter

The INTERPRETER property can be used to specify the path to a Python interpreter, such as /usr/bin/python. If this property is not set, TICS will attempt to find an interpreter from the configured locations in SERVER/PROJECTS.yaml or the client's environment.

Note that the Python interpreter has an effect on the violations that are produced by pylint. It is recommended to use the interpreter in which the project is supposed to run.

Specifying an installation dir

As an alternative to specifying a Python interpreter, an installation directory can be set through the INSTALLDIR property. This installation directory can either be a full Python installation containing pylint, or a virtual environment with access to pylint.

The installation directory can be specified either as an absolute path (e.g., /usr/local/python), or as a relative path from the chk directory (e.g., pylint).

Specifying additions to the PYTHONPATH

The PYTHONPATH property can be used to extend the python path with directories containing libraries. This property should be a list of paths. All of these will be prepended to the PYTHONPATH environment variable before running pylint.

These paths can be absolute (e.g., /usr/lib/python3.6), but they can be specified relative to the directory in which the project is located. To achieve this, start a path with BRANCH_DIR, e.g., BRANCH_DIR/env/lib.

More information about the PYTHONPATH environment variable can be found in the Python documentation.

Rule parameterization

Pylint rule parameters (options) can be configured by specifying them in the IMPL.txt. The following should be followed to parameterize rules in the IMPL.txt:

When options are configured in IMPL.txt, TICS will generate a pylintrc file and it will be used to run Pylint. In practice, this looks like the following:

W0102	pylint	W0102=exclude-protected:_asdict,_fields,_replace,_source,_make;
R0801	pylint	R0801=min-similarity-lines:4;ignore-comments:yes;ignore-imports:no;

Note

For more details on these, refer to the section on IMPL.txt.