pull/12807/merge
Matthias Urlichs 2024-04-25 22:52:09 +02:00 zatwierdzone przez GitHub
commit 692e2548a3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
4 zmienionych plików z 54 dodań i 1 usunięć

Wyświetl plik

@ -8,7 +8,7 @@ Command line options
Usage::
micropython [ -h ] [ -i ] [ -O<level> ] [ -v ] [ -X <option> ] [ -c <command> | -m <module> | <script> ] [ <args> ]
micropython [ -h ] [ -i ] [ -e ] [ -O<level> ] [ -v ] [ -X <option> ] [ -c <command> | -m <module> | <script> ] [ <args> ]
Invocation options:
@ -17,6 +17,20 @@ Invocation options:
Runs the code in ``<command>``. The code can be one or more Python statements.
.. option:: -e
Runs MicroPython in "embedded mode":
* ``boot.py`` and ``main.py`` are executed; boot.py unconditionally,
``main.py`` only if no script argument is used.
* Instead of the ``readline`` library, MicroPython uses the same REPL as
on embedded systems.
This mode is mainly useful for running MicroPython as a subprocess, e.g.
for testing. For interactive use, a ``stty raw; micropython -e …; stty
-raw`` wrapper is required.
.. option:: -m <module>
Runs the module ``<module>``. The module must be in ``sys.path``.

Wyświetl plik

@ -216,6 +216,7 @@ SRC_C += \
SHARED_SRC_C += $(addprefix shared/,\
runtime/gchelper_generic.c \
timeutils/timeutils.c \
runtime/pyexec.c \
$(SHARED_SRC_C_EXTRA) \
)

Wyświetl plik

@ -53,6 +53,7 @@
#include "extmod/vfs_posix.h"
#include "genhdr/mpversion.h"
#include "input.h"
#include "shared/runtime/pyexec.h"
// Command line options, with their defaults
static bool compile_only = false;
@ -319,6 +320,9 @@ static void print_help(char **argv) {
"usage: %s [<opts>] [-X <implopt>] [-c <command> | -m <module> | <filename>]\n"
"Options:\n"
"-h : print this help message\n"
#if MICROPY_USE_READLINE == 1
"-e : embedded mode: run 'boot.py', enable raw input\n"
#endif
"-i : enable inspection via REPL after running command/module/file\n"
#if MICROPY_DEBUG_PRINTERS
"-v : verbose (trace various operations); can be multiple\n"
@ -622,6 +626,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
const int NOTHING_EXECUTED = -2;
int ret = NOTHING_EXECUTED;
bool inspect = false;
#if MICROPY_USE_READLINE == 1
bool embed = false;
#endif
for (int a = 1; a < argc; a++) {
if (argv[a][0] == '-') {
if (strcmp(argv[a], "-i") == 0) {
@ -634,6 +641,11 @@ MP_NOINLINE int main_(int argc, char **argv) {
set_sys_argv(argv, argc, a + 2); // Then what comes after the command
ret = do_str(argv[a + 1]);
break;
#if MICROPY_USE_READLINE == 1
} else if (strcmp(argv[a], "-e") == 0) {
embed = true;
pyexec_file_if_exists("boot.py");
#endif
} else if (strcmp(argv[a], "-m") == 0) {
if (a + 1 >= argc) {
return invalid_args();
@ -729,6 +741,29 @@ MP_NOINLINE int main_(int argc, char **argv) {
inspect = true;
}
if (ret == NOTHING_EXECUTED || inspect) {
#if MICROPY_USE_READLINE == 1
if (embed) {
// Run main.py if not told otherwise
if (ret == NOTHING_EXECUTED) {
ret = pyexec_file_if_exists("main.py");
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}
}
ret = 0;
for (;;) {
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
if (pyexec_raw_repl() != 0) {
break;
}
} else {
if (pyexec_friendly_repl() != 0) {
break;
}
}
}
} else
#endif
if (isatty(0) || inspect) {
prompt_read_history();
ret = do_repl();
@ -738,6 +773,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
}
}
soft_reset_exit:
#if MICROPY_PY_SYS_SETTRACE
MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL;
#endif

Wyświetl plik

@ -42,6 +42,7 @@
#include "shared/readline/readline.h"
#include "shared/runtime/pyexec.h"
#include "genhdr/mpversion.h"
#include "extmod/modplatform.h"
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
int pyexec_system_exit = 0;