diff options
| author | Damien George <damien@micropython.org> | 2022-04-21 16:30:23 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-04-28 15:23:17 +1000 |
| commit | 40047823bcde4ff97b91fdc19d3d5e8f575e4dde (patch) | |
| tree | 84cb207f7b42ca18c28c5c6107d4a8552e574810 /py | |
| parent | 9d08eb02474fcace0a81dd3518b938afbf1486eb (diff) | |
py/modsys: Append MicroPython git version and build date to sys.version.
This commit adds the git hash and build date to sys.version. This is
allowed according to CPython docs, and is what PyPy does. The docs state:
A string containing the version number of the Python interpreter plus
additional information on the build number and compiler used.
Eg on CPython:
Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]'
and PyPy:
Python 2.7.12 (5.6.0+dfsg-4, Nov 20 2016, 10:43:30)
[PyPy 5.6.0 with GCC 6.2.0 20161109] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.version
'2.7.12 (5.6.0+dfsg-4, Nov 20 2016, 10:43:30)\n[PyPy 5.6.0 with GCC ...
With this commit on MicroPython we now have:
MicroPython v1.18-371-g9d08eb024 on 2022-04-28; linux [GCC 11.2.0] v...
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import sys
>>> sys.version
'3.4.0; MicroPython v1.18-371-g9d08eb024 on 2022-04-28'
Note that the start of the banner is the same as the end of sys.version.
This helps to keep code size under control because the string can be reused
by the compiler.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py')
| -rw-r--r-- | py/modsys.c | 3 | ||||
| -rw-r--r-- | py/mpconfig.h | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/py/modsys.c b/py/modsys.c index ac9077622..bdc4d6973 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -36,6 +36,7 @@ #include "py/smallint.h" #include "py/runtime.h" #include "py/persistentcode.h" +#include "genhdr/mpversion.h" #if MICROPY_PY_SYS_SETTRACE #include "py/objmodule.h" @@ -54,7 +55,7 @@ const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adap #endif // version - Python language version that this implementation conforms to, as a string -STATIC const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0"); +STATIC const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); // version_info - Python language version that this implementation conforms to, as a tuple of ints #define I(n) MP_OBJ_NEW_SMALL_INT(n) diff --git a/py/mpconfig.h b/py/mpconfig.h index c308c31bd..0b190a997 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1714,6 +1714,11 @@ typedef double mp_float_t; #define MICROPY_OBJ_BASE_ALIGNMENT #endif +// String used for the banner, and sys.version additional information +#ifndef MICROPY_BANNER_NAME_AND_VERSION +#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE +#endif + // On embedded platforms, these will typically enable/disable irqs. #ifndef MICROPY_BEGIN_ATOMIC_SECTION #define MICROPY_BEGIN_ATOMIC_SECTION() (0) |
