Add Python device interface generator#119
Open
glopesdev wants to merge 3 commits into
Open
Conversation
Add a PythonGenerator class that produces a Python device interface module from device metadata, alongside the existing C# and firmware generators. The generated module targets the pyharp register and payload DSL and emits IntEnum and IntFlag types for group and bit masks, payload classes for structured and converter-backed registers, register classes, and an address-to-class REGISTER_MAP. Application devices merge the core register map, and member and field names follow canonical Python casing through the shared firmware naming convention. Add expected-output tests for the core and device metadata and a cross-stack interop test that writes Harp binary frames through the generated C# interface, then reads them back through the generated Python interface to verify the two stacks agree.
bruno-f-cruz
requested changes
Jun 27, 2026
Switch the interop test bulk-parse check from read_dataframe in harp-data to RegisterBase.parse_bulk in harp-protocol, and drop the harp-data dependency from the test project. The per-frame parse and value assertions are unchanged.
Regenerate the Python interface against the redesigned pyharp register and payload DSL. Whole-register bit and group masks now unwrap to their enum type: the payload is an AnonymousPayload with a single __value__ field and the register parses to the IntFlag or IntEnum directly, replacing the previous struct of boolean fields. Masked boolean sub-fields now use a BoolConverter field with a mask, since BitFlag was removed upstream, and string and converter registers adopt the same AnonymousPayload __value__ form. Bump the interop test pin to the matching pyharp commit and simplify the cross-stack comparison, which now checks mask registers as a plain integer on both sides.
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.
Add a
PythonGeneratorclass that produces a Python device interface module from device metadata, giving the generator set a third target alongside the existing C# and firmware generators. The generated module targets the register and payload DSL of the new pyharp unified API introduced in harp-tech/pyharp#5, so an existingdevice.ymlcan produce a ready-to-use Python interface with no hand-written register code.The module mirrors the conventions of the pyharp hand-written reference:
IntEnumandIntFlagtypes for group masks and bit masks.StructPayloadwithGroupMask,BitFlag, andFielddescriptors, and for converter-backed registers, usingAnonymousPayload.Register*base, plus an address-to-classREGISTER_MAP. Application devices merge the core register map imported fromharp.device.SCREAMING_SNAKE_CASEmembers andsnake_casefields, produced through the same firmware naming convention used by the C firmware generator.User-supplied converters are imported from a companion
.convertersmodule, the Python analog of the partial-method stubs the C# generator emits.Validation
coreanddevicemodules against committed reference files.uvon the release CI legs, one per OS, so upstream pyharp changes that break cross-platform behavior are caught.Notes
PythonGeneratorandPythonImplementation.refactor-unified-apibranch, so the interface may need adjustment as that API settles before a pyharp release.