tempestweb.transpile¶
O compilador do Modo C: lê a camada de app em Python tipado e emite JavaScript nativo. TranspileError traz file:line quando o código sai do subconjunto suportado — é o erro que você vai encontrar antes de qualquer outro ao portar um app para bundle estático.
Guia com exemplos: Modo C — transpile.
tempestweb.transpile ¶
Mode C transpiler — typed Python app layer → native JavaScript.
Transcribes a tempestweb app module (state dataclasses + view + handlers) into
an ES module that runs on the native JS runtime (client/transpile/runtime.js),
with zero Python at execution time. See docs/modo-c-transpile.md.
TranspileError ¶
Bases: Exception
A Python construct fell outside the transpilable subset.
Carries the source location so the message reads like a compiler diagnostic
(file:line: <what> is not supported), in the spirit of mypy --strict.
Source code in tempestweb/transpile/errors.py
LocalModule
dataclass
¶
One project module reachable from the entrypoint.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The module's dotted name relative to the project root
( |
path |
Path
|
The absolute path to the module's source file. |
source |
str
|
The module's source text. |
tree |
Module
|
The parsed module. |
classes |
frozenset[str]
|
The names of the classes the module declares at top level, needed by an importing module to know a name is constructible. |
is_package |
bool
|
Whether the file is an |
is_entry |
bool
|
Whether this is the entrypoint the build starts from. |
Source code in tempestweb/transpile/graph.py
local_module_specifier ¶
Return the ES import specifier for a sibling project module.
Every emitted module lands in the same directory as the entrypoint, named
by its dotted path, so one flat specifier works from any depth — no
../.. to get wrong.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
str
|
The sibling's dotted module name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The relative specifier ( |
Source code in tempestweb/transpile/codegen.py
resolve_graph ¶
Walk the entrypoint's local imports into a dependency-ordered graph.
Depth-first, so a module always appears after everything it imports — the order the emitter and the build write them in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Path
|
The absolute path to the entrypoint module. |
required |
root
|
Path
|
The project root local module names resolve against. |
required |
Returns:
| Type | Description |
|---|---|
list[LocalModule]
|
Every project module reachable from the entrypoint, dependencies first |
list[LocalModule]
|
and the entrypoint last. A single-file app returns a one-item list. |
Raises:
| Type | Description |
|---|---|
TranspileError
|
If a local import cycles, or a relative import climbs above the project root. A cycle is refused rather than emitted: the ES modules would load, but a name read during evaluation of the other half throws on a temporal dead zone, at a line neither module names. |
Source code in tempestweb/transpile/graph.py
transpile_source ¶
Transpile Python module source into native-JS module source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The Python source to transpile. |
required |
filename
|
str
|
Source name for diagnostics and the default banner. |
'<source>'
|
banner
|
str | None
|
Optional leading comment line (see :func: |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated JavaScript module source. |
Raises:
| Type | Description |
|---|---|
TranspileError
|
If the module uses a construct outside the subset. |
Source code in tempestweb/transpile/__init__.py
transpile_file ¶
Transpile a Python source file into native-JS module source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the |
required |
banner
|
str | None
|
Optional leading comment line (see :func: |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated JavaScript module source. |
Raises:
| Type | Description |
|---|---|
TranspileError
|
If the module uses a construct outside the subset. |
Source code in tempestweb/transpile/__init__.py
transpile_project ¶
transpile_project(entry: str | Path, root: str | Path, *, entry_filename: str = 'app.gen.js', banner: str | None = None, reserved: frozenset[str] = frozenset()) -> dict[str, str]
Transpile an entrypoint and every project module it imports.
A Mode C app is no longer one file: each local module the entrypoint reaches
becomes its own ES module next to it, and the emitted imports wire them
together. That is what lets an app import the typed client
tempestweb gen api writes, which is a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
str | Path
|
Path to the entrypoint |
required |
root
|
str | Path
|
The project root that local module names resolve against. |
required |
entry_filename
|
str
|
The artifact name for the entrypoint's own module. The other modules are named after their dotted path. |
'app.gen.js'
|
banner
|
str | None
|
Optional leading comment line for the entrypoint (see
:func: |
None
|
reserved
|
frozenset[str]
|
Artifact file names the emitted modules must not take —
the client assets shipped into the same directory. A project module
named |
frozenset()
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Artifact file name → generated JavaScript source, the entrypoint |
dict[str, str]
|
included. A single-file app returns exactly one entry. |
Raises:
| Type | Description |
|---|---|
TranspileError
|
If any module falls outside the subset, the local imports cycle, a relative import climbs above the root, or a module name collides with a reserved artifact. |