docs: add standalone application guide with Briefcase (#3315)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents 878de46, 3da1f43 · Browse files · 2 files·+149 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+149 added−0 removed
- other:+149 added−0 removed
Provenance
- Commit
a7d2a8d- Tree
90a8f14- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
878de46- Parent 2
3da1f43
2 files changed+149 added−0 removed
modified:docs/index.rst+1 added
77 unmodified lines78 :maxdepth: 179 80 entry-points81 setuptools82+ standalone-apps83 upgrade-guides84 support-multiple-versions85 86 Conceptual Guides59 unmodified linesadded:docs/standalone-apps.md+148 added
1+# Standalone Application with Briefcase2+3+[Briefcase](https://briefcase.beeware.org/) is a tool for packaging Python4+projects as standalone native applications. It can produce installers and5+executables for macOS, Windows, and Linux that do not require the user to6+install Python or any dependencies.7+8+- Produces platform-native installers (``.pkg`` on macOS, ``.msi`` on9+ Windows, ``.deb``/``.rpm`` on Linux).10+- Bundles a Python interpreter and all dependencies.11+- Supports passing command line arguments to the app.12+13+This page outlines the basics of packaging a Click application with14+Briefcase. Be sure to read its15+[documentation](https://briefcase.beeware.org/en/stable/how-to/building/cli-apps/)16+and use ``briefcase --help`` to understand what features are available.17+18+## Installation19+20+Install Briefcase in the virtual environment:21+22+```console23+pip install briefcase24+```25+26+## Configuration27+28+Add a ``[tool.briefcase]`` section and a29+``[tool.briefcase.app.<app-name>]`` section to ``pyproject.toml``.30+Set ``console_app = true`` so Briefcase treats the project as a command31+line application rather than a GUI application.32+33+Given a Click application with the following project structure:34+35+```text36+hello-cli/37+ src/38+ hello_cli/39+ __init__.py40+ app.py41+ LICENSE42+ pyproject.toml43+```44+45+Where ``app.py`` contains a Click command:46+47+```python48+import click49+50+@click.command()51+@click.argument("name", default="World")52+@click.option("--count", default=1, help="Number of times to greet.")53+def main(name, count):54+ """Greet someone by NAME (default: World)."""55+ for _ in range(count):56+ click.echo(f"Hello, {name}!")57+```58+59+Add the following Briefcase configuration to ``pyproject.toml``:60+61+```toml62+[tool.briefcase]63+project_name = "Hello CLI"64+bundle = "com.example"65+version = "0.0.1"66+url = "https://example.com/hello-cli"67+license.file = "LICENSE"68+author = "Your Name"69+author_email = "you@example.com"70+71+[tool.briefcase.app.hello-cli]72+formal_name = "Hello CLI"73+description = "My first application"74+long_description = """More details about the app should go here.75+"""76+sources = [77+ "src/hello_cli",78+]79+console_app = true80+requires = [81+ "click",82+]83+```84+85+The key settings are:86+87+- ``console_app = true`` -- tells Briefcase this is a terminal88+ application, not a GUI.89+- ``sources`` -- the list of source packages to include.90+- ``requires`` -- the Python dependencies to bundle (Click and any other91+ libraries the project needs).92+93+## Entry Point94+95+Briefcase launches the application by running the package with96+``python -m <package>``, so a ``__main__.py`` file **must** exist in the97+package. Without it, Briefcase will not be able to start the application.98+99+Create ``__main__.py`` in the package directory and call the Click100+command:101+102+```python103+from hello_cli.app import main104+105+if __name__ == "__main__":106+ main()107+```108+109+## Running110+111+Use ``briefcase dev`` to run the application directly from the source112+tree. Pass command line arguments after ``--``:113+114+```console115+$ briefcase dev -- World116+Hello, World!117+$ briefcase dev -- World --count 2118+Hello, World!119+Hello, World!120+```121+122+## Building and Packaging123+124+To create a distributable executable, run the following commands:125+126+```console127+briefcase create128+briefcase build129+briefcase package130+```131+132+``briefcase create`` downloads a Python interpreter and installs133+dependencies into an isolated app bundle. ``briefcase build`` compiles134+the app, and ``briefcase package`` produces the final platform installer.135+136+On macOS, this produces a ``.pkg`` installer. On Windows, it produces a137+``.msi`` installer. On Linux, it produces a system package (``.deb``,138+``.rpm``, etc.) for the current distribution.139+140+Once installed, users can run the application directly from the terminal:141+142+```console143+$ hello-cli World144+Hello, World!145+$ hello-cli World --count 2146+Hello, World!147+Hello, World!148+```