Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
377b80b6
Commit
377b80b6
authored
Sep 08, 2014
by
Damien George
Browse files
py: Print imported module's location (__file__) if available.
parent
5c00757a
Changes
2
Hide whitespace changes
Inline
Side-by-side
bare-arm/mpconfigport.h
View file @
377b80b6
...
...
@@ -17,6 +17,7 @@
#define MICROPY_PY_BUILTINS_SET (0)
#define MICROPY_PY_BUILTINS_SLICE (0)
#define MICROPY_PY_BUILTINS_PROPERTY (0)
#define MICROPY_PY___FILE__ (0)
#define MICROPY_PY_GC (0)
#define MICROPY_PY_ARRAY (0)
#define MICROPY_PY_COLLECTIONS (0)
...
...
py/objmodule.c
View file @
377b80b6
...
...
@@ -40,7 +40,19 @@ STATIC mp_map_t mp_loaded_modules_map; // TODO: expose as sys.modules
STATIC
void
module_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
mp_obj_module_t
*
self
=
self_in
;
print
(
env
,
"<module '%s' from '-unknown-file-'>"
,
qstr_str
(
self
->
name
));
const
char
*
name
=
qstr_str
(
self
->
name
);
#if MICROPY_PY___FILE__
// If we store __file__ to imported modules then try to lookup this
// symbol to give more information about the module.
mp_map_elem_t
*
elem
=
mp_map_lookup
(
&
self
->
globals
->
map
,
MP_OBJ_NEW_QSTR
(
MP_QSTR___file__
),
MP_MAP_LOOKUP
);
if
(
elem
!=
NULL
)
{
print
(
env
,
"<module '%s' from '%s'>"
,
name
,
mp_obj_str_get_str
(
elem
->
value
));
return
;
}
#endif
print
(
env
,
"<module '%s'>"
,
name
);
}
STATIC
void
module_load_attr
(
mp_obj_t
self_in
,
qstr
attr
,
mp_obj_t
*
dest
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment