8000 py/builtinhelp: Add options for changing help('modules') format. by radiofan · Pull Request #18734 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@radiofan
Copy link

This commit allow to change count and width of columns for help('modules') output by mpconfigport.h.

Summary

Hello, MicoPython community.
We are porting MicroPython on our device. We recently ran into a problem. Width of screen of our device is so small. Default format of help('modules') is poorly displayed. We would like to be able to change it by NUM_COLUMNS and COLUMN_WIDTH.

Testing

Tested on unix port.

diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h
index e290935bc..a586c4f81 100644
--- a/ports/unix/mpconfigport.h
+++ b/ports/unix/mpconfigport.h
@@ -121,6 +121,9 @@ typedef long mp_off_t;
 // port modtime functions use time_t
 #define MICROPY_TIMESTAMP_IMPL      (MICROPY_TIMESTAMP_IMPL_TIME_T)
 
+#define MICROPY_PY_BUILTINS_HELP_NUM_COLUMNS (2)
+#define MICROPY_PY_BUILTINS_HELP_COLUMN_WIDTH (22)
+
 // Assume that select() call, interrupted with a signal, and erroring
 // with EINTR, updates remaining timeout value.
 #define MICROPY_SELECT_REMAINING_TIME (1)

Result:

MicroPython 9b9d8cc783-dirty on 2026-01-28; linux [GCC 13.1.0] version
Type "help()" for more information.
>>> help("modules")
__main__              io
_asyncio              json
_thread               machine
argparse              math
array                 micropython
asyncio/__init__      mip/__init__
asyncio/core          mip/__main__
asyncio/event         os
asyncio/funcs         platform
asyncio/lock          random
asyncio/stream        re
binascii              requests/__init__
btree                 select
builtins              socket
cmath                 ssl
collections           struct
cryptolib             sys
deflate               termios
errno                 time
ffi                   tls
framebuf              uasyncio
gc                    uctypes
hashlib               vfs
heapq                 websocket
Plus any modules on the filesystem
>>>

@codecov
Copy link
codecov bot commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.41%. Comparing base (be15be3) to head (01ddf21).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18734   +/-   ##
=======================================
  Coverage   98.41%   98.41%           
=======================================
  Files         171      171           
  Lines       22324    22324           
=======================================
  Hits        21971    21971           
  Misses        353      353           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
github-actions bot commented Jan 28, 2026

Code size report:

Reference:  stm32: Default to --connect-under-reset if flashing via deploy-stlink. [af76da9]
Comparison: py/builtinhelp: Add options for changing help('modules') format. [merge of 01ddf21]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Contributor
@dlech dlech left a comment

Choose a reason for hiding this comment

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

Looks like a sensible change to me.

py/builtinhelp.c Outdated

#if MICROPY_PY_BUILTINS_HELP

#ifndef MICROPY_PY_BUILTINS_HELP_NUM_COLUMNS
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect these defines in py/mpconfig.h. There already defines related to MICROPY_PY_BUILTINS_HELP

Copy link
Author

Choose a reason for hiding this comment

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

I think these are fairly niche settings and can reasonably be located locally in the file where they are used.
But if you insist, I will certainly move them.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is up to Damien to decide. My suggestion follow the setting hierarchy in MicroPython, which is usually

mpconfigboard.py
mpconfigport.py
mpconfig.py

There are slight variations of this, like an additional mpconfigmcu.py at the second level, but usually configurable options are expected in one of the config file. But, as always, nor rules without exceptions.

Copy link
Author

Choose a reason for hiding this comment

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

I hear you. I have moved settings.

This commit allow to change count and width of columns
for help('modules') output by mpconfigport.h.

Signed-off-by: radiofan <radiofan22@mail.ru>
@radiofan radiofan force-pushed the add-config-builtinhelp branch from 936caa0 to 01ddf21 Compare January 29, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0