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.
Config#
- class understand.Config#
Bases:
objectA configuration
A configuration is a list CodeCheck checks and their properties.
Methods Summary
Return the kind of the check with the given id.
Return the name of the check with the given id.
Return the tags of the check with the given id.
Return the ids of the checks in the configuration.
Create a configuration from a list of checks.
Return the description of the configuration.
Return a list of configurations.
Load a configuration from a file.
Return a check in this configuration.
Return the name of the configuration.
Save the configuration to a file.
Return the tags that describe the configuration.
Methods Documentation
- check_kind(id) str#
Return the kind of the check with the given id.
Possible kinds are:
Perl Script
Python Script
Dependency
Parser
Not Supported
Implicitly Supported
- Parameters:
id (str) – the check id
- Return type:
str
- Returns:
the check kind
- check_name(id) str#
Return the name of the check with the given id.
- Parameters:
id (str) – the check id
- Return type:
str
- Returns:
the check name
- check_tags(id) list[str]#
Return the tags of the check with the given id.
Tags by convention are “key: value” or “value”. Properties defined by tags include the standard and severity.
- Parameters:
id (str) – the check id
- Return type:
list[str]
- Returns:
the check tags
- checks(db=None) list[str]#
Return the ids of the checks in the configuration.
- Parameters:
db (understand.Db or None) – optional, a database. Required to find checks that a project defines, such as dependency checks. Defaults to the database of the inspection the configuration came from, if any.
- Return type:
list[str]
- Returns:
the check ids
- classmethod create(checklist, name='', description='') understand.Config#
Create a configuration from a list of checks.
- Parameters:
checklist (list[understand.Check or tuple]) – the checks. Each item is an understand.Check, or a tuple of an understand.Check and its options. Options are an understand.Options object or an options string. A check without options keeps the option values it has.
name (str) – optional, the configuration name
description (str) – optional, the configuration description
- Return type:
- Returns:
the new configuration
- Raises:
ValueError – if an options string can’t be applied to its check
- description() str#
Return the description of the configuration.
- Return type:
str
- Returns:
the description, which may be an empty string
- classmethod list(target=None) list[understand.Config]#
Return a list of configurations.
When a database is provided, the list includes all configurations stored in the project plus any standard configurations that apply to the database. Without a database, only standard configurations are listed.
- Parameters:
target (understand.Db or None) – optional, list the configurations for the database.
- Return type:
list[understand.Config]
- Returns:
the list of configurations
- classmethod load(filename) understand.Config#
Load a configuration from a file.
- Parameters:
filename (str) – the path to a configuration .json file
- Return type:
- Returns:
the configuration
- Raises:
understand.UnderstandError – if the file can’t be read or is not a configuration
- lookup_check(id, db=None) understand.Check#
Return a check in this configuration.
The check has the severity and option values set by the configuration.
- Parameters:
id (str) – the check id
db (understand.Db or None) – optional, a database. Required to find checks that a project defines, such as dependency checks. Defaults to the database of the inspection the configuration came from, if any.
- Return type:
- Returns:
the check, or None if the id does not map to a check
- name() str#
Return the name of the configuration.
- Return type:
str
- Returns:
the configuration name
- save(filename) None#
Save the configuration to a file.
The file can be loaded with
Config.loador run withund codecheck.- Parameters:
filename (str) – the path of the .json file to write
- Raises:
understand.UnderstandError – if the file can’t be written
- tags() list[str]#
Return the tags that describe the configuration.
Tags are optional and may be empty.
- Return type:
list[str]
- Returns:
the list of tags