Skip to content

[Bug] REPL auto-import does not work. #741

Closed

Description

@laurensvalk

When starting the REPL, everything in the pybricks package is supposed to be pre-imported.

This no longer works because:

    for (size_t i = 0; i < MP_ARRAY_SIZE(pybricks_globals_table); i++) {
        mp_rom_obj_t module = pybricks_globals_table[i].value;
        if (mp_obj_is_type(module, &mp_type_module)) {
            // Import everything from the module.
            mp_import_all((mp_obj_t)module);
        }
    }

and the modules are no longer included in pybricks_globals_table.

Activity

  1. added
    software: pybricks-micropython
    on Oct 20, 2022
  2. self-assigned this
    on Oct 20, 2022
  3. laurensvalk commented on Oct 20, 2022

    @laurensvalk
    MemberAuthor

    While we are doing this, we could consider importing everything, including those from MicroPython modules. I'll have a look at the RAM cost.

  4. laurensvalk commented on Oct 20, 2022

    @laurensvalk
    MemberAuthor

    While we are doing this, we could consider importing everything, including those from MicroPython modules. I'll have a look at the RAM cost

    On Prime Hub, when importing everything:

    stack: 604 out of 36976
    GC: total: 259008, used: 2272, free: 256736
     No. of 1-blocks: 14, 2-blocks: 3, max blk sz: 112, max free sz: 15915
    

    When importing only pybricks modules (+36 bytes build size for the check):

    stack: 604 out of 36976
    GC: total: 259008, used: 1008, free: 258000
     No. of 1-blocks: 20, 2-blocks: 4, max blk sz: 19, max free sz: 16116
    

    So, about 1.2K extra heap used for importing everything from the (currently included) MicroPython modules.

    Now check on Move Hub. Oh wait, no REPL. 😆

    So I think we can just import everything. If anyone ever needs the REPL and use RAM to the limits, they can just run an empty script that raises the KeyboardInterrupt.

  5. dlech commented on Oct 20, 2022

    @dlech
    Member

    Are we sure that there are and never will be name conflicts for importing * from *? It seems like it would be safer to import * from pybricks modules but import module for everything else.

  6. laurensvalk commented on Oct 20, 2022

    @laurensvalk
    MemberAuthor

    OK, I'll restore importing Pybricks modules only.

  7. dlech commented on Oct 20, 2022

    @dlech
    Member

    I like the idea of importing the other modules too. Maybe we could import * if module starts with pybricks else import module?

  8. laurensvalk commented on Oct 20, 2022

    @laurensvalk
    MemberAuthor

    Sure. Will do that tomorrow.

  9. laurensvalk commented on Oct 20, 2022

    @laurensvalk
    MemberAuthor

    mp_import_name and several other related calls just fetch the module but don't register it as loaded. Simply doing it like pybricks/pybricks-micropython@7b57a7a works though.

  10. dlech commented on Oct 21, 2022

    @dlech
    Member

    can this be closed now?

  11. laurensvalk commented on Oct 21, 2022

    @laurensvalk
    MemberAuthor

    Yes.

  12. added theissue type on Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

software: pybricks-micropython

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions