Skip to content

Gate raspi-config calls behind Shell.run_raspi_config() (fixes #321)#384

Merged
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-piclaw:fix/321-dietpi-raspi-config-gate
May 25, 2026
Merged

Gate raspi-config calls behind Shell.run_raspi_config() (fixes #321)#384
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-piclaw:fix/321-dietpi-raspi-config-gate

Conversation

@makermelissa-piclaw

@makermelissa-piclaw makermelissa-piclaw commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

The Python installer scripts in this repo shell out to raspi-config nonint ... to toggle SPI/I2C, set overscan, change boot behaviour, configure the fan service, etc. raspi-config is only shipped (and only honored) on Raspberry Pi OS — on DietPi, Ubuntu, and other Debian-based distros the binary is absent and shell.run_command returns falsy on the missing executable, so the tweak silently doesn't happen and the user sees a confusing command not found line mid-install. That's the underlying "non-Pi-OS distro" gap behind #321; the reporter's specific is_wayland()/loginctl complaint was already fixed when that helper was deleted in d14339d, but the broader raspi-config-unavailable problem on the same distro remained.

Approach

adafruit/Adafruit_Python_Shell#38 (now merged + released) added a reusable Shell.run_raspi_config(args, suppress_message=False, return_output=False, run_as_user=None) that gates on is_raspberry_pi_os() and short-circuits to a no-op on non-Pi-OS hosts (returning True, or "" when return_output=True so .strip() callers stay happy).

This PR migrates every raspi-config nonint call site in the repo's Python installers to use it.

File Sites What they toggle
adafruit-pitft.py 6 do_boot_behaviour, do_boot_splash, do_boot_target, do_overscan ×2
raspi-blinka.py 7 do_i2c, do_spi, do_serial_hw, do_serial, do_ssh, do_camera, disable_raspi_config_at_boot
raspi-spi-reassign.py 3 do_spi ×2 + get_spi (uses return_output=True + .strip())
joy-bonnet.py 2 do_i2c, do_overscan
retrogame.py 1 do_i2c
pitft-fbcp.py 1 do_spi
rtc.py 1 do_i2c
adafruit_fanservice.py 1 do_fan — was previously gated only on is_raspberry_pi(), which is true on DietPi-on-Pi-hardware

Total: 22 call sites across 8 files, +22 / −22 net.

The leading sudo on the old run_command lines is dropped: all of these installers already require root (require_root() or equivalent), so the inner sudo was redundant.

Out of scope

Bash-only scripts in this repo (pi-eyes.sh, arcade-bonnet.sh, rgb-matrix.sh, retrogame.sh, spectro.sh) still call raspi-config directly. They don't use adafruit_shell and would need a different fix; happy to follow up separately if you want that too.

Test plan

  • Syntax (ast.parse) clean across all 8 files (pre-existing SyntaxWarnings on invalid escape sequences are unrelated).
  • Confirmed via ast walk that all 22 migrated call sites resolve to syntactically valid shell.run_raspi_config(...) invocations, with suppress_message / return_output kwargs preserved on the three sites that use them.
  • On this Pi (Raspberry Pi OS), with Shell.run_command monkey-patched to record calls: run_raspi_config("do_overscan 1") forwards to run_command("raspi-config nonint do_overscan 1", ...) exactly as before.
  • On simulated non-Pi-OS (is_raspberry_pi_os patched to False): all calls short-circuit, return truthy / empty string, zero run_command invocations.

References

@makermelissa-piclaw

Copy link
Copy Markdown
Contributor Author

Follow-up: I've also opened adafruit/Adafruit_Python_Shell#38 which adds the same gating logic as a reusable Shell.run_raspi_config() method, plus migrates the existing Shell.set_window_manager() call internally.

Once that lands and is released to PyPI, the local run_raspi_config() helper in this PR can be deleted in favor of shell.run_raspi_config(...), and the same migration can be applied to the other call sites in this repo (raspi-blinka.py, raspi-spi-reassign.py, joy-bonnet.py, retrogame.py, pitft-fbcp.py) — they all currently shell out to raspi-config nonint ... the same way.

Happy to do this either way:

  • Land this PR as-is (self-contained local helper, ships immediately), then do a follow-up PR after the Shell release to migrate all six scripts to the library helper.
  • Hold this PR until Shell add some hacky file copies for libgpiod python bindings #38 ships, then rewrite to depend on the new method directly.

Let me know which you'd prefer.

…it#321)

This repo's Python installer scripts shell out to 'raspi-config
nonint ...' for SPI/I2C toggles, overscan, boot behaviour, fan
service, etc. The raspi-config binary is only shipped (and only
honored) on Raspberry Pi OS; on DietPi, Ubuntu, and other
Debian-based distros the binary is absent and shell.run_command()
returns falsy on the missing executable, so the tweak silently
doesn't happen and the user sees a confusing 'command not found'
line mid-install.

Adafruit_Python_Shell now ships Shell.run_raspi_config(args, ...)
(adafruit/Adafruit_Python_Shell#38) which gates on
shell.is_raspberry_pi_os() and short-circuits cleanly on non-Pi-OS
hosts, returning True (or '' when return_output=True so .strip()
callers stay happy).

Migrate every raspi-config nonint call site in the repo's Python
scripts to the new helper:

  * adafruit-pitft.py       (6 sites: boot_behaviour, boot_splash,
                             boot_target, overscan x2)
  * raspi-blinka.py         (7 sites: i2c, spi, serial_hw, serial,
                             ssh, camera, disable_raspi_config_at_boot)
  * raspi-spi-reassign.py   (3 sites incl. get_spi with
                             return_output=True / .strip())
  * joy-bonnet.py           (2 sites: i2c, overscan)
  * retrogame.py            (1 site: i2c)
  * pitft-fbcp.py           (1 site: spi)
  * rtc.py                  (1 site: i2c)
  * adafruit_fanservice.py  (1 site: fan -- previously gated only on
                             is_raspberry_pi(), which is true on
                             DietPi-on-Pi-hardware)

Closes the underlying 'non-Pi-OS distro support' gap reported in
adafruit#321. (The reporter's specific is_wayland()/loginctl complaint was
already fixed in d14339d, but the broader raspi-config-unavailable
problem on the same distro remained.)

Behavior on Raspberry Pi OS is unchanged. The leading 'sudo' on
the old run_command lines is dropped: all of these installers
already require root via require_root() (or equivalent), so the
inner sudo was redundant. Bash-only scripts in this repo
(pi-eyes.sh, arcade-bonnet.sh, rgb-matrix.sh, retrogame.sh,
spectro.sh) call raspi-config directly and are out of scope here.
@makermelissa-piclaw makermelissa-piclaw force-pushed the fix/321-dietpi-raspi-config-gate branch from 56c8633 to 053a85a Compare May 25, 2026 22:31
@makermelissa-piclaw makermelissa-piclaw changed the title Skip raspi-config calls on non-Raspberry-Pi-OS distros (fixes #321) Gate raspi-config calls behind Shell.run_raspi_config() (fixes #321) May 25, 2026

@makermelissa makermelissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

@makermelissa makermelissa merged commit 0eb54f8 into adafruit:main May 25, 2026
@makermelissa-piclaw makermelissa-piclaw deleted the fix/321-dietpi-raspi-config-gate branch May 25, 2026 22:34
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.

adafuit-pitft.py fails when using Dietpi linux distro

3 participants