stubber.codemod.board
=====================
.. py:module:: stubber.codemod.board
.. autoapi-nested-parse::
"
Codemods to create the different variants of createstubs.py
Attributes
----------
.. autoapisummary::
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
stubber.codemod.board._DB_MODULE_DOC
stubber.codemod.board._LVGL_MODULE_DOC
Classes
-------
.. autoapisummary::
stubber.codemod.board.CreateStubsVariant
stubber.codemod.board.ReadModulesCodemod
stubber.codemod.board.ModuleDocCodemod
stubber.codemod.board.ModulesUpdateCodemod
stubber.codemod.board.LVGLCodemod
stubber.codemod.board.LowMemoryCodemod
stubber.codemod.board.DBCodemod
stubber.codemod.board.CreateStubsCodemod
Module Contents
---------------
.. py:data:: _STUBBER_MATCHER
.. py:data:: _MODULES_MATCHER
.. py:data:: _DEF_MAIN_MATCHER
.. py:data:: _PROBLEMATIC_MATCHER
.. py:data:: _EXCLUDED_MATCHER
.. py:data:: _LOW_MEM_MODULE_DOC
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""
"""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
"""
"""
.. raw:: html
.. py:data:: _DB_MODULE_DOC
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""
"""
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
"""
"""
.. raw:: html
.. py:data:: _LVGL_MODULE_DOC
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""
"""
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.
"""
"""
.. raw:: html
.. py:class:: CreateStubsVariant
Bases: :py:obj:`str`, :py:obj:`enum.Enum`
Dictates create stubs target variant.
.. py:attribute:: BASE
:value: 'base'
.. py:attribute:: MEM
:value: 'mem'
.. py:attribute:: DB
:value: 'db'
.. py:attribute:: LVGL
:value: 'lvgl'
.. py:class:: ReadModulesCodemod(context: libcst.codemod.CodemodContext, reader_node: Optional[libcst.Module] = None)
Bases: :py:obj:`libcst.codemod.Codemod`
Replaces static modules list with file-load method.
.. py:attribute:: modules_reader_node
:type: libcst.Module
.. py:method:: transform_module_impl(tree: libcst.Module) -> libcst.Module
Replaces static modules list with file-load method.
.. py:class:: ModuleDocCodemod(context: libcst.codemod.CodemodContext, module_doc: str)
Bases: :py:obj:`libcst.codemod.Codemod`
Replaces a module's docstring.
.. py:attribute:: module_doc
:type: str
.. py:method:: transform_module_impl(tree: libcst.Module) -> libcst.Module
Replaces a module's docstring.
.. py:class:: ModulesUpdateCodemod(context: libcst.codemod.CodemodContext, *, modules: Optional[stubber.codemod.modify_list.ListChangeSet] = None, problematic: Optional[stubber.codemod.modify_list.ListChangeSet] = None, excluded: Optional[stubber.codemod.modify_list.ListChangeSet] = None)
Bases: :py:obj:`libcst.codemod.Codemod`
Update or replace the static module list(s) with the provided changes.
.. py:attribute:: modules_changeset
:type: Optional[stubber.codemod.modify_list.ListChangeSet]
.. py:attribute:: problematic_changeset
:type: Optional[stubber.codemod.modify_list.ListChangeSet]
.. py:attribute:: excluded_changeset
:type: Optional[stubber.codemod.modify_list.ListChangeSet]
.. py:attribute:: modules_scope
:type: libcst.matchers.BaseMatcherNode
.. py:attribute:: problematic_scope
:type: libcst.matchers.BaseMatcherNode
.. py:attribute:: excluded_scope
:type: libcst.matchers.BaseMatcherNode
.. py:method:: iter_transforms() -> Iterator[libcst.matchers.MatcherDecoratableTransformer]
.. py:method:: transform_module_impl(tree: libcst.Module) -> libcst.Module
Update or replace the static module list(s) with the provided changes.
.. py:class:: LVGLCodemod(context: libcst.codemod.CodemodContext)
Bases: :py:obj:`libcst.codemod.Codemod`
Generates createstubs.py LVGL variant.
.. py:attribute:: modules_transform
:type: ModulesUpdateCodemod
.. py:attribute:: init_node
:type: libcst.Module
.. py:method:: transform_module_impl(tree: libcst.Module) -> libcst.Module
Generates createstubs.py LVGL variant.
.. py:class:: LowMemoryCodemod(context: libcst.codemod.CodemodContext)
Bases: :py:obj:`libcst.codemod.Codemod`
Generates createstubs.py low-memory variant.
.. py:method:: 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)
.. py:class:: DBCodemod(context: libcst.codemod.CodemodContext)
Bases: :py:obj:`libcst.codemod.Codemod`
Generates createstubs.py db variant.
.. py:method:: transform_module_impl(tree: libcst.Module) -> libcst.Module
Generates createstubs.py db variant.
.. py:class:: CreateStubsCodemod(context: libcst.codemod.CodemodContext, variant: CreateStubsVariant = CreateStubsVariant.BASE, *, modules: Optional[stubber.codemod.modify_list.ListChangeSet] = None, problematic: Optional[stubber.codemod.modify_list.ListChangeSet] = None, excluded: Optional[stubber.codemod.modify_list.ListChangeSet] = None)
Bases: :py:obj:`libcst.codemod.Codemod`
Generates createstubs.py variant based on provided variant.
.. py:attribute:: variant
:type: CreateStubsVariant
.. py:attribute:: modules_transform
:type: ModulesUpdateCodemod
.. py:method:: 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.