createstubs_db

Create stubs for (all) modules on a MicroPython board.

This variant of the createstubs.py script is optimized for use on very-low-memory devices. Note: this version has undergone limited testing.

  1. reads the list of modules from a text file modulelist.txt that should be uploaded to the device.

  2. stored the already processed modules in a text file modulelist.done

  3. process the modules in the database:
    • stub the module

    • update the modulelist.done file

    • reboots the device if it runs out of memory

  4. creates the modules.json

If that cannot be found then only a single module (micropython) is stubbed. In order to run this on low-memory devices two additional steps are recommended: - minification, using python-minifierto reduce overall size, and remove logging overhead. - cross compilation, using mpy-cross, to avoid the compilation step on the micropython device

This variant was generated from createstubs.py by micropython-stubber v1.17.2

Module Contents

Classes

logging

Stubber

Generate stubs for modules in firmware

Functions

ensure_folder(path)

Create nested folders if needed

_build(s)

_info(→ dict[str, str])

version_str(version)

get_boardname(→ str)

Read the board name from the boardname.py file that may have been created upfront

get_root(→ str)

Determine the root folder of the device

file_exists(filename)

show_help()

read_path(→ str)

get --path from cmdline. [unix/win]

is_micropython(→ bool)

runtime test to determine full or micropython

get_modules([skip])

write_skip(done)

read_skip()

main()

Attributes

__version__

ENOENT

_MAX_CLASS_LEVEL

LIBS

log

SKIP_FILE

createstubs_db.__version__ = 'v1.17.2'
createstubs_db.ENOENT = 2
createstubs_db._MAX_CLASS_LEVEL = 2
createstubs_db.LIBS = ['lib', '/lib', '/sd/lib', '/flash/lib', '.']
class createstubs_db.logging
INFO = 20
WARNING = 30
ERROR = 40
level
prnt
static getLogger(name)
classmethod basicConfig(level)
info(msg)
warning(msg)
error(msg)
createstubs_db.log
class createstubs_db.Stubber(path: str = None, firmware_id: str = None)

Generate stubs for modules in firmware

Parameters:
  • path (str) –

  • firmware_id (str) –

property flat_fwid

Turn _fwid from ‘v1.2.3’ into ‘1_2_3’ to be used in filename

get_obj_attributes(item_instance: object)

extract information of the objects members and attributes

Parameters:

item_instance (object) –

add_modules(modules)

Add additional modules to be exported

create_all_stubs()

Create stubs for all configured modules

create_one_stub(module_name: str)
Parameters:

module_name (str) –

create_module_stub(module_name: str, file_name: str = None) bool

Create a Stub of a single python module

Args: - module_name (str): name of the module to document. This module will be imported. - file_name (Optional[str]): the ‘path/filename.pyi’ to write to. If omitted will be created based on the module name.

Parameters:
  • module_name (str) –

  • file_name (str) –

Return type:

bool

write_object_stub(fp, object_expr: object, obj_name: str, indent: str, in_class: int = 0)

Write a module/object stub to an open file. Can be called recursive.

Parameters:
  • object_expr (object) –

  • obj_name (str) –

  • indent (str) –

  • in_class (int) –

clean(path: str = None)

Remove all files from the stub folder

Parameters:

path (str) –

report_start(filename: str = 'modules.json')

Start a report of the modules that have been stubbed “create json with list of exported modules

Parameters:

filename (str) –

report_add(module_name: str, stub_file: str)

Add a module to the report

Parameters:
  • module_name (str) –

  • stub_file (str) –

report_end()
createstubs_db.ensure_folder(path: str)

Create nested folders if needed

Parameters:

path (str) –

createstubs_db._build(s)
createstubs_db._info() dict[str, str]
Return type:

dict[str, str]

createstubs_db.version_str(version: tuple)
Parameters:

version (tuple) –

createstubs_db.get_boardname() str

Read the board name from the boardname.py file that may have been created upfront

Return type:

str

createstubs_db.get_root() str

Determine the root folder of the device

Return type:

str

createstubs_db.file_exists(filename: str)
Parameters:

filename (str) –

createstubs_db.show_help()
createstubs_db.read_path() str

get –path from cmdline. [unix/win]

Return type:

str

createstubs_db.is_micropython() bool

runtime test to determine full or micropython

Return type:

bool

createstubs_db.SKIP_FILE = 'modulelist.done'
createstubs_db.get_modules(skip=0)
createstubs_db.write_skip(done)
createstubs_db.read_skip()
createstubs_db.main()