Crates.io | cargo-pyinit |
lib.rs | cargo-pyinit |
version | 0.1.3 |
source | src |
created_at | 2020-12-28 07:16:44.946812 |
updated_at | 2021-09-28 03:24:18.710619 |
description | A cargo plugin to make it easier to write and convert crates into Python extension modules. |
homepage | https://github.com/rexlunae/cargo-pyinit |
repository | https://github.com/rexlunae/cargo-pyinit.git |
max_upload_size | |
id | 328147 |
size | 35,052 |
Cargo extension to make a Rust crate into a hybrid Python/Rust library.
This crate is based on PyO3 https://github.com/PyO3/pyo3
You will need:
setuptools_rust can be installed with pip:
pip install setuptools_rust
And toml can be installed like this:
pip install toml
From github:
git clone https://github.com/rexlunae/cargo-pyinit.git
cd cargo-pyinit
cargo install --path .
From cargo:
cargo install pyinit
pyinit can only be used to create or modify a library crate.
From inside a source directory:
cd my-create-directory
cargo pyinit
If the directory is already a cargo crate, it will convert it into a hybrid crate suitable for use with python. If the directory is empty, it will create a new library crate with the same name as the directory it's in.
From outside a directory:
cargo pyinit crate-name
This will create the directory with the given name, if needed, and either create a new crate or modify an existing crate.
Unlike the example code for PyO3, pyinit creates a new file (pylib.rs) that becomes the base of the library, which imports everything from the old lib.rs (or whatever it was previously called). This separates the Python interface definition somewhat, but it also means that some items that are only allowed at the top level of the crate such as feature flags be moved manually. When creating a new crate, the result will work out of the box with either cargo build
or the Python setup tools, however, if you are modifying an existing crate, you will probably have to spend some time manually moving things into the pylib.rs from your lib.rs. You will need to build the Python interface manually as well. This does not happen automatically.
The resulting hybrid crate has a setup.py, which can be installed in Python with either python setup.py develop
for a development version, or python setup.py install
for release. You can also use pip install .