The Understand Python API gives scripts access to everything Understand knows about your code — entities, references, metrics, and dependencies — and powers custom checks, graphs, and reports.

Inspection#

class understand.Inspection#

Bases: object

An inspection

An inspection wraps CodeCheck output. The main purpose is to provide the violations and ignored violations found from a particular CodeCheck run. Information about the inspection as a whole is also available, including the configuration and files inspected and the time of the inspection.

Methods Summary

config

Return the configuration that was run.

draw

Generate graph output

end_time

Return the end time of the inspection in ISO format.

errors

Return the error messages from the inspection.

files

Return the files that were inspected.

name

Return the name of the inspection.

report

Generate a report for the inspection.

save

Save the inspection to a SARIF file.

start_time

Return the start time of the inspection in ISO format.

violations

Return the violations found by the inspection.

Methods Documentation

config() → understand.Config#

Return the configuration that was run.

Return type:

understand.Config

Returns:

the configuration, or None if it is not available

draw(graph, filename='', options=None, variant='', format='', save_legend=False) → bytes | understand.GraphContext | None#

Generate graph output

Parameters:
  • graph (str or understand.Graph) – the graph to generate

  • filename (str or None) – output path when writing to disk; omit when using format

  • options (str or understand.Options or None) – optional, graph options

  • variant (str or None) – the variant of the graph to generate

  • format (str or None) – in-memory export format

  • save_legend (bool or None) – save the legend

Return type:

bytes or understand.GraphContext or None

Returns:

None after a successful export when filename is given; a read-only GraphContext when format is “raw”; otherwise graph bytes for the requested in-memory format.

Raises:

understand.UnderstandError – if an error occurs

View More.

end_time() → str#

Return the end time of the inspection in ISO format.

This may be an empty string if the time is not known or the inspection is still running.

Return type:

str

Returns:

the end time of the inspection

errors() → list[str]#

Return the error messages from the inspection.

Return type:

list[str]

Returns:

the error messages

files() → list[str]#

Return the files that were inspected.

Return type:

list[str]

Returns:

the input files

name() → str#

Return the name of the inspection.

Return type:

str

Returns:

the inspection name

report(name, filename, options=None, pages=None, format='') → None#

Generate a report for the inspection.

Parameters:
  • name (str or understand.Report) – the report to generate (same name as in the GUI), or a catalog object from Report.list

  • filename (str) – output directory or output file name (pdf only)

  • options (str or understand.Options or None) – optional, report options

  • pages (list[str] or tuple[str] or None) – optional, report page ids to output. None or empty means all pages.

  • format (str or None) – optional, comma separated output format(s) for directory output

Return type:

None

Raises:

understand.UnderstandError – if an error occurs

View More.

save(filename) → None#

Save the inspection to a SARIF file.

The file can be loaded with Db.load_inspection.

Parameters:

filename (str) – the path of the .sarif file to write

Raises:

understand.UnderstandError – if the file can’t be written

start_time() → str#

Return the start time of the inspection in ISO format.

This may be an empty string if the time is not known.

Return type:

str

Returns:

the start time of the inspection

violations() → list[understand.Violation]#

Return the violations found by the inspection.

Return type:

list[understand.Violation]

Returns:

the violations