ConfigService¶
The ConfigService provides read access to a user’s application configuration
through a series of ConfigHandler objects. The default config handlers provide
access to both per-application configuration and configuration for all crafts. An
application can provide additional config handlers for custom use cases.
The configuration items available to the configuration service are defined in the
ConfigModel, which an application can extend.
Handler Order¶
The application’s configuration is retrieved from the handlers in the order in which they were registered to the config cervice. By default this order is:
AppEnvironmentHandlergets app-specific environment variables.CraftEnvironmentHandlergets generalCRAFT_*environment variables.Extra handlers (if any) provided by the application.
SnapConfigHandler(if running as a snap) gets a snap configuration option.DefaultConfigHandlergets the default value, if there is one.
A handler raises a KeyError if it doesn’t have a relevant
config option set. If no handlers return a value when getting a configuration option, a
KeyError is raised to signify that no configuration could be
found.
Configuration model¶
Each application has a configuration model, by default craft_application.ConfigModel,
which is provided to the application by the ConfigModel attribute of the app’s AppMetadata instance. An app may extend its fields from those
in the configuration model.
- class craft_application.ConfigModel¶
The configuration model for the app.
This model informs the config service what configuration items are available to the application.
- build_environment: str | None¶
The build environment to use for this app.
Defaults to unset, can also be set as
hostto enable destructive mode.
- idle_mins: pydantic.NonNegativeInt | None¶
How long the container used by lifecycle steps remains active after the app exits.
If unset, this defaults to exiting synchronously before the app exits.
- max_parallel_build_count: int¶
The maximum parallel build count to send to Craft Parts.
If this value is set but
parallel_build_countis not, the smaller ofmax_parallel_build_countor the number of processor cores available to the app process is used. If unset, the number of processor cores available is used.
- parallel_build_count: int¶
The parallel build count to send to Craft Parts.
Supersedes any value set in
max_parallel_build_count.
- verbosity_level: EmitterMode¶
The verbosity level for the app.
API documentation¶
- class craft_application.services.config.ConfigHandler¶
The abstract class that is the parent of all configuration handlers.
- final class craft_application.services.config.AppEnvironmentHandler¶
Configuration handler to get values from app-specific environment variables.
Environment variables used for this are prefixed with a fully upper-case form of the application name. For example,
TESTCRAFT_DEBUG.
- final class craft_application.services.config.CraftEnvironmentHandler¶
Configuration handler to get values from CRAFT environment variables.
- class craft_application.services.config.SnapConfigHandler¶
Configuration handler that gets values from snapd.
Snap configuration values are set with kebab case, so the
verbosity_levelconfiguration value can be set toverboseusing the commandsnap set <snap-name> verbosity-level=verbose
- final class craft_application.services.config.DefaultConfigHandler¶
Configuration handler for getting default values.
- class craft_application.services.config.ConfigService¶
Application-wide configuration access.
- __init__(app: application.AppMetadata, services: ServiceFactory, *, extra_handlers: Iterable[type[ConfigHandler]] = ()) None¶