vouch-opensource / mcumgr-client

client for mcumgr commands
Apache License 2.0
31 stars 13 forks source link

Add python wrapper #26

Closed adrienbruant closed 4 months ago

adrienbruant commented 4 months ago

This pull requests adds a python wrapper to mcumgr-client and uses github CI to build wheels for various platforms and architectures. The goal is to allow integration with python applications and package distribution via pip. The maintainers of this project should provision a trusted publisher on PyPI for mcumgr-client.

This is simply a wrapper as my rust skills don't allow me to create proper bindings. Wrapping a binary has the advantage of not requiring one python wheel per ABI.

I've set default-features = false for serialport to remove libudev dependency and improve portability. I don't believe it removes anything from the client as libudev provides enumeration capabilities.

Don't know if this is a project goal so take it as a mere suggestion. If not, I'm happy to make it a side project.

Frank-Buss commented 4 months ago

Thanks, great idea! But I think the best would be to refactor the Rust in a library and the Rust command line frontend. Then the wrapper can use a clear API instead of parsing the command line. Like curl / libCurl, etc. What do you think?

Frank-Buss commented 4 months ago

The Rust library could even become a standard Rust crate.

adrienbruant commented 4 months ago

I've had a deeper look at the implementation of the client and I don't see an obvious interface to create a library from, at least not one my rudimentary rust skills can refactor. Everything seems to be linked to CLI struct which is not a great interface for a library.

I think we should have some sort of session object that manages the serial port based on initializer options. Maybe the serial port shouldn't be managed by the library so that it can be handled by the application (python context manager with)?

That's why I settled with wrapping the binary application. I understand this PR does not go in the right direction for this project and someone more versed in rust would do a better job. Unfortunately I can't dedicate more time to this as our current implementation satisfies our need.

Frank-Buss commented 4 months ago

I think the Python wrapper is still a good idea, regardless of if it uses a program or library. Your Python interface looks nice and would be the same anyway, which means it wouldn't break Python user programs, in case someone wants to refactor the Rust program to a library someday.

But I discussed it also at Vouch, and we have no experience releasing Python packages etc. So maybe a good idea if you create your own mcumgr-client Python wrapper repository. Might be best to include the mcumgr-client project as a git submodule. I can add a link to your wrapper in the readme page, or you can send a PR for it.

adrienbruant commented 4 months ago

This is what I ended up doing, but I didn't want to steal your name on PyPI in case you end up deploying your own package in the future, so I've deployed under the name mcumgr-client-wrapper.

https://github.com/comap-smart-home/mcumgr-client-wrapper https://pypi.org/project/mcumgr-client-wrapper/

Frank-Buss commented 4 months ago

Thanks, I added the link to the readme.

adrienbruant commented 4 months ago

Likewise, thank you for the reference.