summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-10-25 21:16:24 +0300
committerDamien George <damien.p.george@gmail.com>2014-10-26 15:54:19 +0000
commite503512f83139429713b910d263a52732d8ceb15 (patch)
tree92e3f9bafb7ca859fadfacb9e693bd2cfa0851f9 /py
parentbc1488a05f509cd5be8bfab9574babfcb993806f (diff)
downloadmicropython-e503512f83139429713b910d263a52732d8ceb15.tar.gz
micropython-e503512f83139429713b910d263a52732d8ceb15.zip
unix: Implement -m option (execute module from stdlib).
Support for packages as argument not implemented, but otherwise error and exit handling should be correct. This for example will allow to do: pip-micropython install micropython-test.pystone micropython -m test.pystone
Diffstat (limited to 'py')
-rw-r--r--py/builtinimport.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 80c4c77f68..af93aace91 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -286,6 +286,14 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
module_obj = mp_obj_new_module(mod_name);
+ // 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) {
+ mp_obj_module_t *o = module_obj;
+ mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
+ }
+
if (stat == MP_IMPORT_STAT_DIR) {
DEBUG_printf("%s is dir\n", vstr_str(&path));
// https://docs.python.org/3/reference/import.html