Skip to content

os.uname(): sysname is CircuitPython; nodename is the hostname - #11905

Merged
tannewt merged 4 commits into
adafruit:mainfrom
dhalbert:os-uname-sysname-nodename
Nov 18, 2026
Merged

tannewt merged 4 commits into
adafruit:mainfrom
dhalbert:os-uname-sysname-nodename

Conversation

@dhalbert

@dhalbert dhalbert commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Code by Claude, reviewed and revised by @dhalbert.

Problem

os.uname().sysname and os.uname().nodename both returned the microcontroller name. In CPython, sysname is the OS name and nodename is the machine's hostname.

Fix

  • sysname is now "CircuitPython".
  • On boards with Wi-Fi or Ethernet, nodename is the network hostname, read on each call. It will track changes to wifi.radio.hostname or Ethernet.hostname.
  • Before Wi-Fi or Ethernet is set up, nodename is the hostname the interface will use: CIRCUITPY_WIFI_HOSTNAME from settings.toml if set, otherwise the port's default (cpy-<board>-<mac>, PicoW on raspberrypi, cpy-<mac> on espressif Ethernet).
  • On boards without networking, nodename is still the microcontroller name. os.uname() will still return a constant tuple instead of constructing one. This means that builds with no network support grow only enough to include the "CircuitPython" string.
  • The cpy-<board>-<mac> default-hostname code, which was copied in three places, is now refactored into network_format_default_hostname() in supervisor/shared/network.c.

This is a breaking change, so it is for 11.0.0.

Testing

  • Metro ESP32-S3, Pico W (raspberrypi and zephyr-cp builds): nodename before and after import wifi, after setting wifi.radio.hostname, and with and without CIRCUITPY_WIFI_HOSTNAME.
  • ESP32-P4-Function-EV: nodename with board.ETHERNET, before and after setting its hostname.
  • New zephyr-cp native_sim test, tests/test_os.py.

sysname and nodename were both the microcontroller name.

- sysname is "CircuitPython", or "Zephyr" on zephyr-cp
  (CIRCUITPY_OS_UNAME_SYSNAME).
- On boards with Wi-Fi or Ethernet, nodename is the network hostname,
  read on each call. Before the interface is set up, it is the hostname
  the interface will use: CIRCUITPY_WIFI_HOSTNAME if set, otherwise the
  port's default.
- On boards without networking, nodename is still the microcontroller
  name, and os.uname() still returns a constant tuple.

Move the "cpy-<board>-<mac>" default-hostname formatting, which was
copied in three places, into supervisor/shared/network.c. Add per-port
wifi_hostname_is_set(), wifi_get_default_hostname() and
mii_get_default_hostname(), which work before the interface is set up.

Fixes adafruit#10153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhalbert
dhalbert requested a review from tannewt November 18, 2026 19:23
dhalbert and others added 2 commits November 18, 2026 14:38
It reports whether common_hal_wifi_init() has run, which is more general
than whether the hostname is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The de_DE build overflowed by 4 bytes after adding the "CircuitPython"
os.uname().sysname string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannewt

tannewt commented Nov 18, 2026

Copy link
Copy Markdown
Member

Why is sysname Zephyr on the Zephyr port? That should be an implementation detail. I think it should be CircuitPython still.

@dhalbert

Copy link
Copy Markdown
Collaborator Author

Why is sysname Zephyr on the Zephyr port? That should be an implementation detail. I think it should be CircuitPython still.

I thought it would be nice to know, and it's an RTOS. But I waffled on this. I'll take it out.

The RTOS is an implementation detail. Drop the zephyr-cp override and
the CIRCUITPY_OS_UNAME_SYSNAME setting, which now has only one value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@tannewt
tannewt merged commit 101416a into adafruit:main Nov 18, 2026
717 checks passed
@dhalbert
dhalbert deleted the os-uname-sysname-nodename branch November 18, 2026 23:20
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.

Return hostname for os.uname().nodename and OS name for os.sysname()

2 participants