| 1 |
# Plugins |
| 2 |
|
| 3 |
Briefcase ships with support for a range of platforms, output formats and GUI toolkits. Internally, these features are implemented using a plugin interface; as a result, it is possible for third-party projects to add their own features to Briefcase by implementing plugins that satisfy those interfaces. |
| 4 |
|
| 5 |
Each plugin is defined using an [entry point](https://packaging.python.org/en/latest/specifications/entry-points/) definition in `pyproject.toml`. |
| 6 |
|
| 7 |
## `briefcase.bootstraps` { #bootstrap-interface } |
| 8 |
|
| 9 |
The Briefcase [new project wizard][new] asks users to select a GUI toolkit. The option selected at this step alters the content of the code generated by the wizard, generating framework-specific requirements, system packages, and stub code for a new application using that GUI framework. These additions are configured using a `briefcase.bootstrap` plugin. |
| 10 |
|
| 11 |
To add a custom `briefcase.bootstrap` plugin, add a `[project.entry-points."briefcase.bootstraps"]` section to your `pyproject.toml` file; each name/value pair under that section will be interpreted as a bootstrap. The name of each bootstrap setting is the label that will be surfaced to the user in the wizard. The value is a string identifying a class that implements the `briefcase.bootstraps.base.BaseGuiBootstrap` abstract base class. |
| 12 |
|
| 13 |
For example, the Toga bootstrap is implemented using the following configuration: |
| 14 |
|
| 15 |
```toml |
| 16 |
[project.entry-points."briefcase.bootstraps"] |
| 17 |
Toga = "briefcase.bootstraps.toga:TogaGuiBootstrap" |
| 18 |
``` |
| 19 |
|
| 20 |
## `briefcase.debuggers` { #debugger-interface } |
| 21 |
|
| 22 |
Briefcase supports running apps with a debugger attached. The debugger used at run time is selected using a `briefcase.debuggers` plugin. |
| 23 |
|
| 24 |
To add a custom `briefcase.debuggers` plugin, add a `[project.entry-points."briefcase.debuggers"]` section to your `pyproject.toml` file; each name/value pair under that section will be interpreted as a debugger. The name of each debugger setting is the identifier used to select the debugger at the command line. The value is a string identifying a class that implements the `briefcase.debuggers.base.BaseDebugger` abstract base class. |
| 25 |
|
| 26 |
A `BaseDebugger` subclass must implement the following abstract properties: |
| 27 |
|
| 28 |
- `name` - a `str` returning the human-readable name of the debugger. |
| 29 |
- `connection_mode` - a `briefcase.debuggers.base.DebuggerConnectionMode` value indicating how the debugger connects to the app. The two possible values are `DebuggerConnectionMode.SERVER` (the app listens for incoming debugger connections) and `DebuggerConnectionMode.CLIENT` (the app connects to a running debugger). |
| 30 |
- `debugger_support_pkg` - a `str` returning the pip requirement specifier for the package that provides in-app debugger support. |
| 31 |
|
| 32 |
For example, the `pdb` debugger is implemented using the following configuration: |
| 33 |
|
| 34 |
```toml |
| 35 |
[project.entry-points."briefcase.debuggers"] |
| 36 |
pdb = "briefcase.debuggers.pdb:PdbDebugger" |
| 37 |
``` |
| 38 |
|
| 39 |
The `debugger_support_pkg` package will be installed into the runtime environment for an app. It is responsible for triggering debugger behavior on any process started in the environment. Depending on the `connection_mode`, this means either waiting for an incoming debugger connection (in the case of a `SERVER`), or a initiating a debugger connection (in the case of `CLIENT`). A debugger should be started if the runtime environment contains the `BRIEFCASE_DEBUGGER` environment variable; the value of that variable will be a JSON-encoded dictionary of configuration parameters: |
| 40 |
|
| 41 |
- `debugger` - The identifying name of the debugger being registered (e.g., `pdb`) |
| 42 |
- `host` - The name of the host where the debugger is running |
| 43 |
- `port` - The port where the debugger is running |
| 44 |
- `host_os` - The value of [`platform.system()`][platform.system] on the machine where the debugger is running |
| 45 |
- `app_path_mappings` - A mapping between application code paths in the app, and the source files on the development machine |
| 46 |
- `app_packages_path_mappings` - A mapping between code paths for app dependencies, and original versions installed on the development machine |
| 47 |
|
| 48 |
## `briefcase.platforms` and `briefcase.formats.*` { #platform-interface } |
| 49 |
|
| 50 |
Each command implemented by Briefcase is specialized by a platform and output format. This implementation is defined using a pair of plugins - a `briefcase.platforms` definition describing a platform, and a `briefcase.format.<platform>` definition that defines the output formats for that platform. |
| 51 |
|
| 52 |
The `briefcase.platforms` entry point defines the existence of a platform. Each name in this section is name of a platform that can be used when invoking Briefcase commands. The value is a fully-qualified Python module name that must defines a single constant `DEFAULT_OUTPUT_FORMAT`. |
| 53 |
|
| 54 |
Each platform name is then incorporated into the name of a separate `format` entry point. Each entry in the `format` section for a platform is the name of an output format that can be used when invoking Briefcase commands. The value is a fully-qualified Python module name that defines 7 symbols: |
| 55 |
|
| 56 |
- `create` - a subclass of `briefcase.commands.create.CreateCommand` |
| 57 |
- `update` - a subclass of `briefcase.commands.create.UpdateCommand` |
| 58 |
- `open` - a subclass of `briefcase.commands.create.OpenCommand` |
| 59 |
- `build` - a subclass of `briefcase.commands.create.BuildCommand` |
| 60 |
- `run` - a subclass of `briefcase.commands.create.RunCommand` |
| 61 |
- `package` - a subclass of `briefcase.commands.create.PackageCommand` |
| 62 |
- `publish` - a subclass of `briefcase.commands.create.PublishCommand` |
| 63 |
|
| 64 |
For example, the macOS Xcode output format is implemented using the following configuration: |
| 65 |
|
| 66 |
```toml |
| 67 |
[project.entry-points."briefcase.platforms"] |
| 68 |
macOS = "briefcase.platforms.macOS" |
| 69 |
|
| 70 |
[project.entry-points."briefcase.formats.macOS"] |
| 71 |
xcode = "briefcase.platforms.macOS.xcode" |
| 72 |
``` |
| 73 |
|
| 74 |
## `briefcase.channels.*` { #publication-channel-interface } |
| 75 |
|
| 76 |
Briefcase provides a plugin interface that enables publishing apps to distribution channels (e.g., the iOS App Store or Google Play Store) via the [publish][publish] command. |
| 77 |
|
| 78 |
--8<-- "_snippets/available-channels.md" |
| 79 |
|
| 80 |
Publication channel entry points are scoped by platform and output format. To add a custom publication channel plugin, add a `[project.entry-points."briefcase.channels.<platform>.<format>"]` section to your `pyproject.toml` file; each name/value pair under that section will be interpreted as a publication channel. The name of each setting is the identifier used to select the channel with `--channel` on the command line. The value is a string identifying a class that implements the `briefcase.channels.base.BasePublicationChannel` abstract base class. |
| 81 |
|
| 82 |
A `BasePublicationChannel` subclass must implement: |
| 83 |
|
| 84 |
- `name` - an abstract `str` property returning the human-readable name of the channel. |
| 85 |
- `publish_app(app, command, **options)` - an abstract method that performs the actual publication. `app` is the `AppConfig` for the application being published; `command` satisfies the `PublishCommandAPI` protocol (see below). |
| 86 |
|
| 87 |
The `PublishCommandAPI` protocol (`briefcase.channels.base.PublishCommandAPI`) defines the stable API surface that plugins can rely on from the `command` parameter: |
| 88 |
|
| 89 |
- `console` - the console object for user interaction |
| 90 |
- `tools` - the tool registry |
| 91 |
- `dist_path` - the path to the distribution output directory |
| 92 |
- `distribution_path(app)` - returns the path to the distributable artefact for the given app |
| 93 |
|
| 94 |
If only one channel is registered for a platform/format combination, it is selected automatically. If multiple channels are available, the user must specify `--channel` on the command line. |
| 95 |
|
| 96 |
For example, the iOS App Store channel is implemented using the following configuration: |
| 97 |
|
| 98 |
```toml |
| 99 |
[project.entry-points."briefcase.channels.iOS.Xcode"] |
| 100 |
appstore = "briefcase.channels.appstore:AppStorePublicationChannel" |
| 101 |
``` |