climate_ref.doctor.registry
#
The set of checks that ref doctor runs.
A check is a plain function over a DoctorContext, declared with @check. The built-in
checks live under climate_ref.doctor.checks; a package outside this one contributes its
own by advertising a module in the climate-ref.doctor-checks entry point group, which
is imported for its @check declarations:
[project.entry-points."climate-ref.doctor-checks"]
my_provider = "my_package.doctor_checks"
BUILT_IN = 'built-in'
module-attribute
#
RegisteredCheck.source for a check that ships with climate_ref.
CHECK_ENTRY_POINT_GROUP = 'climate-ref.doctor-checks'
module-attribute
#
Entry point group through which another package contributes checks.
RegisteredCheck
#
A check and what it is for.
Source code in packages/climate-ref/src/climate_ref/doctor/registry.py
description
instance-attribute
#
One line describing what the check looks for, shown by ref doctor --list.
func
instance-attribute
#
The check itself.
slug
instance-attribute
#
Stable identifier, e.g. duplicate-coverage. Stamped onto the check's findings.
source = BUILT_IN
class-attribute
instance-attribute
#
Where the check came from: BUILT_IN, or the name of the entry point that supplied it.
__call__(context)
#
Run the check, stamping this check's slug onto every finding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
DoctorContext
|
The deployment to check. |
required |
Returns:
| Type | Description |
|---|---|
list[Finding]
|
The findings, each carrying |
Source code in packages/climate-ref/src/climate_ref/doctor/registry.py
check(slug, description)
#
Declare a function as a doctor check.
The decorated function is returned unchanged, so it stays directly callable in tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Stable identifier for the check, in kebab-case. |
required |
description
|
str
|
One line describing what the check looks for. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[CheckFunction], CheckFunction]
|
A decorator that registers the function and returns it. |
Source code in packages/climate-ref/src/climate_ref/doctor/registry.py
iter_checks()
#
Every check available to this deployment, built-in first, then each plugin's.
Returns:
| Type | Description |
|---|---|
tuple[RegisteredCheck, ...]
|
The registered checks, ordered by source and then by registration order. |
Source code in packages/climate-ref/src/climate_ref/doctor/registry.py
load_plugin_checks()
#
Import the check modules advertised by other packages.
Importing a module runs its @check declarations. A module that cannot be imported is
recorded rather than raised, so one broken plugin does not take the command down. The
error is reported as a finding by run_checks.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The load errors, keyed by entry point name. |
Source code in packages/climate-ref/src/climate_ref/doctor/registry.py
register_check(registered)
#
Add a check to the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registered
|
RegisteredCheck
|
The check to add. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If another check already claims the same slug. Two checks sharing a slug would be indistinguishable in the report. |
Source code in packages/climate-ref/src/climate_ref/doctor/registry.py
run_checks(context, checks=None)
#
Run the checks and collect their findings, worst first.
A check that raises is reported as a finding rather than stopping the run, so one broken check cannot hide the others. So is a plugin that could not be imported, because a check that never ran must not look like a check that passed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
DoctorContext
|
The deployment to check. |
required |
checks
|
Iterable[RegisteredCheck] | None
|
The checks to run. Defaults to every registered check. |
None
|
Returns:
| Type | Description |
|---|---|
list[Finding]
|
Findings ordered by severity, then by the check that produced them. |