-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate API clients based on description #373
Generate API clients based on description #373
Conversation
It's hard to understand what's going on here without having someone that really knows what's going on in the parser/generator side, We will need to dup(mengel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me start with: this is a nice work and really remember me a parsing/compiler classes. :)
Now few comments:
- In general, good, should work (not there yet as I shared in the comment).
- Such parser/generator would deserve a separate repo IMHO
- Pro: Automatically generation of python/golang/whatever code.
- Cons: Increase the complexity to maintain binding code as we need to understand the generator (instead of pure python as today). What happens if we want to generate golang? rust? A new shine language? Probably we will need to create a class/methods to adapt it?
Another point about simplicity, today we have all methods from Hirte() class which to my eyes seems pretty simple but with this implementation now we have more objects/classes (inherence) like HirteManager(), HirteNode(), HirteUnit() which is normal as the parser reads from the specification. How about we generate a docstring about the API too?
For the future, I would transform this project to generic parser/generator from dbus to whatever language users would like. Today is completely related to hirte but has potential to be generic and used for many of hundreds of projects out there.
Let's see the next round of patch to test it again. Also, would help if you could squash all these commits.
The generator is not part of the |
If we want to generate a client for another language like go, rust, etc. the only thing that is required are proper Jinja2 templates. For example, just passing the path to the rust template to the generator should result in the rust client for the hirte api.
I refactored it a bit so we generate only one file, but still multiple classes - each class represents an interface. This is also a bit clearer in regards to which API "endpoint" is actually used and makes using them rather explicit, e.g. by using node = HirteNode("laptop") it makes sense to pass the node name to it. In addition, the lifetime of the dbus proxy is linked to the object - which is important for the monitor, for example - and the connection is reused per instance makes it more efficient than (re-)opening it per function call.
That would be great to have and would be possible if we extend our API description e.g. by annotations or doc tags - these can be parsed by the generator and passed to the templates.
Maybe, yes. But for now its rather hirte specific. I am still baffled that there is no such project yet, to be honest.
I'll rebased them a bit, so it should be easier to review. But since its a pretty big change, I'd not want to put everything in one commit. |
Starting with some quick comments:
and
|
Fixed.
Added the quotes. |
Why "temporarily removed client package from rpm"? |
I couldn't figure out how to use the python macros to add it to the rpm, e.g. |
I guess since it the python code was not in 0.3 we're not regressing if we temporarily remove it. |
I had the same problem that why I used %install instead of these pre-defined macros. You see the same problem using the %install? |
Agreed, if required, spec can always wait a bit. It will not hurt. |
Signed-off-by: Michael Engel <[email protected]>
Signed-off-by: Michael Engel <[email protected]>
- generated dbus api client for python - refactored current python client - extended the generated client - refactored the python client examples - temporarily removed client package from rpm Signed-off-by: Michael Engel <[email protected]>
- added a lint CI step to check for api spec changes - added a manually triggered job to publish pypi package Signed-off-by: Michael Engel <[email protected]>
Great patch a few comments, let's merge and you can continue the journey with the minor changes to improve this solution. BTW, could you please also verify this one? This is the only one example not working for me now. ./EnableUnitTraceback (most recent call last): |
LGTM |
sorry the delay to review, this week I took PTO days. |
* aligned hirte api description with implementation Signed-off-by: Michael Engel <[email protected]> * implemented dbus api client generator Signed-off-by: Michael Engel <[email protected]> * rework of python client for hirte dbus api - generated dbus api client for python - refactored current python client - extended the generated client - refactored the python client examples - temporarily removed client package from rpm Signed-off-by: Michael Engel <[email protected]> * extended github workflow for dbus api changes - added a lint CI step to check for api spec changes - added a manually triggered job to publish pypi package Signed-off-by: Michael Engel <[email protected]> --------- Signed-off-by: Michael Engel <[email protected]>
This PR