Application

The Application is the entry point to any Craft Application. Most apps will only need to configure their own AppMetadata.

AppMetadata

final class craft_application.application.AppMetadata(name: str, summary: str | None = None, docs_url: str | None = None, source_ignore_patterns: list[str] = <factory>, project_variables: list[str] = <factory>, mandatory_adoptable_fields: list[str] = <factory>, ConfigModel: type[~craft_application._config.ConfigModel] = <class 'craft_application._config.ConfigModel'>, ProjectClass: type[~craft_application.models.project.Project] = <class 'craft_application.models.project.Project'>, supports_multi_base: bool = False, always_repack: bool = True, check_supported_base: bool = False)

Metadata about a craft application.

class ConfigModel(*, verbosity_level: EmitterMode = EmitterMode.BRIEF, debug: bool = False, build_environment: str | None = None, secrets: str, platform: str | None = None, build_for: str | None = None, parallel_build_count: int, max_parallel_build_count: int, lxd_remote: str = 'local', launchpad_instance: str = 'production')

A configuration model for a craft application.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

ProjectClass

The project model to use for this app.

Most applications will need to override this, but a very basic application could use the default model without modification.

alias of Project

check_supported_base: bool = False

Whether this application allows building on unsupported bases.

When True, the app can build on a base even if it is end-of-life. Relevant apt repositories will be migrated to old-releases.ubuntu.com. Currently only supports EOL Ubuntu releases.

When False, the repositories are not migrated and base support is not checked.

docs_url: str | None = None

The root URL for the app’s documentation.

name: str

The name of the application.

summary: str | None = None

A short summary of the application.

property versioned_docs_url: str | None

The docs_url with the proper app version.

Application

class craft_application.application.Application(app: AppMetadata, services: service_factory.ServiceFactory, *, extra_loggers: Iterable[str] = ())

Craft Application Builder.

Variables:
  • app – Metadata about this application

  • services – A ServiceFactory for this application

Parameters:

extra_loggers – Logger names to integrate with craft-cli beyond the defaults.

add_command_group(name: str, commands: Sequence[type[craft_cli.BaseCommand]], *, ordered: bool = False) None

Add a CommandGroup to the Application.

add_global_argument(argument: GlobalArgument) None

Add a global argument to the Application.

property app_config: dict[str, Any]

Get the configuration passed to dispatcher.load_command().

This can generally be left as-is. It’s strongly recommended that if you are overriding it, you begin with config = super().app_config and update the dictionary from there.

property cache_dir: Path

Get the directory for caching any data.

property command_groups: list[CommandGroup]

Return command groups.

Merges command groups provided by the application with craft-application’s default commands.

If the application and craft-application provide a command with the same name in the same group, the application’s command is used.

Note that a command with the same name cannot exist in multiple groups.

configure(global_args: dict[str, Any]) None

Configure the application using any global arguments.

get_arg_or_config(parsed_args: argparse.Namespace, item: str) Any

Get a configuration option that could be overridden by a command argument.

Parameters:
  • parsed_args – The argparse Namespace to check.

  • item – the name of the namespace or config item.

Returns:

the requested value.

get_project(*, platform: str | None = None, build_for: str | None = None) Project

Get the project model.

This only resolves and renders the project the first time it gets run. After that, it merely uses a cached project model.

Parameters:
  • platform – the platform name listed in the build plan.

  • build_for – the architecture to build this project for.

Returns:

A transformed, loaded project model.

is_managed() bool

Shortcut to tell whether we’re running in managed mode.

property log_path: Path | None

Get the path to this process’s log file, if any.

property project: Project

Get this application’s Project metadata.

register_plugins(plugins: dict[str, PluginType]) None

Register plugins for this application.

run() int

Bootstrap and run the application.

run_managed(platform: str | None, build_for: str | None) None

Run the application in a managed instance.