-
We have a Rust workspace with several projects in it. One of the projects is named "core" and contains all the common pieces between the different projects, including our models. We want to perform some data science using pandas, etc. Therefore we decided to use PyO3 to export our models to a Python module. Following the guides and tutorial, everything worked like a charm by simply adding annotations to the models with the appropriate proc macros, and we now have a Python module built with However, now the "core" crate does not compile with Looking as other discussions and going through the issues, we thought we would be able to make it work with the workarounds like specifying 2 crate types, or splitting the features: [lib]
name = "core"
crate-type = ["cdylib", "rlib"]
[features]
default = ["extension-module"]
extension-module = ["pyo3/extension-module"] But it did not help. Therefore we are wondering if we are doing correctly? 🤔 Is it possible to have just one crate for both the rust lib and the python extensions? Or are we supposed to create different 2 crates? The closest answer we found was this one: https://users.rust-lang.org/t/wrap-rust-library-for-python-without-changing-rust-library/69285/4. But like the author of the question mentioned in his last message, we though that recreating wrapping structs and wrapping functions was not the ideal path. We would appreciate if anybody could provide some guidance/best practices for this kind of effort. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Try remove [tool.maturin]
cargo-extra-args = "--features extension-module" |
Beta Was this translation helpful? Give feedback.
-
What happens to functions exported to Python? Taking the following code as example, it seems that there's no way to keep the Rust function
|
Beta Was this translation helpful? Give feedback.
-
Any thoughts on Rust code which read data files? What is the best practice for the corresponding Python package to handle the data files? The safest way seems to make copies of data files into the Python package. This means that on the same machine which uses both the Rust library and the Python package, the data files are potentially duplicated. |
Beta Was this translation helpful? Give feedback.
Try remove
default = ["extension-module"]
and specify the feature inpyproject.toml
instead: