Skip to content

pb_client.compile.compile_source async

compile_source(source, *, name=SOURCE_NAME)

Compile Python source into a program the hub can run.

For source that did not come from a file, so there is nothing to discover: a program typed at a shell cannot import a module of its own, since there is no directory it came from. The one module is called __main__, which every firmware runs -- there is no file name to call it instead, and __main__ is also what the hub would then display.

Parameters:

Name Type Description Default
source str

The Python code.

required
name str

What to call it in compiler diagnostics and in tracebacks from the hub. Defaults to SOURCE_NAME.

SOURCE_NAME

Returns:

Type Description
bytes

The compiled program, ready to download.

Raises:

Type Description
CompileError

If the compiler rejects it.