Skip to content

Commit 07408cb

Browse files
committed
unix: Make micropython -m <module> work for frozen modules.
This requires some special handling, which was previosuly applied only to the main code path.
1 parent d7192fe commit 07408cb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

py/builtinimport.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
268268
mp_lexer_t *lex = mp_find_frozen_module(mod_str, mod_len);
269269
if (lex != NULL) {
270270
module_obj = mp_obj_new_module(module_name_qstr);
271+
// if args[3] (fromtuple) has magic value False, set up
272+
// this module for command-line "-m" option (set module's
273+
// name to __main__ instead of real name).
274+
// TODO: Duplicated below too.
275+
if (fromtuple == mp_const_false) {
276+
mp_obj_module_t *o = module_obj;
277+
mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
278+
}
271279
do_load_from_lexer(module_obj, lex, mod_str);
272280
return module_obj;
273281
}

0 commit comments

Comments
 (0)