Template repo for writing Python extensions in Rust.
Based on documentation at https://www.maturin.rs/index.html.
$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install .
(.venv) $ python
>>> from python_lib import StateMachine, par_run
>>> machines = [StateMachine for _ in range(100)]
>>> _ = par_run(machines)
The src/python folder contains example Python objects written in Rust. These are exported into the Python extension module in src/python_module.rs.
- Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Install pyenv:
curl https://pyenv.run | bash
- Install Python interpreter(s) listed in the file
.python-version
:
while read line; do
pyenv install "$line"
done < .python-version
- Create a virtual environment:
python3 -m venv .venv
- Activate the venv:
source .venv/bin/activate
- Install the dependencies:
pip install -e .[develop]
Run tests:
cargo test
Run linters:
cargo fmt -v --check
cargo clippy
Run all tests and linters:
tox
Run specific linters:
# Black, isort, mypy, pylint
tox -e black
# etc. ...
cargo fmt
tox -e format