Repository navigation
Avoid the setuptools runtime dependency pulled in through gpiozero #168
Copy link
Copy link
Description
zigpy-zigate depends on gpiozero to drive the PiZiGate's GPIO pins. gpiozero requires colorzero, which declares setuptools as a runtime dependency:
zigpy-zigate 0.14.0
└── gpiozero 2.0.1
└── colorzero 2.0
└── setuptools
We ran into this while fixing Dependabot for zha (zigpy/zha#935): it's the only reason setuptools is in zha's uv.lock, and zigpy/zha#937 had to add a Dependabot ignore for it (Dependabot sees setuptools both as zha's build requirement and as this transitive lock entry, and fails, see dependabot/dependabot-core#14118).
Why it matters
- Home Assistant doesn't allow
setuptoolsas a runtime dependency (Prevent types-*/setuptools/wheel runtime requirements in dependencies home-assistant/core#145381) and warns about.pthfiles in dependencies (Warn about *.pth files in dependencies home-assistant/core#166411). Both checks carry azhaexception for this chain inscript/hassfest/requirements.py: one inFORBIDDEN_PACKAGE_EXCEPTIONS(setuptoolsis a forbidden runtime dependency) and one inFORBIDDEN_PACKAGE_FILES_EXCEPTIONS(it installs adistutils-precedence.pthfile). Theremote_rpi_gpiointegration has the same two exceptions, through its owngpiozerorequirement. - Every install gets it, though only PiZiGate users need GPIO. The dependency has no platform marker, and
zigpy_zigate/common.pyimportsgpiozeroat module level, so importing the radio module (zigpy_zigate.zigbee.application) loadsgpiozeroandcolorzero. zha imports that module at startup (zha/application/const.py), so every Home Assistant install with ZHA loads the whole chain.
Upgrading doesn't help
colorzerodoesn't actually usesetuptools: nothing incolorzero2.0 (or its currentmaster) importssetuptoolsorpkg_resources; it's only listed ininstall_requiresin itssetup.cfg. Package setuptools should not be a runtime dependency waveform80/colorzero#9 asks for it to be dropped (opened 2025-05-26, prompted by Prevent types-*/setuptools/wheel runtime requirements in dependencies home-assistant/core#145381). 2.0 (2021) is still the latest release.gpiozeroimportscolorzerounconditionally (from colorzero import Colorat the top ofgpiozero/output_devices.py, forRGBLED, whichgpiozero/__init__.pyimports), so it can't be left out. The latest release, 2.0.1.post3 (2026-07-27), still requires it. Why is setuptools a run-time requirement for gpiozero? gpiozero/gpiozero#1183 asks the same question fromgpiozero's side.
Options
- Get it fixed in
colorzero. A one-line change in itssetup.cfgand a new release. That would also let Home Assistant drop theremote_rpi_gpioexceptions. The issue has had no reply from the maintainer since it was opened, but the repo isn't dormant (a PR was merged in March 2026), so a PR might get further than the issue. - Replace
gpiozerowith a small built-in GPIO helper. The PiZiGate code only switches two output pins (GPIO 17 and 27) and keeps driving them afterwards (UnclosableOutputDevice). A pure-Python implementation on the Linux GPIO character device (/dev/gpiochipNwithioctl) needs no dependencies;gpiozerowas chosen in Switch fromRPi.GPIOtogpiozero#125 because it's pure Python, unlikeRPi.GPIO(RPi.GPIO dependency is no more installed in Home Assistant Core 2022.7.7 #124). It might also help on the Raspberry Pi 5: Home Assistant installs none ofgpiozero's other backends (lgpio,RPi.GPIO,pigpio;remote_rpi_gpio'spigpioclient needs a separate daemon), sogpiozerofalls back to its built-in native backend, which is built for the BCM283x-style GPIO registers of the Pi 1–4; the Pi 5's GPIO sits on its RP1 chip instead. Costs: new code to own; it has to find the right GPIO chip by label or line name (the Pi 5's header moved betweengpiochip4andgpiochip0across kernel versions), keep the line request open so the pins stay driven, and it's hard to test without the hardware (Switch fromRPi.GPIOtogpiozero#125 was also written without a PiZiGate, with the pin sequence checked on an oscilloscope). - Make
gpiozerooptional. Move thegpiozeroimport and theUnclosableOutputDeviceclass into the PiZiGate functions (set_pizigate_running_mode()/set_pizigate_flashing_mode()), and movegpiozeroto an extra (e.g.zigpy-zigate[pizigate]). Installs without it lose all three packages. But zha, and with it Home Assistant, would then have to either depend on the extra (bringing the chain back) or stop supporting the PiZiGate out of the box. - Leave it. Home Assistant's exceptions and zha's Dependabot ignore stay.
Questions
- Which route: the upstream fix, a built-in GPIO helper, or an optional dependency?
- Can anyone test a PiZiGate, ideally on both a Pi 4 and a Pi 5? Does it work on a Pi 5 today?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Priority
None yet
Size
None yet
Area
None yet
Activity
TheJulianJES commentedon Oct 12, 2026
@zigpy-review-bot Create PR for option 2, run review rounds before.
zigpy-review-bot commentedon Oct 12, 2026
Opened #169 for option 2: a small built-in helper on the Linux GPIO character device (v2 uAPI, Linux 5.10+) replaces
gpiozero, sogpiozero,colorzeroandsetuptoolsdrop out of the dependency tree. It finds the PiZiGate lines by name (GPIO17/GPIO27) across all gpiochips, falling back to the Pi pinctrl chip labels (needed on the Pi 5's launch kernel), and keeps the line requests open so the pins stay driven. The pin sequence and timings are unchanged. Tests pass; the PR went through three review rounds and the last one was clean.It's not tested on PiZiGate hardware yet. The PR body lists the behaviour changes (needs access to
/dev/gpiochip*instead of/dev/gpiomem; pins on non-Raspberry-Pi kernels may stop being driven after the process exits) and asks for testers on a Pi 4 and a Pi 5.Separately: pre-commit currently can't install the
autoflake8hook (its upstream repo is gone), which also affectsdev, so the PR's pre-commit CI step may fail for that reason.puddly commentedon Oct 12, 2026
One other alternative would be writing a minimal module for
/dev/gpiomemaccess and leave Pi 5 compatibility for the future. So far, it's been over three years since the Pi 5 was released and this has not come up. I don't think the ZiGate GPIO module is really that popular. Something like:zigpy-review-bot commentedon Oct 13, 2026
A related data point from home-assistant/core#185946. To be clear, that one is not a zigpy-zigate (or gpiozero) bug: a single bit had flipped in the user's local copy of
gpiozero/spi_devices.py, turning a newline into a0x08byte. The published 2026.10.1 image has the correct file.It does show the cost of the module-level import described above, though. The user has no ZiGate, but zha imports
zigpy_zigate.zigbee.applicationat startup, which pulls inzigpy_zigate.common→gpiozero→gpiozero.spi_devices. The resultingSyntaxErrorfailed the wholehomeassistant.components.zhaimport, so ZHA didn't load at all, because of a file that only matters to PiZiGate users.Any of the options here that drops
gpiozero(#169, a minimal/dev/gpiomemmodule) or moves the import into the PiZiGate functions takes it off ZHA's startup path.zigpy-review-bot commentedon Oct 13, 2026
Opened #170 for puddly's suggestion: his
/dev/gpiomemhelper (first commit, co-authored) replacesgpiozero, sogpiozero,colorzeroandsetuptoolsdrop out of the runtime dependencies, as with #169.On Home Assistant,
gpiozeronormally drives the PiZiGate through its native backend, which writes the same GPIO registers through/dev/gpiomem, so Pi 1–4 users on Home Assistant keep the same device access and the pins stay driven after exit as before. A follow-up commit adds a board check (the Raspberry Pi revision code, read likegpiozerodoes): it refuses to write the registers on a Pi 5 or a non-Pi board instead of hitting the wrong chip. The Pi 5 stays unsupported, as it is today withgpiozero's native backend.The PR body compares it with #169 and lists the corner cases where it behaves differently from
gpiozero(no/dev/memfallback; setups wheregpiozerouseslgpioinstead, which is what could make a PiZiGate work on a Pi 5 today). Only one of the two PRs should be merged. Not tested on PiZiGate hardware yet.