-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add Python implementation with native Rust module #547
Conversation
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.
Looks good, haven't tested this on my own but if it works then 🤷
One thing that could clean things up would be to separate the CLI and the library code to separate crates (using cargo workspace perhaps?) so that the library wouldn't download and compile all the CLI dependencies, thus reducing binary size.
Adds a separate Python vault version under
python-pyo3
that uses the Rust vault internally.pyo3 is used to create Python bindings for the Rust vault. There is a single
lib.rs
file that wraps the Rust vault library. It simply has one function for each CLI command that takes parameters from python side and calls the matching rust cli command. Pyo3 has an additional tool maturin which is used to init the project, and handle building and publishing.The Python side only has the CLI specification that was written from scratch to match the Rust CLI (uses subcommands so
all
instead of--all
). All actual functionality happens in the rust module (including print output for the most part). To enable this, I moved the Rust vaultcli.rs
to be part of the Rust lib, so it can be reused for python. Otherwise would need to duplicate all that in Python, going against one of the primary goals for this whole thing. This does lead to a bit of code duplication for passing around the arguments since each command creates its own vault instance but this way the communication between rust and python is very simple and kept to a minimun.There is an
experimental-async
feature for pyo3 that would enable async support between rust and python, but since we don't actually need to do anything async directly in the CLI, I did this the easy way and just wrapped all rust code inside a separate runtime invocation for each function with a blocking task, so the python side does not need to care about async at all.Typer does not seem to support giving commands flag aliases like we have in the rust version. Currently it does not have the argument flags at all, so it is not backwards compatible with the old python cli interface.