-
Hello all, Is there a good way to add a python package to an existing rust library, without changing that library (avoiding pyo3 as a dependency)? I feel like this should be possible, maybe with cargo workspaces, but have yet to figure out how to do this. I have an existing crates.io project that has a rust library, and a CLI binary. I'd like to create a python module for PyPi that uses this library, and keep it contained in the same package so it uses the same version numbering. This will require some wrapping both rust-side and python-side, which I don't really want to ship with the main crate, both to avoid confusion and to help keep dependencies slimmer. My thought was to use a directory structure like the following: some_project/
├── Cargo.toml
├── bindings_py/ # Main directory for rust project
│ ├── Cargo.toml # Don't really want this file to avoid managing "version"
│ │ # Currently has dependency `some_project = { path = "../" }`
│ ├── docs/ # Sphinx docs for the python package
│ ├── pysrc/ # This is what should be called in python by `import some_project`
│ │ │ # Includes all python-side wrapping
│ │ ├── __init__.py # This should import the builds and do necessary python-side wrapping
│ │ └── __init__.pyi # Typing goes here, I think (?)
│ ├── src/
│ │ └── lib.rs # Rust-side wrapping for the library
│ └── tests/ # Pytest integration tests for the python & rust combined
│ └── some_python_test.py
├── pyproject.toml
├── README_pypi.md # Also unsure how to specify the README to use for pypi
├── README.md
├── src/
│ ├── bin/
│ │ └── bin.rs # This creates the CLI executable that ships with the package
│ ├── lib.rs # Main package library
│ └── something.rs # Support for main package library
├── target/
│ ├── debug
│ └── wheels
└── tests/ # Standard rust integration tests
└── rust_integration_test.rs But I have been struggling with getting Maturin to use the version from the top level Is something like this possible, or is there a better structure for creating mixed rust/python libraries? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not possible today since Cargo requires the You can't not avoid
|
Beta Was this translation helpful? Give feedback.
It's not possible today since Cargo requires the
version
field, see rust-lang/cargo#9829. But I think you can use something like cargo-workspaces or cargo-release to manage your crate versions.You can't not avoid
Cargo.toml
since you need to specify Rust dependencies.https://maturin.rs/metadata.html