diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-05-09 14:22:21 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-05-09 14:22:21 +0300 |
commit | edc02bd952ed4a2042f81b0eaa41f0168ed3d98d (patch) | |
tree | 7691b0c2fee9c44ca951ba17b369a572a66afbcb /py/builtinimport.c | |
parent | 9bd67d9fbc09823e33642e7ec709afbf88d11d0a (diff) | |
download | micropython-edc02bd952ed4a2042f81b0eaa41f0168ed3d98d.tar.gz micropython-edc02bd952ed4a2042f81b0eaa41f0168ed3d98d.zip |
unix/main: Implement -m option for packages.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index cf17d53053..d01ebbe73f 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -429,8 +429,13 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { // if args[3] (fromtuple) has magic value False, set up // this module for command-line "-m" option (set module's - // name to __main__ instead of real name). - if (i == mod_len && fromtuple == mp_const_false) { + // name to __main__ instead of real name). Do this only + // for *modules* however - packages never have their names + // replaced, instead they're -m'ed using a special __main__ + // submodule in them. (This all apparently is done to not + // touch package name itself, which is important for future + // imports). + if (i == mod_len && fromtuple == mp_const_false && stat != MP_IMPORT_STAT_DIR) { mp_obj_module_t *o = MP_OBJ_TO_PTR(module_obj); mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__)); #if MICROPY_CPYTHON_COMPAT |