10000 py/modsys: Introduce sys.implementation._machine constant. · sstobbe/micropython@402df83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 402df83

Browse files
committed
py/modsys: Introduce sys.implementation._machine constant.
This contains a string useful for identifying the underlying machine. This string is kept consistent with the second part of the REPL banner via the new config option MICROPY_BANNER_MACHINE. This makes os.uname() more or less redundant, as all the information in os.uname() is now available in the sys module. Signed-off-by: Damien George <damien@micropython.org>
1 parent 59c5d41 commit 402df83

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

docs/library/sys.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Constants
7070

7171
* *name* - string "micropython"
7272
* *version* - tuple (major, minor, micro), e.g. (1, 7, 0)
73+
* *_machine* - string describing the underlying machine
7374
* *_mpy* - supported mpy file-format version (optional attribute)
7475

7576
This object is the recommended way to distinguish MicroPython from other

ports/unix/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) {
179179

180180
STATIC int do_repl(void) {
181181
mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION);
182-
mp_hal_stdout_tx_str("; " MICROPY_PY_SYS_PLATFORM " [" MICROPY_PLATFORM_COMPILER "] version\n"
183-
"Use Ctrl-D to exit, Ctrl-E for paste mode\n");
182+
mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE);
183+
mp_hal_stdout_tx_str("\nUse Ctrl-D to exit, Ctrl-E for paste mode\n");
184184

185185
#if MICROPY_USE_READLINE == 1
186186

py/modsys.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "py/smallint.h"
3737
#include "py/runtime.h"
3838
#include "py/persistentcode.h"
39+
#include "extmod/moduplatform.h"
3940
#include "genhdr/mpversion.h"
4041

4142
#if MICROPY_PY_SYS_SETTRACE
@@ -69,34 +70,38 @@ STATIC const mp_obj_tuple_t mp_sys_implementation_version_info_obj = {
6970
3,
7071
{ I(MICROPY_VERSION_MAJOR), I(MICROPY_VERSION_MINOR), I(MICROPY_VERSION_MICRO) }
7172
};
73+
STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE);
7274
#if MICROPY_PERSISTENT_CODE_LOAD
7375
#define SYS_IMPLEMENTATION_ELEMS \
7476
MP_ROM_QSTR(MP_QSTR_micropython), \
7577
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
78+
MP_ROM_PTR(&mp_sys_implementation_machine_obj), \
7679
MP_ROM_INT(MPY_FILE_HEADER_INT)
7780
#else
7881
#define SYS_IMPLEMENTATION_ELEMS \
7982
MP_ROM_QSTR(MP_QSTR_micropython), \
80-
MP_ROM_PTR(&mp_sys_implementation_version_info_obj)
83+
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
84+
MP_ROM_PTR(&mp_sys_implementation_machine_obj)
8185
#endif
8286
#if MICROPY_PY_ATTRTUPLE
8387
STATIC const qstr impl_fields[] = {
8488
MP_QSTR_name,
8589
MP_QSTR_version,
90+
MP_QSTR__machine,
8691
#if MICROPY_PERSISTENT_CODE_LOAD
8792
MP_QSTR__mpy,
8893
#endif
8994
};
9095
STATIC MP_DEFINE_ATTRTUPLE(
9196
mp_sys_implementation_obj,
9297
impl_fields,
93-
2 + MICROPY_PERSISTENT_CODE_LOAD,
98+
3 + MICROPY_PERSISTENT_CODE_LOAD,
9499
SYS_IMPLEMENTATION_ELEMS
95100
);
96101
#else
97102
STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
98103
{&mp_type_tuple},
99-
2 + MICROPY_PERSISTENT_CODE_LOAD,
104+
3 + MICROPY_PERSISTENT_CODE_LOAD,
100105
{
101106
SYS_IMPLEMENTATION_ELEMS
102107
}

py/mpconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,15 @@ typedef double mp_float_t;
17191719
#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
17201720
#endif
17211721

1722+
// String used for the second part of the banner, and sys.implementation._machine
1723+
#ifndef MICROPY_BANNER_MACHINE
1724+
#ifdef MICROPY_HW_BOARD_NAME
1725+
#define MICROPY_BANNER_MACHINE MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME
1726+
#else
1727+
#define MICROPY_BANNER_MACHINE MICROPY_PY_SYS_PLATFORM " [" MICROPY_PLATFORM_COMPILER "] version"
1728+
#endif
1729+
#endif
1730+
17221731
// On embedded platforms, these will typically enable/disable irqs.
17231732
#ifndef MICROPY_BEGIN_ATOMIC_SECTION
17241733
#define MICROPY_BEGIN_ATOMIC_SECTION() (0)

shared/runtime/pyexec.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ STATIC int pyexec_friendly_repl_process_char(int c) {
402402
// reset friendly REPL
403403
mp_hal_stdout_tx_str("\r\n");
404404
mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION);
405-
mp_hal_stdout_tx_str("; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n");
405+
mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE);
406+
mp_hal_stdout_tx_str("\r\n");
406407
#if MICROPY_PY_BUILTINS_HELP
407408
mp_hal_stdout_tx_str("Type \"help()\" for more information.\r\n");
408409
#endif
@@ -554,7 +555,8 @@ int pyexec_friendly_repl(void) {
554555

555556
friendly_repl_reset:
556557
mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION);
557-
mp_hal_stdout_tx_str("; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n");
558+
mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE);
559+
mp_hal_stdout_tx_str("\r\n");
558560
#if MICROPY_PY_BUILTINS_HELP
559561
mp_hal_stdout_tx_str("Type \"help()\" for more information.\r\n");
560562
#endif

0 commit comments

Comments
 (0)
0