From a3f9dec78852caeb56b70f1cf5cd2bd71f36c1ee Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 15 Aug 2025 13:11:51 +1000 Subject: [PATCH] py/mpconfig: Enable the sys module at all feature levels by default. This is a pretty fundamental module, and even minimal ports like unix and zephyr minimal have it enabled. So, enabled it by default at the lowest feature level. Most things in the `sys` module are configurable, and off by default, so it shouldn't add too much to ports that don't already have it enabled (which is just the minimal port). Also note that `sys` is still disabled on the bare-arm port, to keep that ultra minimal. It means we now have bare-arm without `sys` and the minimal port with `sys`. That will allow different code size comparisons if/when new `sys` features are added. Signed-off-by: Damien George --- examples/embedding/mpconfigport.h | 1 + ports/bare-arm/mpconfigport.h | 3 +++ ports/minimal/mpconfigport.h | 6 ++++++ ports/nrf/mpconfigport.h | 1 - ports/powerpc/mpconfigport.h | 1 - ports/unix/variants/minimal/mpconfigvariant.h | 3 +-- ports/zephyr/mpconfigport_minimal.h | 1 - py/mpconfig.h | 2 +- 8 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/embedding/mpconfigport.h b/examples/embedding/mpconfigport.h index ed34a5d766..b7a38aa81a 100644 --- a/examples/embedding/mpconfigport.h +++ b/examples/embedding/mpconfigport.h @@ -13,3 +13,4 @@ #define MICROPY_ENABLE_COMPILER (1) #define MICROPY_ENABLE_GC (1) #define MICROPY_PY_GC (1) +#define MICROPY_PY_SYS (0) diff --git a/ports/bare-arm/mpconfigport.h b/ports/bare-arm/mpconfigport.h index 65bb67f7b9..f4b87f23ef 100644 --- a/ports/bare-arm/mpconfigport.h +++ b/ports/bare-arm/mpconfigport.h @@ -37,6 +37,9 @@ // Python internal features #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NONE) +// Fine control over Python builtins, classes, modules, etc. +#define MICROPY_PY_SYS (0) + // Type definitions for the specific machine typedef int32_t mp_int_t; // must be pointer size diff --git a/ports/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h index 87287cbc6f..b542c124d4 100644 --- a/ports/minimal/mpconfigport.h +++ b/ports/minimal/mpconfigport.h @@ -21,6 +21,12 @@ // Use the minimum headroom in the chunk allocator for parse nodes. #define MICROPY_ALLOC_PARSE_CHUNK_INIT (16) +// Disable all optional sys module features. +#define MICROPY_PY_SYS_MODULES (0) +#define MICROPY_PY_SYS_EXIT (0) +#define MICROPY_PY_SYS_PATH (0) +#define MICROPY_PY_SYS_ARGV (0) + // type definitions for the specific machine typedef intptr_t mp_int_t; // must be pointer size diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index d944fc8a11..d361d01cce 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -289,7 +289,6 @@ #define MICROPY_PY_GENERATOR_PEND_THROW (1) #define MICROPY_PY_MATH (1) #define MICROPY_PY_STRUCT (1) -#define MICROPY_PY_SYS (1) #define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (1) #endif diff --git a/ports/powerpc/mpconfigport.h b/ports/powerpc/mpconfigport.h index 091e94bdaf..fcb66bab1e 100644 --- a/ports/powerpc/mpconfigport.h +++ b/ports/powerpc/mpconfigport.h @@ -81,7 +81,6 @@ #define MICROPY_PY_CMATH (0) #define MICROPY_PY_IO (0) #define MICROPY_PY_STRUCT (1) -#define MICROPY_PY_SYS (1) #define MICROPY_MODULE_FROZEN_MPY (1) #define MICROPY_CPYTHON_COMPAT (0) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) diff --git a/ports/unix/variants/minimal/mpconfigvariant.h b/ports/unix/variants/minimal/mpconfigvariant.h index 97ed786b8f..2edac41c7f 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.h +++ b/ports/unix/variants/minimal/mpconfigvariant.h @@ -61,6 +61,5 @@ #define MICROPY_PY_BUILTINS_RANGE_ATTRS (1) #define MICROPY_PY_GENERATOR_PEND_THROW (1) -// Enable just the sys and os built-in modules. -#define MICROPY_PY_SYS (1) +// Add just the os built-in module. #define MICROPY_PY_OS (1) diff --git a/ports/zephyr/mpconfigport_minimal.h b/ports/zephyr/mpconfigport_minimal.h index 24e0c9f1ad..c802ba5254 100644 --- a/ports/zephyr/mpconfigport_minimal.h +++ b/ports/zephyr/mpconfigport_minimal.h @@ -59,7 +59,6 @@ #define MICROPY_PY_BUILTINS_STR_OP_MODULO (1) #define MICROPY_PY_BUILTINS_BYTEARRAY (1) #define MICROPY_PY_BUILTINS_DICT_FROMKEYS (1) -#define MICROPY_PY_SYS (1) #ifdef CONFIG_BOARD #define MICROPY_HW_BOARD_NAME "zephyr-" CONFIG_BOARD diff --git a/py/mpconfig.h b/py/mpconfig.h index 877b262c8b..303eb08f90 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1610,7 +1610,7 @@ typedef time_t mp_timestamp_t; // Whether to provide "sys" module #ifndef MICROPY_PY_SYS -#define MICROPY_PY_SYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) +#define MICROPY_PY_SYS (1) #endif // Whether to initialise "sys.path" and "sys.argv" to their defaults in mp_init()