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.

MetricContext#

class understand.MetricContext#

Bases: object

Metric plugin object

This object is provided to a metric plugin’s test_* and value functions. Use the id() to find the requested metric id. Use options() to define and lookup custom options.

Methods Summary

cache

Return a cache that can be used to store, retrieve, and share data.

db

Return the database associated with this metric.

id

The id of the requested metric.

is_aborted

Return True if metric generation has been aborted by the user.

list

Return the list of built-in metrics

options

Return the Options object associated with this metric.

Methods Documentation

cache(id='') → understand.Cache#

Return a cache that can be used to store, retrieve, and share data. If id is not given, it will be a script-specific identifier. This function may return None if caching is not available.

Return type:

understand.Cache

Returns:

a cache object or None

db() → understand.Db#

Return the database associated with this metric.

Return type:

understand.Db

Returns:

the database

id() → str#

The id of the requested metric.

Return type:

str

is_aborted() → bool#

Return True if metric generation has been aborted by the user.

Return type:

bool

Returns:

True if metric generation has been aborted by the user

list(ent) → list[str]#
list(arch) → list[str]
list(db) → list[str]
list(entkindstr) → list[str]

Return the list of built-in metrics

This only lists metrics calculated by Understand, and does not include any metrics provided by plugins. So, it is safe to call from a metric plugin. This function should be used instead of the following four functions: ent.metrics, arch.metrics, db.metrics, or Metrics.list. Those functions are not safe to call from a Metric plugin because they include metrics defined by metric plugins.

Parameters:
  • arch (understand.Arch) – an architecture to list metrics for

  • ent (understand.Ent) – an entity to list metrics for

  • db (understand.Db) – a database to list metrics for

  • entkindstr (str) – an entity kind string which may be empty.

Return type:

list[str]

options() → understand.Options#

Return the Options object associated with this metric.

Return type:

understand.Options

Returns:

the options object