tempestweb.pwa¶
The artifacts that make the app installable: the manifest.webmanifest generated from the project config, and the icons in every size a browser asks for. Called by build; import it directly only to produce the artifacts outside the CLI.
Guide with examples: PWA & offline.
tempestweb.pwa ¶
tempestweb.pwa — PWA build artifacts (manifest + icons). Track P, P0/P5.
This package owns the Python side of the PWA: emitting a spec-compliant,
installable manifest.webmanifest and the icon set during tempestweb build
(both Mode A and Mode B). The shape of the manifest mirrors the pure-JS
client/pwa/manifest.js so the two never drift; this module is the build-time
emitter that writes files to disk.
See docs/plan.md §7 P0/P5 for the contract.
IconSpec
dataclass
¶
Specification for one icon file to emit.
Attributes:
| Name | Type | Description |
|---|---|---|
filename |
str
|
File name written under the icons directory. |
size |
int
|
Square edge length in pixels (e.g. 192, 512). |
maskable |
bool
|
Whether this icon is intended as a maskable icon. Maskable icons get a larger safe-zone inset so the OS mask never clips art. |
Source code in tempestweb/pwa/icons.py
ManifestOptions
dataclass
¶
Project overrides for the generated manifest.
Every field defaults to an installable-shaped value; a project's
tempestweb config overrides what it needs.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Full application name. |
short_name |
str
|
Home-screen label. |
description |
str
|
Human description. |
start_url |
str
|
URL opened on launch. |
scope |
str
|
Navigation scope. |
display |
str
|
One of the installable display modes. |
theme_color |
str
|
Toolbar color (CSS color). |
background_color |
str
|
Splash background (CSS color). |
lang |
str
|
BCP-47 language tag. |
dir |
str
|
Text direction ("ltr" | "rtl" | "auto"). |
orientation |
str | None
|
Optional preferred orientation. |
app_id |
str | None
|
Stable app identity; defaults to |
icons |
list[dict[str, str]]
|
Icon set; defaults to |
categories |
list[str]
|
App-store categories. |
launch_handler |
dict[str, Any] | None
|
|
display_override |
list[str]
|
Ordered display fallbacks; defaults to
|
shortcuts |
list[dict[str, Any]]
|
P5 app shortcuts. |
share_target |
dict[str, Any] | None
|
P5 share target descriptor. |
file_handlers |
list[dict[str, Any]]
|
P5 file handler descriptors. |
Source code in tempestweb/pwa/manifest.py
emit_icons ¶
emit_icons(dest_dir: Path, specs: tuple[IconSpec, ...] = DEFAULT_ICON_SPECS, color: tuple[int, int, int, int] = (17, 17, 17, 255)) -> list[Path]
Write the icon set to dest_dir (e.g. <build>/icons).
Maskable specs get a ~10% safe-zone inset so the OS mask never clips the art.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_dir
|
Path
|
Output directory (created if missing). |
required |
specs
|
tuple[IconSpec, ...]
|
Icon specifications to emit. |
DEFAULT_ICON_SPECS
|
color
|
tuple[int, int, int, int]
|
Base color for the icons. |
(17, 17, 17, 255)
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The list of paths written, in spec order. |
Source code in tempestweb/pwa/icons.py
placeholder_png ¶
placeholder_png(size: int, color: tuple[int, int, int, int] = (17, 17, 17, 255), inset: int = 0, inset_color: tuple[int, int, int, int] = (255, 255, 255, 255)) -> bytes
Build a valid 8-bit RGBA PNG of a solid color with an optional inset.
The inset draws a centered square of inset_color to mimic a maskable
icon's safe zone, so the generated maskable variants look intentional.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Square edge length in pixels (> 0). |
required |
color
|
tuple[int, int, int, int]
|
Background RGBA (0-255 each). |
(17, 17, 17, 255)
|
inset
|
int
|
Border width in pixels left as |
0
|
inset_color
|
tuple[int, int, int, int]
|
RGBA of the inner square. |
(255, 255, 255, 255)
|
Returns:
| Type | Description |
|---|---|
bytes
|
The complete PNG file bytes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in tempestweb/pwa/icons.py
build_manifest ¶
Build a manifest object from options, filling installable defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
ManifestOptions | None
|
Project overrides. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A JSON-able manifest object ready for |
Source code in tempestweb/pwa/manifest.py
default_extras ¶
Return the default P5 manifest extras a scaffolded app ships.
A "Home" shortcut, a POST share target and a CSV file handler. References only — the host app wires the routes (share_target pairs with native.share).
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with |
Source code in tempestweb/pwa/manifest.py
emit_manifest ¶
Serialize a manifest object to JSON text for manifest.webmanifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
A manifest object (typically from |
required |
indent
|
int
|
Spaces of indentation (0 for minified). |
2
|
Returns:
| Type | Description |
|---|---|
str
|
The JSON string. |
Source code in tempestweb/pwa/manifest.py
validate_extras ¶
Validate the P5 manifest extras (shortcuts/share_target/file_handlers).
Progressive enhancements with uneven browser support, so this is a shape
check, not an install requirement. Mirrors validateExtras in
client/pwa/manifest.js.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
A manifest (or extras) object. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Human-readable problems; empty when present extras are well-formed. |
Source code in tempestweb/pwa/manifest.py
validate_installable ¶
Return install-criteria errors for a manifest ([] when installable).
Mirrors validateInstallable in client/pwa/manifest.js.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
A parsed manifest object. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Human-readable problems; empty when installable. |
Source code in tempestweb/pwa/manifest.py
write_manifest ¶
Build and write manifest.webmanifest to dest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest
|
Path
|
Output file path (parent dirs are created). |
required |
options
|
ManifestOptions | None
|
Project overrides. |
None
|
indent
|
int
|
JSON indentation. |
2
|
Returns:
| Type | Description |
|---|---|
Path
|
The path written. |
Source code in tempestweb/pwa/manifest.py
package_digests ¶
Map each wheel file name in the lock to the sha256 it declares.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lock
|
dict[str, Any]
|
The parsed |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
|
Source code in tempestweb/pwa/pyodide_vendor.py
pyodide_cdn_base ¶
Return the jsdelivr base URL for a Pyodide release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
The Pyodide release tag (e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Source code in tempestweb/pwa/pyodide_vendor.py
resolve_package_files ¶
Resolve the wheel files for roots and their transitive dependencies.
Walks the dependency graph in pyodide-lock.json from each root package,
collecting every reachable package's file_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lock
|
dict[str, Any]
|
The parsed |
required |
roots
|
tuple[str, ...]
|
The package names the app imports (e.g. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The sorted, de-duplicated list of wheel file names to vendor. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a required package is absent from the lock file. |
Source code in tempestweb/pwa/pyodide_vendor.py
vendor_pyodide ¶
vendor_pyodide(out_dir: str | Path, *, version: str, packages: tuple[str, ...], fetch: Fetcher | None = None) -> list[str]
Download the Pyodide runtime + packages closure into out_dir.
Writes the core runtime files and every resolved wheel as siblings in
out_dir (the artifact's pyodide/ directory). The lock file is fetched
once and reused to resolve the package closure, then written alongside the
rest so the offline indexURL is self-contained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dir
|
str | Path
|
The directory to write the vendored files into (created if absent). |
required |
version
|
str
|
The Pyodide release tag to vendor. |
required |
packages
|
tuple[str, ...]
|
The package names the app imports (their closure is vendored). |
required |
fetch
|
Fetcher | None
|
Download function (injected in tests). Defaults to an HTTP fetch. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The file names written, in fetch order (lock first, then the remaining |
list[str]
|
core files, then the wheels). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a downloaded wheel does not match the |