py/modsys: Add support for sys.executable.
Only intended to be used on Unix and other "OS" ports. Matches CPython. This should give the absolute path to the executing binary. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com> Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
c44b3927b8
commit
0e8dfaf538
10
py/modsys.c
10
py/modsys.c
|
@ -115,6 +115,12 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
|
||||||
STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM);
|
STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MICROPY_PY_SYS_EXECUTABLE
|
||||||
|
// executable - the path to the micropython binary
|
||||||
|
// This object is non-const and is populated at startup in main()
|
||||||
|
MP_DEFINE_STR_OBJ(mp_sys_executable_obj, "");
|
||||||
|
#endif
|
||||||
|
|
||||||
// exit([retval]): raise SystemExit, with optional argument given to the exception
|
// exit([retval]): raise SystemExit, with optional argument given to the exception
|
||||||
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
|
||||||
if (n_args == 0) {
|
if (n_args == 0) {
|
||||||
|
@ -262,6 +268,10 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_PY_SYS_EXECUTABLE
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_executable), MP_ROM_PTR(&mp_sys_executable_obj) },
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extensions to CPython
|
* Extensions to CPython
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1372,6 +1372,13 @@ typedef double mp_float_t;
|
||||||
#define MICROPY_PY_SYS_EXC_INFO (0)
|
#define MICROPY_PY_SYS_EXC_INFO (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Whether to provide "sys.executable", which is the absolute path to the
|
||||||
|
// micropython binary
|
||||||
|
// Intended for use on the "OS" ports (e.g. Unix)
|
||||||
|
#ifndef MICROPY_PY_SYS_EXECUTABLE
|
||||||
|
#define MICROPY_PY_SYS_EXECUTABLE (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Whether to provide "sys.exit" function
|
// Whether to provide "sys.exit" function
|
||||||
#ifndef MICROPY_PY_SYS_EXIT
|
#ifndef MICROPY_PY_SYS_EXIT
|
||||||
#define MICROPY_PY_SYS_EXIT (1)
|
#define MICROPY_PY_SYS_EXIT (1)
|
||||||
|
|
Loading…
Reference in New Issue