Skip to content

Invocation

Leandro Baca edited this page Apr 9, 2021 · 3 revisions

Command Line Interface

The Static Code Analyzer can be invoked as follows from the command line:

python -m pscodeanalyzer.engine [-v] [-c <config_file>] [-p <profile>] [-s "VARIABLE=value"] <files_or_directories>

where:

  • -v or --verbosity increases the output verbosity level. It can be specified multiple times for increasing verbosity. Specifying it once will usually be desired for a continuous integration use-case, which will output details about the issues encountered.
  • -c or --configfile allows for the indication of which configuration file to use. See the Configuration File page for details about the configuration file format and default paths.
  • -p or --profile allows for the indication of which profile to reference within the configuration file. If omitted, "default" is used.
  • -s or --substitute allows for the specification of values for the substitution variables in the configuration profile. It can be specified multiple times, once for each substitution variable.
  • files_or_directories allows for the indication of one or more files or directories (to be processed recursively) on which the analysis must be performed. Wildcards are permitted.

When invoked from command line, it is not possible to indicate to the engine the type of each source file, nor the interval within each to analyze. This can only be achieved through direct invocation of the Python module.

Python Module

The Static Code Analyzer can be invoked from a Python script by calling the analyze function from the pscodeanalyzer.engine module. The arguments are as follows (the first two are positional, the others are keyword arguments):

  • source_files: a list whose items are either:
    • strings representing paths to files;
    • two-item tuples whose first item is a string representing the path to a file and the second item is an integer denoting the type of the source file (can be None, in which case it is ignored);
    • three-item tuples whose first item is a string representing the path to a file, the second item is an integer denoting the type of the source file (can be None, in which case it is ignored), and the third item is a list of two-item tuples denoting line intervals within which to limit the analysis.
  • config_file: the path to the configuration file;
  • profile: the name of the profile to reference within the configuration file (defaults to "default");
  • substitutions: a dictionary mapping substitution variable names to their values;
  • exhaustive: a Boolean indicating whether to stop after the first error (False) or continue processing all source files for every applicable evaluator (True);
  • verbose_output: a Boolean indicating whether verbose output should be enabled.

The function returns a list of FileReport objects, one for each input file that raised at least one Report object.

Clone this wiki locally