Add Python interface generator command - #34
Merged
Conversation
bruno-f-cruz
approved these changes
Aug 30, 2026
bruno-f-cruz
left a comment
Member
There was a problem hiding this comment.
Tested from the build with a couple of devices, and everything seems to be working.
The generate interface command gains csharp and python subcommands. Invoking it without a language still generates the .NET interface, so existing invocations are unchanged. The metadata path argument and the namespace and output options are declared once on the interface command and read by both subcommands, so the metadata path is given before the language token. The namespace option applies only to the .NET interface and is rejected when passed to python.
Adds a code generation section to the readme, and restructures the interface section of the article so the shared description of the generated output is stated once with the .NET and Python targets as subsections. The readme description regains "interfacing with", which agrees with the package and repository descriptions.
glopesdev
force-pushed
the
generate-python-interface
branch
from
August 31, 2026 22:20
c87672a to
356eb84
Compare
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.
Exposes the Python device interface generator added in
Harp.Generators0.6.0, which reached the toolkit in #33 but had no command line to invoke it. The language becomes an optional subcommand ofgenerate interface, so the published invocation keeps working and generating the .NET interface exactly as before.The
csharpsubcommand generates the same two files the bare command does, so it exists to say explicitly what the default already does rather than to add behavior.The consequence worth reviewing is token order. The metadata path is given before the language, so
generate interface device.yml pythonworks andgenerate interface python device.ymlreports an unrecognized argument.--namespaceand--outputwork on either side of the language token.PythonGeneratortakes no namespace, so--namespaceapplies only to the .NET interface. Rather than accept and ignore it, thepythonsubcommand rejects it through a validator.Documentation
The README gains a code generation section naming both targets, and the interface section of the code generation article is restructured. The description of what a generated interface contains, a type per register with its enum and payload types and a map from address to type, is now stated once, with
### .NET interfaceand### Python interfaceas subsections carrying only what differs.The output location option, which every generation command accepts identically, is also stated once as its own section instead of being repeated under each command. That removes four blocks whose headings collided on the same anchor.
Both targets are named by the library they are built on rather than by the language alone,
Bonsai.Harpand Harp Python, since the generated .NET code requiresBonsai.Harpand thereforeBonsai.Core. The subcommands staycsharpandpython, since the command line axis is the language while the documentation carries the dependency.Verification
Verified against the Behavior device metadata. Both .NET paths, the bare command and
csharp, produce output byte-identical to the two generated filesharp-tech/device.behaviorhas checked in, so the default path is unchanged. The generateddevice.pyis 1258 lines carrying 172 classes, imports fromharp.protocolandharp.device.core, declaresDEVICE_NAMEandREGISTER_MAP, and parses cleanly as Python. Every command shown in the readme and the article was run as written.Closes #29