createstubs

Create stubs for (all) modules on a MicroPython board

Attributes

_LOW_MEM_PORTS

_is_low_mem_port

_has_inspect

_has_inspect

__version__

ENOENT

ENOMESSAGE

_MAX_CLASS_LEVEL

LIBS

log

Classes

logging

Stubber

Generate stubs for modules in firmware

Functions

reset()

ensure_folder(path)

Create nested folders if needed

_build(s)

_get_base_system_info(→ collections.OrderedDict[str, str])

Get basic system implementation details.

_normalize_port_info(→ None)

Normalize port names to be consistent with the repo.

_extract_version_info(→ None)

Extract version information from sys.implementation.

_extract_hardware_info(→ None)

Extract board, CPU, and machine details.

_extract_build_info(→ None)

Extract build information from various system sources.

_detect_firmware_family(→ None)

Detect special firmware families (pycopy, pycom, ev3-pybricks).

_process_micropython_version(→ None)

Process MicroPython-specific version formatting.

_process_mpy_info(→ None)

Process MPY architecture and version information.

_format_version_strings(→ None)

Handle final version string formatting.

_info(→ dict[str, str])

Gather comprehensive system information for MicroPython stubbing.

_version_str(version)

get_boardname(→ None)

Read the board_id 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

main()

Module Contents

createstubs.reset()
createstubs._LOW_MEM_PORTS = ('esp8266',)
createstubs._is_low_mem_port = False
createstubs._has_inspect = False
createstubs._has_inspect = True
createstubs.__version__ = 'v1.28.3'
createstubs.ENOENT = 2
createstubs.ENOMESSAGE = 44
createstubs._MAX_CLASS_LEVEL = 2
createstubs.LIBS = ['lib', '/lib', '/sd/lib', '/flash/lib', '.']
class createstubs.logging
DEBUG = 10
INFO = 20
WARNING = 30
ERROR = 40
level = 20
prnt
static getLogger(name)
classmethod basicConfig(level)
debug(msg)
info(msg)
warning(msg)
error(msg)
createstubs.log
class createstubs.Stubber(path: str = '', firmware_id: str = '')

Generate stubs for modules in firmware

Parameters:
  • path (str)

  • firmware_id (str)

info
_is_low_mem_port
_capture_docstrings
_use_inspect
_start_free
path
problematic = ['upip', 'upysh', 'webrepl_setup', 'http_client', 'http_client_ssl', 'http_server', 'http_server_ssl']
excluded = ['webrepl', '_webrepl', 'port_diag', 'example_sub_led.py', 'example_pub_button.py']
modules: list[str] = []
_json_name = None
_json_first = False
load_exlusions()
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_shallow_stub(fp, module_obj: object)
Parameters:

module_obj (object)

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:
property flat_fwid

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

clean(path: str = '')

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.ensure_folder(path: str)

Create nested folders if needed

Parameters:

path (str)

createstubs._build(s)
createstubs._get_base_system_info() collections.OrderedDict[str, str]

Get basic system implementation details.

Return type:

collections.OrderedDict[str, str]

createstubs._normalize_port_info(info: collections.OrderedDict[str, str]) None

Normalize port names to be consistent with the repo.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._extract_version_info(info: collections.OrderedDict[str, str]) None

Extract version information from sys.implementation.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._extract_hardware_info(info: collections.OrderedDict[str, str]) None

Extract board, CPU, and machine details.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._extract_build_info(info: collections.OrderedDict[str, str]) None

Extract build information from various system sources.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._detect_firmware_family(info: collections.OrderedDict[str, str]) None

Detect special firmware families (pycopy, pycom, ev3-pybricks).

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._process_micropython_version(info: collections.OrderedDict[str, str]) None

Process MicroPython-specific version formatting.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._process_mpy_info(info: collections.OrderedDict[str, str]) None

Process MPY architecture and version information.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._format_version_strings(info: collections.OrderedDict[str, str]) None

Handle final version string formatting.

Parameters:

info (collections.OrderedDict[str, str])

Return type:

None

createstubs._info() dict[str, str]

Gather comprehensive system information for MicroPython stubbing.

Returns a dictionary containing family, version, port, board, and other system details needed for stub generation.

Return type:

dict[str, str]

createstubs._version_str(version: tuple)
Parameters:

version (tuple)

createstubs.get_boardname(info: dict) None

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

Parameters:

info (dict)

Return type:

None

createstubs.get_root() str

Determine the root folder of the device

Return type:

str

createstubs.file_exists(filename: str)
Parameters:

filename (str)

createstubs.show_help()
createstubs.read_path() str

get –path from cmdline. [unix/win]

Return type:

str

createstubs.is_micropython() bool

runtime test to determine full or micropython

Return type:

bool

createstubs.main()