Skip to content

Commit a63555a

Browse files
committed
py/builtinimport: Set __file__ on MPY modules
This sets the __file__ property on MPY modules like how it's done on pure python modules.
1 parent c23d202 commit a63555a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

py/builtinimport.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex) {
155155
#endif
156156

157157
#if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_MODULE_FROZEN_MPY
158-
STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) {
158+
STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code, const char *filename) {
159159
#if MICROPY_PY___FILE__
160-
// TODO
161-
//qstr source_name = lex->source_name;
162-
//mp_store_attr(module_obj, MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name));
160+
mp_store_attr(module_obj, MP_QSTR___file__, MP_OBJ_NEW_QSTR(qstr_from_str(filename)));
163161
#endif
164162

165163
// execute the module in its context
@@ -222,7 +220,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
222220
// its data) in the list of frozen files, execute it.
223221
#if MICROPY_MODULE_FROZEN_MPY
224222
if (frozen_type == MP_FROZEN_MPY) {
225-
do_execute_raw_code(module_obj, modref);
223+
do_execute_raw_code(module_obj, modref, file_str);
226224
return;
227225
}
228226
#endif
@@ -235,7 +233,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
235233
#if MICROPY_PERSISTENT_CODE_LOAD
236234
if (file_str[file->len - 3] == 'm') {
237235
mp_raw_code_t *raw_code = mp_raw_code_load_file(file_str);
238-
do_execute_raw_code(module_obj, raw_code);
236+
do_execute_raw_code(module_obj, raw_code, file_str);
239237
return;
240238
}
241239
#endif

0 commit comments

Comments
 (0)