Decouple protocol layer from Qt - #382
Open
joshperry wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This decouples the protocol layer from PyQt5 so it can be imported from headless/CLI contexts without pulling in the GUI toolkit.
Motivation
The protocol layer (
keyboard_comm.py,vial_device.py, and friends) implements HID communication and keymap serialization — none of which requires Qt. However, transitive imports ofutil.py(which importsPyQt5at the top level) andunlocker.py(aQDialogsubclass) made it impossible tofrom protocol.keyboard_comm import Keyboardwithout having PyQt5 installed. This blocks use cases like CLI tooling, scripting, and CI/CD integration.Changes
New file:
util_base.py— Containshid_send,MSG_LEN,chunks,find_vial_devices,is_rawhid,pad_for_vibl, and the serial number magic constants. Zero GUI dependencies.Refactored:
util.py— Re-exports everything fromutil_baseviafrom util_base import ..., so all existing GUI code continues to work with no changes.protocol/keyboard_comm.py,protocol/tap_dance.py,protocol/combo.py,protocol/key_override.py,protocol/alt_repeat_key.py,protocol/macro.py— Replaced top-levelfrom unlocker import Unlockerwith lazy imports inside the methods that actually use it (only triggered when writingQK_BOOT).protocol/macro.py— Also madefrom macro.macro_action_ui import tag_to_actionlazy (Qt dependency viaQObject).vial_device.py— Imports fromutil_baseinstead ofutil.New test:
test/test_protocol_gui_free.py— AST-scans the protocol import chain for top-level Qt and GUI module imports. Catches regressions automatically.What this does NOT change
Unlockerunlock flow is unchanged; it's just imported at call time rather than module load time.from util import ...statements in GUI code continue to work via re-export.