Skip to content

Commit 3a159a5

Browse files
committed
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
1 parent 41418a7 commit 3a159a5

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

bricks/_common/micropython.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,8 @@ static void run_user_program(void) {
234234
if (nlr_push(&nlr) == 0) {
235235
nlr_set_abort(&nlr);
236236

237-
mpy_info_t *info = mpy_data_find(MP_QSTR___main__);
238-
239-
if (!info) {
240-
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("no __main__ module"));
241-
}
237+
// Main program is in the first mpy file.
238+
mpy_info_t *info = mpy_first;
242239

243240
// This is similar to __import__ except we don't push/pop globals
244241
mp_reader_t reader;

0 commit comments

Comments
 (0)