Skip to content

Commit

Permalink
Remove rust-cpython support from documentation (#2057)
Browse files Browse the repository at this point in the history
  • Loading branch information
messense authored Apr 25, 2024
1 parent ea6fa48 commit a2c7399
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["konstin <[email protected]>", "messense <[email protected]>"]
name = "maturin"
version = "1.5.1"
description = "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages"
description = "Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages"
exclude = [
"test-crates/**/*",
"sysconfig/*",
Expand Down
59 changes: 29 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _formerly pyo3-pack_
[![FreeBSD](https://img.shields.io/cirrus/github/PyO3/maturin/main?logo=CircleCI&style=flat-square)](https://cirrus-ci.com/github/PyO3/maturin)
[![discord server](https://img.shields.io/discord/1209263839632424990?logo=discord)](https://discord.gg/33kcChzH7f)

Build and publish crates with pyo3, rust-cpython, cffi and uniffi bindings as well as rust binaries as python packages with minimal configuration.
Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages with minimal configuration.
It supports building wheels for python 3.8+ on windows, linux, mac and freebsd, can upload them to [pypi](https://pypi.org/) and has basic pypy and graalpy support.

Check out the [User Guide](https://maturin.rs/)!
Expand All @@ -28,12 +28,12 @@ pipx install maturin
There are four main commands:

* `maturin new` creates a new cargo project with maturin configured.
* `maturin publish` builds the crate into python packages and publishes them to pypi.
* `maturin build` builds the wheels and stores them in a folder (`target/wheels` by default), but doesn't upload them. It's possible to upload those with [twine](https://github.com/pypa/twine) or `maturin upload`.
* `maturin develop` builds the crate and installs it as a python module directly in the current virtualenv. Note that while `maturin develop` is faster, it doesn't support all the feature that running `pip install` after `maturin build` supports.
- `maturin new` creates a new cargo project with maturin configured.
- `maturin publish` builds the crate into python packages and publishes them to pypi.
- `maturin build` builds the wheels and stores them in a folder (`target/wheels` by default), but doesn't upload them. It's possible to upload those with [twine](https://github.com/pypa/twine) or `maturin upload`.
- `maturin develop` builds the crate and installs it as a python module directly in the current virtualenv. Note that while `maturin develop` is faster, it doesn't support all the feature that running `pip install` after `maturin build` supports.

`pyo3` and `rust-cpython` bindings are automatically detected. For cffi or binaries, you need to pass `-b cffi` or `-b bin`.
`pyo3` bindings are automatically detected. For cffi or binaries, you need to pass `-b cffi` or `-b bin`.
maturin doesn't need extra configuration files and doesn't clash with an existing setuptools-rust or milksnake configuration.
You can even integrate it with testing tools such as [tox](https://tox.readthedocs.io/en/latest/).
There are examples for the different bindings in the `test-crates` folder.
Expand All @@ -46,7 +46,7 @@ The name of the module, which you are using when importing, will be the `name` v
Python packages come in two formats:
A built form called wheel and source distributions (sdist), both of which are archives.
A wheel can be compatible with any python version, interpreter (cpython and pypy, mainly), operating system and hardware architecture (for pure python wheels),
can be limited to a specific platform and architecture (e.g. when using ctypes or cffi) or to a specific python interpreter and version on a specific architecture and operating system (e.g. with pyo3 and rust-cpython).
can be limited to a specific platform and architecture (e.g. when using ctypes or cffi) or to a specific python interpreter and version on a specific architecture and operating system (e.g. with pyo3).

When using `pip install` on a package, pip tries to find a matching wheel and install that. If it doesn't find one, it downloads the source distribution and builds a wheel for the current platform,
which requires the right compilers to be installed. Installing a wheel is much faster than installing a source distribution as building wheels is generally slow.
Expand All @@ -55,9 +55,9 @@ When you publish a package to be installable with `pip install`, you upload it t
For testing, you can use [test pypi](https://test.pypi.org/) instead, which you can use with `pip install --index-url https://test.pypi.org/simple/`.
Note that for publishing for linux, [you need to use the manylinux docker container](#manylinux-and-auditwheel), while for publishing from your repository you can use the [PyO3/maturin-action github action](https://github.com/PyO3/maturin-action).

## pyo3 and rust-cpython
## pyo3

For pyo3 and rust-cpython, maturin can only build packages for installed python versions. On linux and mac, all python versions in `PATH` are used.
For pyo3, maturin can only build packages for installed python versions. On linux and mac, all python versions in `PATH` are used.
If you don't set your own interpreters with `-i`, a heuristic is used to search for python installations.
On windows all versions from the python launcher (which is installed by default by the python.org installer) and all conda environments except base are used. You can check which versions are picked up with the `list-python` subcommand.

Expand Down Expand Up @@ -146,7 +146,7 @@ my-project
maturin will add the native extension as a module in your python folder. When using develop, maturin will copy the native library and for cffi also the glue code to your python folder. You should add those files to your gitignore.

With cffi you can do `from .my_project import lib` and then use `lib.my_native_function`, with pyo3/rust-cpython you can directly `from .my_project import my_native_function`.
With cffi you can do `from .my_project import lib` and then use `lib.my_native_function`, with pyo3 you can directly `from .my_project import my_native_function`.

Example layout with pyo3 after `maturin develop`:

Expand All @@ -173,7 +173,6 @@ fn my_lib_name(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
}
```


## Python metadata

maturin supports [PEP 621](https://www.python.org/dev/peps/pep-0621/), you can specify python package metadata in `pyproject.toml`.
Expand Down Expand Up @@ -272,23 +271,23 @@ maturin itself is manylinux compliant when compiled for the musl target.

## Examples

* [ballista-python](https://github.com/apache/arrow-ballista-python) - A Python library that binds to Apache Arrow distributed query engine Ballista
* [chardetng-py](https://github.com/john-parton/chardetng-py) - Python binding for the chardetng character encoding detector.
* [connector-x](https://github.com/sfu-db/connector-x/tree/main/connectorx-python) - ConnectorX enables you to load data from databases into Python in the fastest and most memory efficient way
* [datafusion-python](https://github.com/apache/arrow-datafusion-python) - a Python library that binds to Apache Arrow in-memory query engine DataFusion
* [deltalake-python](https://github.com/delta-io/delta-rs/tree/main/python) - Native Delta Lake Python binding based on delta-rs with Pandas integration
* [opendal](https://github.com/apache/incubator-opendal/tree/main/bindings/python) - OpenDAL Python Binding to access data freely
* [orjson](https://github.com/ijl/orjson) - A fast, correct JSON library for Python
* [polars](https://github.com/pola-rs/polars/tree/master/py-polars) - Fast multi-threaded DataFrame library in Rust | Python | Node.js
* [pydantic-core](https://github.com/pydantic/pydantic-core) - Core validation logic for pydantic written in Rust
* [pyrus-cramjam](https://github.com/milesgranger/pyrus-cramjam) - Thin Python wrapper to de/compression algorithms in Rust
* [pyxel](https://github.com/kitao/pyxel) - A retro game engine for Python
* [roapi](https://github.com/roapi/roapi) - ROAPI automatically spins up read-only APIs for static datasets without requiring you to write a single line of code
* [robyn](https://github.com/sansyrox/robyn) - A fast and extensible async python web server with a Rust runtime
* [ruff](https://github.com/charliermarsh/ruff) - An extremely fast Python linter, written in Rust
* [tantivy-py](https://github.com/quickwit-oss/tantivy-py) - Python bindings for Tantivy
* [watchfiles](https://github.com/samuelcolvin/watchfiles) - Simple, modern and high performance file watching and code reload in python
* [wonnx](https://github.com/webonnx/wonnx/tree/master/wonnx-py) - Wonnx is a GPU-accelerated ONNX inference run-time written 100% in Rust
- [ballista-python](https://github.com/apache/arrow-ballista-python) - A Python library that binds to Apache Arrow distributed query engine Ballista
- [chardetng-py](https://github.com/john-parton/chardetng-py) - Python binding for the chardetng character encoding detector.
- [connector-x](https://github.com/sfu-db/connector-x/tree/main/connectorx-python) - ConnectorX enables you to load data from databases into Python in the fastest and most memory efficient way
- [datafusion-python](https://github.com/apache/arrow-datafusion-python) - a Python library that binds to Apache Arrow in-memory query engine DataFusion
- [deltalake-python](https://github.com/delta-io/delta-rs/tree/main/python) - Native Delta Lake Python binding based on delta-rs with Pandas integration
- [opendal](https://github.com/apache/incubator-opendal/tree/main/bindings/python) - OpenDAL Python Binding to access data freely
- [orjson](https://github.com/ijl/orjson) - A fast, correct JSON library for Python
- [polars](https://github.com/pola-rs/polars/tree/master/py-polars) - Fast multi-threaded DataFrame library in Rust | Python | Node.js
- [pydantic-core](https://github.com/pydantic/pydantic-core) - Core validation logic for pydantic written in Rust
- [pyrus-cramjam](https://github.com/milesgranger/pyrus-cramjam) - Thin Python wrapper to de/compression algorithms in Rust
- [pyxel](https://github.com/kitao/pyxel) - A retro game engine for Python
- [roapi](https://github.com/roapi/roapi) - ROAPI automatically spins up read-only APIs for static datasets without requiring you to write a single line of code
- [robyn](https://github.com/sansyrox/robyn) - A fast and extensible async python web server with a Rust runtime
- [ruff](https://github.com/charliermarsh/ruff) - An extremely fast Python linter, written in Rust
- [tantivy-py](https://github.com/quickwit-oss/tantivy-py) - Python bindings for Tantivy
- [watchfiles](https://github.com/samuelcolvin/watchfiles) - Simple, modern and high performance file watching and code reload in python
- [wonnx](https://github.com/webonnx/wonnx/tree/master/wonnx-py) - Wonnx is a GPU-accelerated ONNX inference run-time written 100% in Rust

## Contributing

Expand All @@ -309,7 +308,7 @@ If you don't have time to contribute yourself but still wish to support the proj

Licensed under either of:

* Apache License, Version 2.0, ([LICENSE-APACHE](https://github.com/PyO3/maturin/blob/main/license-apache) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](https://github.com/PyO3/maturin/blob/main/license-mit) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](https://github.com/PyO3/maturin/blob/main/license-apache) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](https://github.com/PyO3/maturin/blob/main/license-mit) or http://opensource.org/licenses/MIT)

at your option.
2 changes: 1 addition & 1 deletion ci/build_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Maintainer: konstin <[email protected]>
Architecture: $architecture
Provides: $BINARY_NAME
Conflicts: $conflictname
Description: Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages
Description: Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
EOF

fakeroot dpkg-deb --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb"
8 changes: 0 additions & 8 deletions guide/src/bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ from Python.
> **Note**: Maturin _does not_ automatically detect `cffi` bindings. You _must_
> specify them via either command line with `-b cffi` or in `pyproject.toml`.
## `rust-cpython`

[rust-cpython](https://github.com/dgrunwald/rust-cpython) is Rust bindings for
the Python interpreter. Currently it only supports CPython.

Maturin automatically detects rust-cpython bindings when it's added as a
dependency in `Cargo.toml`.

## `bin`

Maturin also supports distributing binary applications written in Rust as
Expand Down
10 changes: 5 additions & 5 deletions guide/src/distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ The [PyO3/maturin-action](https://github.com/PyO3/maturin-action) github action

maturin contains a reimplementation of auditwheel automatically checks the generated library and gives the wheel the proper platform tag.

* If your system's glibc is too new, it will assign the `linux` tag.
* If you link other shared libraries, maturin will try to bundle them within the wheel, note that this requires [patchelf](https://github.com/NixOS/patchelf),
- If your system's glibc is too new, it will assign the `linux` tag.
- If you link other shared libraries, maturin will try to bundle them within the wheel, note that this requires [patchelf](https://github.com/NixOS/patchelf),
it can be installed along with maturin from PyPI: `pip install maturin[patchelf]`.

You can also manually disable those checks and directly use native linux target with `--manylinux off`.
Expand All @@ -68,7 +68,6 @@ Note that this image is very basic and only contains python, maturin and stable
See [konstin/complex-manylinux-maturin-docker](https://github.com/konstin/complex-manylinux-maturin-docker) for a small educational example
or [nanoporetech/fast-ctc-decode](https://github.com/nanoporetech/fast-ctc-decode/blob/b226ea0f2b2f4f474eff47349703d57d2ea4801b/.github/workflows/publish.yml) for a real world setup.


```
Usage: maturin build [OPTIONS] [ARGS]...
Expand Down Expand Up @@ -103,7 +102,7 @@ Options:
-b, --bindings <BINDINGS>
Which kind of bindings to use
[possible values: pyo3, pyo3-ffi, rust-cpython, cffi, uniffi, bin]
[possible values: pyo3, pyo3-ffi, cffi, uniffi, bin]
-o, --out <OUT>
The directory to store the built wheels in. Defaults to a new "wheels" directory in the project's target directory
Expand Down Expand Up @@ -202,7 +201,7 @@ And [maturin-action](https://github.com/PyO3/maturin-action) makes it easy to do
##### Use Zig

Since v0.12.7 maturin added support for linking with [`zig cc`](https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html),
compile for Linux works and is regularly tested on CI, other platforms may also work but aren't tested regularly.
compile for Linux works and is regularly tested on CI, other platforms may also work but aren't tested regularly.

You can install zig following the [official documentation](https://ziglang.org/download), or install it from PyPI via `pip install ziglang`.
Then pass `--zig` to maturin `build` or `publish` commands to use it, for example
Expand Down Expand Up @@ -294,6 +293,7 @@ Options:
By default, the workflow provided by `generate-ci` will publish the release artifacts to PyPI using API token authentication. However, maturin also supports [trusted publishing (OpenID Connect)](https://docs.pypi.org/trusted-publishers/).

To enable it, modify the `release` action in the generated GitHub workflow file:

- remove `MATURIN_PYPI_TOKEN` from the `env` section to make maturin use trusted publishing
- add `id-token: write` to the action's `permissions` (see [Configuring OpenID Connect in PyPI](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-pypi) from GitHub's documentation).
- if `Environment name: release` was set in PyPI, add `environment: release`
Expand Down
4 changes: 3 additions & 1 deletion guide/src/local_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Options:
-b, --bindings <BINDINGS>
Which kind of bindings to use
[possible values: pyo3, pyo3-ffi, rust-cpython, cffi, uniffi, bin]
[possible values: pyo3, pyo3-ffi, cffi, uniffi, bin]
--strip
Strip the library for minimum file size
Expand Down Expand Up @@ -131,7 +131,9 @@ To install a package in editable mode with pip:
cd my-project
pip install -e .
```

or

```bash
cd my-project
maturin develop
Expand Down
9 changes: 6 additions & 3 deletions guide/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Options:
--name <NAME> Set the resulting package name, defaults to the directory name
--mixed Use mixed Rust/Python project layout
--src Use Python first src layout for mixed Rust/Python project
-b, --bindings <BINDINGS> Which kind of bindings to use [possible values: pyo3, rust-cpython, cffi, uniffi, bin]
-b, --bindings <BINDINGS> Which kind of bindings to use [possible values: pyo3, cffi, uniffi, bin]
-h, --help Print help information
```

Expand All @@ -93,7 +93,7 @@ tomli==2.0.1
```

maturin is configured in `pyproject.toml` as introduced by [PEP
518](https://www.python.org/dev/peps/pep-0518/). This file lives in the root
518](https://www.python.org/dev/peps/pep-0518/). This file lives in the root
of your project tree:

```ignore
Expand Down Expand Up @@ -180,6 +180,7 @@ fn guessing_game(m: &Bound<'_, PyModule>) -> PyResult<()> {

Thanks to pyo3, there's very little difference between this and the example in
The Rust Book. All we had to do was:

1. Include the pyo3 prelude
2. Add `#[pyfunction]` to our function
3. Add the `#[pymodule]` block to expose the function as part of a Python module
Expand All @@ -189,7 +190,7 @@ pyo3. It can do a lot more!

## Build and install the module with `maturin develop`

Note that *this is just a Rust project* at this point, and with few exceptions
Note that _this is just a Rust project_ at this point, and with few exceptions
you can build it as you'd expect using `cargo build`. maturin helps with this,
however, adding some platform-specific build configuration and ultimately
packaging the binary results as a wheel (a `.whl` file, which is an archive of
Expand Down Expand Up @@ -233,6 +234,7 @@ So let's use maturin to build and install in our current environment.

Your `guessing_game` module should now be available in your current virtual
environment. Go ahead and play a few games!

```shell
(.venv) ferris@rustbox [~/src/rust/guessing-game] % python
Python 3.9.6 (default, Aug 25 2021, 16:04:27)
Expand Down Expand Up @@ -286,6 +288,7 @@ maturin can even publish wheels directly to [PyPI](https://pypi.org) with
`maturin publish`!

## Summary

Congratulations! You successfully created a Python module implemented entirely
in Rust thanks to pyo3 and maturin.

Expand Down
2 changes: 1 addition & 1 deletion maturin/import_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def install(bindings: str | None = None, release: bool = False) -> Importer | No
Install the import hook.
:param bindings: Which kind of bindings to use.
Possible values are pyo3, rust-cpython and cffi
Possible values are pyo3, cffi and uniffi
:param release: Build in release mode, otherwise debug mode by default
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def finalize_options(self):
author="konstin",
author_email="[email protected]",
url="https://github.com/pyo3/maturin",
description="Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as "
description="Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as "
"python packages",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries
//! Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries
//! as python packages. This file contains the CLI and keyring integration.
//!
//! Run with --help for usage information
Expand Down Expand Up @@ -34,7 +34,7 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
styles = cargo_options::styles(),
)]
#[cfg_attr(clippy, allow(clippy::large_enum_variant))]
/// Build and publish crates with pyo3, rust-cpython and cffi bindings as well
/// Build and publish crates with pyo3, cffi and uniffi bindings as well
/// as rust binaries as python packages
enum Opt {
#[command(name = "build", alias = "b")]
Expand Down
Loading

0 comments on commit a2c7399

Please sign in to comment.