Browse Source

py: Add sys.implementation, containing uPy name and version number.

Uses attrtuple if it's enabled, otherwise just a normal tuple.
pull/1194/head
Damien George 10 years ago
parent
commit
c3184aea63
  1. 31
      py/modsys.c
  2. 19
      py/py-version.sh
  3. 4
      py/qstrdefs.h

31
py/modsys.c

@ -35,6 +35,8 @@
#if MICROPY_PY_SYS #if MICROPY_PY_SYS
#include "genhdr/py-version.h"
/// \module sys - system specific functions /// \module sys - system specific functions
// defined per port; type of these is irrelevant, just need pointer // defined per port; type of these is irrelevant, just need pointer
@ -53,6 +55,34 @@ STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0");
#define I(n) MP_OBJ_NEW_SMALL_INT(n) #define I(n) MP_OBJ_NEW_SMALL_INT(n)
// TODO: CPython is now at 5-element array, but save 2 els so far... // TODO: CPython is now at 5-element array, but save 2 els so far...
STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3), I(4), I(0)}}; STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3), I(4), I(0)}};
// sys.implementation object
// this holds the MicroPython version
STATIC const mp_obj_tuple_t mp_sys_implementation_version_info_obj = {
{&mp_type_tuple},
3,
{ I(MICROPY_VERSION_MAJOR), I(MICROPY_VERSION_MINOR), I(MICROPY_VERSION_MICRO) }
};
#if MICROPY_PY_ATTRTUPLE
STATIC const qstr impl_fields[] = { MP_QSTR_name, MP_QSTR_version };
STATIC MP_DEFINE_ATTRTUPLE(
mp_sys_implementation_obj,
impl_fields,
2,
MP_OBJ_NEW_QSTR(MP_QSTR_micropython),
(mp_obj_t)&mp_sys_implementation_version_info_obj
);
#else
STATIC const mp_obj_tuple_t mp_sys_implementation_obj = {
{&mp_type_tuple},
2,
{
MP_OBJ_NEW_QSTR(MP_QSTR_micropython),
(mp_obj_t)&mp_sys_implementation_version_info_obj,
}
};
#endif
#undef I #undef I
#ifdef MICROPY_PY_SYS_PLATFORM #ifdef MICROPY_PY_SYS_PLATFORM
@ -98,6 +128,7 @@ STATIC const mp_map_elem_t mp_module_sys_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_argv), (mp_obj_t)&MP_STATE_VM(mp_sys_argv_obj) }, { MP_OBJ_NEW_QSTR(MP_QSTR_argv), (mp_obj_t)&MP_STATE_VM(mp_sys_argv_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_version), (mp_obj_t)&version_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_version), (mp_obj_t)&version_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_version_info), (mp_obj_t)&mp_sys_version_info_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_version_info), (mp_obj_t)&mp_sys_version_info_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_implementation), (mp_obj_t)&mp_sys_implementation_obj },
#ifdef MICROPY_PY_SYS_PLATFORM #ifdef MICROPY_PY_SYS_PLATFORM
{ MP_OBJ_NEW_QSTR(MP_QSTR_platform), (mp_obj_t)&platform_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_platform), (mp_obj_t)&platform_obj },
#endif #endif

19
py/py-version.sh

@ -11,9 +11,28 @@ git diff-index --cached --quiet HEAD -- 2> /dev/null || git_files_are_clean=0
if [ "${git_files_are_clean}" != "1" ]; then if [ "${git_files_are_clean}" != "1" ]; then
git_hash="${git_hash}-dirty" git_hash="${git_hash}-dirty"
fi fi
# Try to extract MicroPython version
if echo ${git_tag} | grep -q '^v[0-9]'; then
ver=$(echo ${git_tag} | cut -b 2- | cut -d - -f 1)
ver_major=$(echo ${ver} | cut -d . -f 1)
ver_minor=$(echo ${ver} | cut -d . -f 2)
ver_micro=$(echo ${ver} | cut -d . -f 3)
if [ -z ${ver_micro} ]; then
ver_micro="0"
fi
else
ver_major="0"
ver_minor="0"
ver_micro="1"
fi
cat <<EOF cat <<EOF
// This file was generated by py/py-version.sh // This file was generated by py/py-version.sh
#define MICROPY_GIT_TAG "${git_tag}" #define MICROPY_GIT_TAG "${git_tag}"
#define MICROPY_GIT_HASH "${git_hash}" #define MICROPY_GIT_HASH "${git_hash}"
#define MICROPY_BUILD_DATE "$(date '+%Y-%m-%d')" #define MICROPY_BUILD_DATE "$(date '+%Y-%m-%d')"
#define MICROPY_VERSION_MAJOR (${ver_major})
#define MICROPY_VERSION_MINOR (${ver_minor})
#define MICROPY_VERSION_MICRO (${ver_micro})
EOF EOF

4
py/qstrdefs.h

@ -450,6 +450,10 @@ Q(stdout)
Q(stderr) Q(stderr)
Q(version) Q(version)
Q(version_info) Q(version_info)
#if MICROPY_PY_ATTRTUPLE
Q(name)
#endif
Q(implementation)
#if MICROPY_PY_SYS_MAXSIZE #if MICROPY_PY_SYS_MAXSIZE
Q(maxsize) Q(maxsize)
#endif #endif

Loading…
Cancel
Save