Skip to content

Conversation

@laurensvalk
Copy link
Member


bricks/_common/micropython: Share mpy execution.

  • Replaces do_execute_raw_code (which came from MicroPython but was changed
    upstream) with do_execute_proto_fun so we don't fall too far behind.

  • Create shared implementation that main and imported modules can both use
    to deduplicate code.


bricks/_common/micropython: Run first mpy instead of main

Default to running the first mpy file instead of searching for main in
the metadata. Now hosts can specify the actual file name so we can include
it in on-brick UIs like on EV3.

This is distinct from __name__ == "__main__" which will still work, just as it
does in normal Python.

See pybricks/support#2364


bricks/_common/mpconfigport: Drop MICROPY_MODULE_BUILTIN_INIT.

This isn't used anywhere. The color module says it uses it, but this is not the case.

@coveralls
Copy link

coveralls commented Oct 9, 2025

Coverage Status

coverage: 59.808% (+0.01%) from 59.794%
when pulling f72f846 on mpy-updates
into 560988e on master.

#define MICROPY_PY_RANDOM_EXTRA_FUNCS (PYBRICKS_OPT_EXTRA_LEVEL1)
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC ({ extern uint32_t pbdrv_clock_get_us(void); pbdrv_clock_get_us(); })
#define MICROPY_MODULE_BUILTIN_INIT (1)
#define MICROPY_MODULE_BUILTIN_INIT (0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define MICROPY_MODULE_BUILTIN_INIT (0)
#define MICROPY_MODULE_BUILTIN_INIT (MICROPY_PY_RANDOM)

AFAICT, we still need this to seed the random module on hubs that support it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you!

…l hubs.

This is only used in the random module. The color
module says it uses it, but this is not the case.
Default to running the first `mpy` file instead of searching for __main__ in
the metadata. Now hosts can specify the actual file name so we can include
it in on-brick UIs like on EV3.

This is distinct from __name__ = "__main__" which will still work, just as it
does in normal Python.

See pybricks/support#2364
bricks/_common/micropython: Share mpy execution.

- Replaces `do_execute_raw_code` (which came from MicroPython but was changed
  upstream) with `do_execute_proto_fun` so we don't fall too far behind.

- Create shared implementation that main and imported modules can both use
  to deduplicate code.
@laurensvalk laurensvalk merged commit f72f846 into master Oct 10, 2025
32 checks passed
@dlech dlech deleted the mpy-updates branch October 10, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants