stubber.codemod.board

” Codemods to create the different variants of createstubs.py

Module Contents

Classes

CreateStubsVariant

Dictates create stubs target variant.

ReadModulesCodemod

Replaces static modules list with file-load method.

ModuleDocCodemod

Replaces a module's docstring.

ModulesUpdateCodemod

Update or replace the static module list(s) with the provided changes.

LVGLCodemod

Generates createstubs.py LVGL variant.

LowMemoryCodemod

Generates createstubs.py low-memory variant.

DBCodemod

Generates createstubs.py db variant.

CreateStubsCodemod

Generates createstubs.py variant based on provided variant.

Attributes

_STUBBER_MATCHER

_MODULES_MATCHER

_DEF_MAIN_MATCHER

_PROBLEMATIC_MATCHER

_EXCLUDED_MATCHER

_LOW_MEM_MODULE_DOC

_DB_MODULE_DOC

_LVGL_MODULE_DOC

stubber.codemod.board._STUBBER_MATCHER
stubber.codemod.board._MODULES_MATCHER
stubber.codemod.board._DEF_MAIN_MATCHER
stubber.codemod.board._PROBLEMATIC_MATCHER
stubber.codemod.board._EXCLUDED_MATCHER
stubber.codemod.board._LOW_MEM_MODULE_DOC = Multiline-String
Show Value
"""
"""Create stubs for (all) modules on a MicroPython board.

    This variant of the createstubs.py script is optimised for use on low-memory devices, and reads the list of modules from a text file
    `modulelist.txt` in the root or `libs` folder that should be uploaded to the device.
    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:
    - minifification, using python-minifier
      to reduce overall size, and remove logging overhead.
    - cross compilation, using mpy-cross,
      to avoid the compilation step on the micropython device
"""
"""
stubber.codemod.board._DB_MODULE_DOC = Multiline-String
Show Value
"""
"""
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

"""
"""
stubber.codemod.board._LVGL_MODULE_DOC = Multiline-String
Show Value
"""
"""
Create stubs for the lvgl modules on a MicroPython board.

Note that the stubs can be very large, and it may be best to directly store them on an SD card if your device supports this.
"""
"""
class stubber.codemod.board.CreateStubsVariant

Bases: str, enum.Enum

Dictates create stubs target variant.

BASE = 'base'
MEM = 'mem'
DB = 'db'
LVGL = 'lvgl'
class stubber.codemod.board.ReadModulesCodemod(context: libcst.codemod.CodemodContext, reader_node: libcst.Module | None = None)

Bases: libcst.codemod.Codemod

Replaces static modules list with file-load method.

Parameters:
  • context (libcst.codemod.CodemodContext) –

  • reader_node (Optional[libcst.Module]) –

modules_reader_node: libcst.Module
transform_module_impl(tree: libcst.Module) libcst.Module

Replaces static modules list with file-load method.

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module

class stubber.codemod.board.ModuleDocCodemod(context: libcst.codemod.CodemodContext, module_doc: str)

Bases: libcst.codemod.Codemod

Replaces a module’s docstring.

Parameters:
  • context (libcst.codemod.CodemodContext) –

  • module_doc (str) –

module_doc: str
transform_module_impl(tree: libcst.Module) libcst.Module

Replaces a module’s docstring.

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module

class stubber.codemod.board.ModulesUpdateCodemod(context: libcst.codemod.CodemodContext, *, modules: stubber.codemod.modify_list.ListChangeSet | None = None, problematic: stubber.codemod.modify_list.ListChangeSet | None = None, excluded: stubber.codemod.modify_list.ListChangeSet | None = None)

Bases: libcst.codemod.Codemod

Update or replace the static module list(s) with the provided changes.

Parameters:
modules_changeset: stubber.codemod.modify_list.ListChangeSet | None
problematic_changeset: stubber.codemod.modify_list.ListChangeSet | None
excluded_changeset: stubber.codemod.modify_list.ListChangeSet | None
modules_scope: libcst.matchers.BaseMatcherNode
problematic_scope: libcst.matchers.BaseMatcherNode
excluded_scope: libcst.matchers.BaseMatcherNode
iter_transforms() Iterator[libcst.matchers.MatcherDecoratableTransformer]
Return type:

Iterator[libcst.matchers.MatcherDecoratableTransformer]

transform_module_impl(tree: libcst.Module) libcst.Module

Update or replace the static module list(s) with the provided changes.

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module

class stubber.codemod.board.LVGLCodemod(context: libcst.codemod.CodemodContext)

Bases: libcst.codemod.Codemod

Generates createstubs.py LVGL variant.

Parameters:

context (libcst.codemod.CodemodContext) –

modules_transform: ModulesUpdateCodemod
init_node: libcst.Module
transform_module_impl(tree: libcst.Module) libcst.Module

Generates createstubs.py LVGL variant.

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module

class stubber.codemod.board.LowMemoryCodemod(context: libcst.codemod.CodemodContext)

Bases: libcst.codemod.Codemod

Generates createstubs.py low-memory variant.

Parameters:

context (libcst.codemod.CodemodContext) –

transform_module_impl(tree: libcst.Module) libcst.Module

Generates createstubs.py low-memory variant. - replace the static module list with the low-memory variant (read from file)

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module

class stubber.codemod.board.DBCodemod(context: libcst.codemod.CodemodContext)

Bases: libcst.codemod.Codemod

Generates createstubs.py db variant.

Parameters:

context (libcst.codemod.CodemodContext) –

transform_module_impl(tree: libcst.Module) libcst.Module

Generates createstubs.py db variant.

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module

class stubber.codemod.board.CreateStubsCodemod(context: libcst.codemod.CodemodContext, variant: CreateStubsVariant = CreateStubsVariant.BASE, *, modules: stubber.codemod.modify_list.ListChangeSet | None = None, problematic: stubber.codemod.modify_list.ListChangeSet | None = None, excluded: stubber.codemod.modify_list.ListChangeSet | None = None)

Bases: libcst.codemod.Codemod

Generates createstubs.py variant based on provided variant.

Parameters:
variant: CreateStubsVariant
modules_transform: ModulesUpdateCodemod
transform_module_impl(tree: libcst.Module) libcst.Module

Generates a createstubs.py variant based on provided flavor. Transform it to emit the appropriate variant of createstubs.py, Optionally allows to replace the - list of modules to stub. (if relevant for the flavour) - list of problematic modules. - list of excluded modules.

Parameters:

tree (libcst.Module) –

Return type:

libcst.Module