Skip to content

py/modsys: Add sys.implementation._build entry. #16843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dpgeorge
Copy link
Member

@dpgeorge dpgeorge commented Mar 3, 2025

Summary

For a given MicroPython firmware/executable It can be sometimes important to know how it was built, which variant/board configuration it came from. For example in mpflash and octoprobe; see #16498.

This PR adds a new field sys.implementation._build that can help identify the configuration that MicroPython was built with.

For now it's either:

  • <VARIANT> for unix, webassembly and windows ports
  • <BOARD>-<VARIANT> for microcontroller ports (the variant is optional)

In the future additional elements may be added to this string, separated by -.

Testing

Tested on:

  • unix: _build='standard'
  • webassembly: _build='pyscript'
  • PYBV10, DP variant: _build='PYBV10-DP'
  • ESP32: _build='ESP32_GENERIC'
  • RPI_PICO2, RISCV variant: _build='RPI_PICO2-RISCV'

Trade-offs and Alternatives

This adds a small amount of code size to most of the builds (except the very minimal ones where it's excluded when MICROPY_PY_ATTRTUPLE is disabled). These builds have a lot of other features enabled and so should have enough space to add this small feature.

Otherwise it's difficult to properly implement something equivalent:

  • storing a file on the filesystem to indicate the build information will not be updated when new firmware is installed, unless the user also updates the filesystem
  • inspecting existing sys entries and probing for features can help to determine the board/build, but it's not an easy thing to do and you need to know for each board/build what properties it has that distinguishes it from other boards/builds (eg for PYBV10-DP you'd need to probe that it has double-precision float via float("1e100") and see if that's infinity or not).

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Mar 3, 2025
@dpgeorge dpgeorge linked an issue Mar 3, 2025 that may be closed by this pull request
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (b4cf82b) to head (f5b4545).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16843   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21864    21864           
=======================================
  Hits        21545    21545           
  Misses        319      319           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Mar 3, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:  +192 +0.022% standard[incl +32(data)]
      stm32:   +44 +0.011% PYBV10
     mimxrt:   +40 +0.011% TEENSY40
        rp2:   +24 +0.003% RPI_PICO_W
       samd:   +68 +0.025% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:   +51 +0.011% VIRT_RV32

@dpgeorge dpgeorge requested a review from projectgus March 3, 2025 01:13
@dpgeorge dpgeorge added this to the release-1.25.0 milestone Mar 3, 2025
@andrewleech
Copy link
Contributor

This looks good to me, nice and simple. I definitely agree it's valuable information to have in a build.

@Josverl
Copy link
Contributor

Josverl commented Mar 3, 2025

Thanks, works fine

  • windows : _build='standard'
  • windows v2 _build='standard', _v2=True
  • pyb1.1 : _build='PYBV11-DP_THREAD'

LGTM !

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this looks very useful!

hmaerki added a commit to octoprobe/octoprobe that referenced this pull request Mar 4, 2025
@hmaerki
Copy link
Contributor

hmaerki commented Mar 4, 2025

I adapted octoprobe to use this string to termine if the firmware has to be flashed.

Worked successfully on all tentacles (TEENSY, ESP32_GENERIC_C3, ESP32_GENERIC_S3, RPI_PICO2_W, RPI_PICO2, LOLIN_C3_MINI, NUCLEO_WB55, ARDUINO_NANO_33_BLE_SENSE, ESP8266_GENERIC-FLASH_512K, ...)

Thank you - I love it!

For a given MicroPython firmware/executable it can be sometimes important
to know how it was built, which variant/board configuration it came from.

This commit adds a new field `sys.implementation._build` that can help
identify the configuration that MicroPython was built with.

For now it's either:
* <VARIANT> for unix, webassembly and windows ports
* <BOARD>-<VARIANT> for microcontroller ports (the variant is optional)

In the future additional elements may be added to this string, separated by
a hyphen.

Resolves issue micropython#16498.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the py-sys-add-sys-implementation-board branch from 265d1b2 to f5b4545 Compare March 5, 2025 01:24
@dpgeorge
Copy link
Member Author

dpgeorge commented Mar 5, 2025

Thanks for the feedback and testing.

@dpgeorge dpgeorge merged commit f5b4545 into micropython:master Mar 5, 2025
65 checks passed
@dpgeorge dpgeorge deleted the py-sys-add-sys-implementation-board branch March 5, 2025 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PYBV11: 'sys.implementation[2]' does not reflect the build variant
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy