| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from collections.abc import Collection |
| 4 |
from pathlib import Path |
| 5 |
from typing import Any, TypedDict |
| 6 |
|
| 7 |
from briefcase.console import Console |
| 8 |
|
| 9 |
|
| 10 |
class AppContext(TypedDict): |
| 11 |
formal_name: str |
| 12 |
app_name: str |
| 13 |
class_name: str |
| 14 |
module_name: str |
| 15 |
source_dir: str |
| 16 |
test_source_dir: str |
| 17 |
project_name: str |
| 18 |
description: str |
| 19 |
author: str |
| 20 |
author_email: str |
| 21 |
bundle: str |
| 22 |
url: str |
| 23 |
license: str |
| 24 |
|
| 25 |
|
| 26 |
class BaseGuiBootstrap: |
| 27 |
"""Definition for a plugin that defines a new Briefcase app.""" |
| 28 |
|
| 29 |
# These are the field names that will be defined in the cookiecutter context. |
| 30 |
# Any fields defined here must be implemented as methods that return a ``str`` |
| 31 |
# or ``None``. Returning ``None`` omits the field as a key in the context, thereby |
| 32 |
# deferring the value for the field to the cookiecutter template. |
| 33 |
fields: Collection[str] = [ |
| 34 |
"app_source", |
| 35 |
"app_start_source", |
| 36 |
"pyproject_table_briefcase_extra_content", |
| 37 |
"pyproject_table_briefcase_app_extra_content", |
| 38 |
"pyproject_table_macOS", |
| 39 |
"pyproject_table_linux", |
| 40 |
"pyproject_table_linux_system_debian", |
| 41 |
"pyproject_table_linux_system_rhel", |
| 42 |
"pyproject_table_linux_system_suse", |
| 43 |
"pyproject_table_linux_system_arch", |
| 44 |
"pyproject_table_linux_appimage", |
| 45 |
"pyproject_table_linux_flatpak", |
| 46 |
"pyproject_table_windows", |
| 47 |
"pyproject_table_iOS", |
| 48 |
"pyproject_table_android", |
| 49 |
"pyproject_table_web", |
| 50 |
"pyproject_extra_content", |
| 51 |
] |
| 52 |
|
| 53 |
# A short annotation that's appended to the name of the GUI toolkit when the user |
| 54 |
# is presented with the options to create a new project. |
| 55 |
display_name_annotation: str = "" |
| 56 |
|
| 57 |
def __init__(self, console: Console, context: AppContext): |
| 58 |
self.console = console |
| 59 |
|
| 60 |
# context contains metadata about the app being created |
| 61 |
self.context = context |
| 62 |
|
| 63 |
def extra_context(self, project_overrides: dict[str, str]) -> dict[str, Any] | None: |
| 64 |
"""Runs prior to other plugin hooks to provide additional context. |
| 65 |
|
| 66 |
This can be used to prompt the user with additional questions or run arbitrary |
| 67 |
logic to supplement the context provided to cookiecutter. |
| 68 |
|
| 69 |
:param project_overrides: Any overrides provided by the user as -Q options that |
| 70 |
haven't been consumed by the standard bootstrap wizard questions. |
| 71 |
""" |
| 72 |
|
| 73 |
def app_source(self) -> str | None: |
| 74 |
"""The Python source code for app.py.""" |
| 75 |
|
| 76 |
def app_start_source(self) -> str | None: |
| 77 |
"""The Python source code for __main__.py to start the app.""" |
| 78 |
|
| 79 |
def pyproject_table_briefcase_extra_content(self) -> str | None: |
| 80 |
"""Additional content for ``tool.briefcase`` table.""" |
| 81 |
|
| 82 |
def pyproject_table_briefcase_app_extra_content(self) -> str | None: |
| 83 |
"""Additional content for ``tool.briefcase.app.<app-name>`` table.""" |
| 84 |
|
| 85 |
def pyproject_table_macOS(self) -> str | None: |
| 86 |
"""Content for ``tool.briefcase.app.<app-name>.macOS`` table.""" |
| 87 |
|
| 88 |
def pyproject_table_linux(self) -> str | None: |
| 89 |
"""Content for ``tool.briefcase.app.<app-name>.linux`` table.""" |
| 90 |
|
| 91 |
def pyproject_table_linux_system_debian(self) -> str | None: |
| 92 |
"""Content for ``tool.briefcase.app.<app-name>.linux.debian`` table.""" |
| 93 |
|
| 94 |
def pyproject_table_linux_system_rhel(self) -> str | None: |
| 95 |
"""Content for ``tool.briefcase.app.<app-name>.linux.rhel`` table.""" |
| 96 |
|
| 97 |
def pyproject_table_linux_system_suse(self) -> str | None: |
| 98 |
"""Content for ``tool.briefcase.app.<app-name>.linux.suse`` table.""" |
| 99 |
|
| 100 |
def pyproject_table_linux_system_arch(self) -> str | None: |
| 101 |
"""Content for ``tool.briefcase.app.<app-name>.linux.arch`` table.""" |
| 102 |
|
| 103 |
def pyproject_table_linux_appimage(self) -> str | None: |
| 104 |
"""Content for ``tool.briefcase.app.<app-name>.linux.appimage`` table.""" |
| 105 |
|
| 106 |
def pyproject_table_linux_flatpak(self) -> str | None: |
| 107 |
"""Content for ``tool.briefcase.app.<app-name>.linux.flatpak`` table.""" |
| 108 |
|
| 109 |
def pyproject_table_windows(self) -> str | None: |
| 110 |
"""Content for ``tool.briefcase.app.<app-name>.windows`` table.""" |
| 111 |
|
| 112 |
def pyproject_table_iOS(self) -> str | None: |
| 113 |
"""Content for ``tool.briefcase.app.<app-name>.iOS`` table.""" |
| 114 |
|
| 115 |
def pyproject_table_android(self) -> str | None: |
| 116 |
"""Content for ``tool.briefcase.app.<app-name>.android`` table.""" |
| 117 |
|
| 118 |
def pyproject_table_web(self) -> str | None: |
| 119 |
"""Content for ``tool.briefcase.app.<app-name>.web`` table.""" |
| 120 |
|
| 121 |
def pyproject_extra_content(self) -> str | None: |
| 122 |
"""Additional TOML to add to the bottom of pyproject.toml.""" |
| 123 |
|
| 124 |
def post_generate(self, base_path: Path) -> None: |
| 125 |
"""Runs after the template has been generated. |
| 126 |
|
| 127 |
This can be used to produce any additional files that the base template doesn't |
| 128 |
provide. |
| 129 |
|
| 130 |
:param base_path: The path to the root of the generated project. |
| 131 |
""" |