8000 ports: Add '.frozen' as the first entry in sys.path. · micropython/micropython@86ce442 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86ce442

Browse files
jimmodpgeorge
authored andcommitted
ports: Add '.frozen' as the first entry in sys.path.
Frozen modules will be searched preferentially, but gives the user the ability to override this behavior. This matches the previous behavior where "" was implicitly the frozen search path, but the frozen list was checked before the filesystem. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent d6d4a58 commit 86ce442

File tree

10 files changed

+33
-9
lines changed

10 files changed

+33
-9
lines changed

ports/esp32/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ void mp_task(void *pvParameter) {
141141
gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
142142
mp_init();
143143
mp_obj_list_init(mp_sys_path, 0);
144+
#if MICROPY_MODULE_FROZEN
145+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
146+
#endif
144147
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
145148
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
146149
mp_obj_list_init(mp_sys_argv, 0);

ports/esp8266/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ STATIC void mp_reset(void) {
5353
gc_init(heap, heap + sizeof(heap));
5454
mp_init();
5555
mp_obj_list_init(mp_sys_path, 0);
56+
#if MICROPY_MODULE_FROZEN
57+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
58+
#endif
5659
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
5760
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
5861
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));

ports/mimxrt/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ int main(void) {
7676
mp_init();
7777

7878
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
79+
#if MICROPY_MODULE_FROZEN
80+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
81+
#endif
7982
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
8083
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
8184
#if MICROPY_PY_NETWORK

ports/nrf/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ int main(int argc, char **argv) {
130130

131131
mp_init();
132132
mp_obj_list_init(mp_sys_path, 0);
133+
#if MICROPY_MODULE_FROZEN
134+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
135+
#endif
133136
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
134137
mp_obj_list_init(mp_sys_argv, 0);
135138

ports/rp2/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ int main(int argc, char **argv) {
101101
// Initialise MicroPython runtime.
102102
mp_init();
103103
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
104+
#if MICROPY_MODULE_FROZEN
105+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
106+
#endif
104107
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
105108
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
106109
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);

ports/stm32/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ void stm32_main(uint32_t reset_mode) {
495495
// MicroPython init
496496
mp_init();
497497
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
498+
#if MICROPY_MODULE_FROZEN
499+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
500+
#endif
498501
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
499502
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
500503

ports/unix/main.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
495495
char *home = getenv("HOME");
496496
char *path = getenv("MICROPYPATH");
497497
if (path == NULL) {
498-
#ifdef MICROPY_PY_SYS_PATH_DEFAULT
499498
path = MICROPY_PY_SYS_PATH_DEFAULT;
500-
#else
501-
path = "~/.micropython/lib:/usr/lib/micropython";
502-
#endif
503499
}
504-
size_t path_num = 1; // [0] is for current dir (or base dir of the script)
500+
size_t path_num = 2; // [0] is frozen, [1] is for current dir (or base dir of the script)
505501
if (*path == PATHLIST_SEP_CHAR) {
506502
path_num++;
507503
}
@@ -514,10 +510,11 @@ MP_NOINLINE int main_(int argc, char **argv) {
514510
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), path_num);
515511
mp_obj_t *path_items;
516512
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
517-
path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_);
513+
path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen);
514+
path_items[1] = MP_OBJ_NEW_QSTR(MP_QSTR_);
518515
{
519516
char *p = path;
520-
for (mp_uint_t i = 1; i < path_num; i++) {
517+
for (mp_uint_t i = 2; i < path_num; i++) {
521518
char *p1 = strchr(p, PATHLIST_SEP_CHAR);
522519
if (p1 == NULL) {
523520
p1 = p + strlen(p);
@@ -658,9 +655,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
658655
break;
659656
}
660657

661-
// Set base dir of the script as first entry in sys.path
658+
// Set base dir of the script as second entry in sys.path.
662659
char *p = strrchr(basedir, '/');
663-
path_items[0] = mp_obj_new_str_via_qstr(basedir, p - basedir);
660+
path_items[1] = mp_obj_new_str_via_qstr(basedir, p - basedir);
664661
free(pathbuf);
665662

666663
set_sys_argv(argv, argc, a);

ports/unix/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
#define MICROPY_PY_SYS_PLATFORM "linux"
124124
#endif
125125
#endif
126+
#ifndef MICROPY_PY_SYS_PATH_DEFAULT
127+
#define MICROPY_PY_SYS_PATH_DEFAULT "~/.micropython/lib:/usr/lib/micropython"
128+
#endif
126129
#define MICROPY_PY_SYS_MAXSIZE (1)
127130
#define MICROPY_PY_SYS_STDFILES (1)
128131
#define MICROPY_PY_SYS_EXC_INFO (1)

ports/unix/variants/minimal/mpconfigvariant.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@
8888
#define MICROPY_PY_SYS (1)
8989
#define MICROPY_PY_SYS_EXIT (0)
9090
#define MICROPY_PY_SYS_PLATFORM "linux"
91+
#ifndef MICROPY_PY_SYS_PATH_DEFAULT
92+
#define MICROPY_PY_SYS_PATH_DEFAULT "~/.micropython/lib:/usr/lib/micropython"
93+
#endif
9194
#define MICROPY_PY_SYS_MAXSIZE (0)
9295
#define MICROPY_PY_SYS_STDFILES (0)
9396
#define MICROPY_PY_CMATH (0)

shared/upytesthelper/upytesthelper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ void upytest_execute_test(const char *src) {
9494
gc_init(heap_start, heap_end);
9595
mp_init();
9696
mp_obj_list_init(mp_sys_path, 0);
97+
#if MICROPY_MODULE_FROZEN
98+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
99+
#endif
97100
mp_obj_list_init(mp_sys_argv, 0);
98101

99102
nlr_buf_t nlr;

0 commit comments

Comments
 (0)
0