mcu_stubber

This script creates stubs on and for a connected micropython MCU board.

Attributes

HERE

reset_before

TESTING

Classes

Variant

Variants to generate stubs on a MCU

Form

Optimization forms of scripts

Functions

hard_reset(→ bool)

Reset the board

run_createstubs(dest, mcu[, variant, mount_vfs])

Run a createstubs[variant] on the provided board.

build_cmd(→ List[str])

Build the import createstubs[_??] command to run on the board

ensure_lib_directory(mcu)

Create lib directory and add to sys.path for mip_install.

generate_board_stubs(→ Tuple[int, Optional[pathlib.Path]])

Generate the firmware stubs (formerly MCU stubs) for this MCU board.

copy_boardname_to_board(mcu)

Copies the board name to the board by writing it to the 'boardname.py' file.

install_scripts_to_board(mcu, form)

Copy the createstubs script(s) to the board.

get_stubfolder(out)

set_loglevel(→ str)

Set log level based on verbose level

copy_to_repo(→ Optional[pathlib.Path])

Copy the generated stubs to the stubs repo.

stub_connected_mcus(→ int)

Runs the stubber to generate stubs for connected MicroPython boards.

print_publish_table(all_built[, console])

print_stub_locations_table(stub_locations[, console])

Print a table of stub locations for generated stubs.

Module Contents

mcu_stubber.HERE
mcu_stubber.reset_before = True
mcu_stubber.TESTING = False
class mcu_stubber.Variant

Bases: str, enum.Enum

Variants to generate stubs on a MCU

full = 'full'
mem = 'mem'
db = 'db'
class mcu_stubber.Form

Bases: str, enum.Enum

Optimization forms of scripts

py = 'py'
min = 'min'
mpy = 'mpy'
mcu_stubber.hard_reset(board: mpflash.mpremoteboard.MPRemoteBoard) bool

Reset the board

Parameters:

board (mpflash.mpremoteboard.MPRemoteBoard)

Return type:

bool

mcu_stubber.run_createstubs(dest: pathlib.Path, mcu: mpflash.mpremoteboard.MPRemoteBoard, variant: Variant = Variant.db, mount_vfs: bool = True)

Run a createstubs[variant] on the provided board. Retry running the command up to 10 times, with a 15 second timeout between retries. this should allow for the boards with little memory to complete even if they run out of memory.

Parameters:
mcu_stubber.build_cmd(dest: pathlib.Path | None, variant: Variant = Variant.db) List[str]

Build the import createstubs[_??] command to run on the board

Parameters:
Return type:

List[str]

mcu_stubber.ensure_lib_directory(mcu: mpflash.mpremoteboard.MPRemoteBoard)

Create lib directory and add to sys.path for mip_install.

mpremote mip requires a lib path in sys.path but does not create the directory itself. This must be called before mip_install.

Parameters:

mcu (mpflash.mpremoteboard.MPRemoteBoard)

mcu_stubber.generate_board_stubs(dest: pathlib.Path, mcu: mpflash.mpremoteboard.MPRemoteBoard, variant: Variant = Variant.db, form: Form = Form.mpy, mount_vfs: bool = True, exclude: List[str] | None = None) Tuple[int, pathlib.Path | None]

Generate the firmware stubs (formerly MCU stubs) for this MCU board. :param dest: The destination folder for the stubs :type dest: Path :param port: The port the board is connected to :type port: str

Parameters:
Return type:

Tuple[int, Optional[pathlib.Path]]

mcu_stubber.copy_boardname_to_board(mcu: mpflash.mpremoteboard.MPRemoteBoard)

Copies the board name to the board by writing it to the ‘boardname.py’ file.

Parameters:

mcu (mpflash.mpremoteboard.MPRemoteBoard) – The MCU object representing the microcontroller.

Returns:

None

mcu_stubber.install_scripts_to_board(mcu: mpflash.mpremoteboard.MPRemoteBoard, form: Form)

Copy the createstubs script(s) to the board. The scripts are sourced from the ‘board’ folder that is included

  • in the micropython-stubber package.

  • or in de repo during development

Parameters:
  • mcu (str) – The microcontroller unit.

  • variant (str) – The variant of the board.

  • form (Form) – The form of the scripts to be copied.

Returns:

True if the scripts are successfully copied, False otherwise.

Return type:

bool

mcu_stubber.get_stubfolder(out: List[str])
Parameters:

out (List[str])

mcu_stubber.set_loglevel(verbose: int) str

Set log level based on verbose level Get the level from the verbose setting (0=INFO, 1=DEBUG, 2=TRACE) Set the format string, based on the level. Add the handler to the logger, with the level and format string. Return the level

Parameters:

verbose (int)

Return type:

str

mcu_stubber.copy_to_repo(source: pathlib.Path, fw: dict) pathlib.Path | None

Copy the generated stubs to the stubs repo. If the destination folder exists, it is first emptied when successful: returns the destination path - None otherwise

Parameters:
Return type:

Optional[pathlib.Path]

mcu_stubber.stub_connected_mcus(variant: str, format: str, debug: bool, serial: List[str], ignore: List[str], bluetooth: bool, exclude: List[str] | None = None, mount_vfs: bool = True) int

Runs the stubber to generate stubs for connected MicroPython boards.

Parameters:
  • variant (str) – The variant of the createstubs script.

  • format (str) – The format of the createstubs script.

  • debug (bool) – Flag indicating whether to enable debug mode.

  • serial (List[str])

  • ignore (List[str])

  • bluetooth (bool)

  • exclude (Union[List[str], None])

  • mount_vfs (bool)

Returns:

None

Return type:

int

mcu_stubber.print_publish_table(all_built: List, console: rich.console.Console | None = None)
Parameters:
  • all_built (List)

  • console (Optional[rich.console.Console])

mcu_stubber.print_stub_locations_table(stub_locations: List, console: rich.console.Console | None = None)

Print a table of stub locations for generated stubs.

Parameters:
  • stub_locations (List)

  • console (Optional[rich.console.Console])