From a2c73998a1458e03bd8a1daccb0465169b53a5ac Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 25 Apr 2024 09:38:35 +0800 Subject: [PATCH] Remove rust-cpython support from documentation (#2057) --- Cargo.toml | 2 +- README.md | 59 +++++++++++++++++----------------- ci/build_deb.sh | 2 +- guide/src/bindings.md | 8 ----- guide/src/distribution.md | 10 +++--- guide/src/local_development.md | 4 ++- guide/src/tutorial.md | 9 ++++-- maturin/import_hook.py | 2 +- setup.py | 2 +- src/main.rs | 4 +-- tests/cmd/maturin.stdout | 4 +-- 11 files changed, 51 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 85e96a6b4..b02f04304 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["konstin ", "messense "] 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/*", diff --git a/README.md b/README.md index 531d8a77b..baba64754 100644 --- a/README.md +++ b/README.md @@ -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/)! @@ -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. @@ -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. @@ -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. @@ -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`: @@ -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`. @@ -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 @@ -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. diff --git a/ci/build_deb.sh b/ci/build_deb.sh index 4e1d529cc..64f75eac1 100755 --- a/ci/build_deb.sh +++ b/ci/build_deb.sh @@ -45,7 +45,7 @@ Maintainer: konstin 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" diff --git a/guide/src/bindings.md b/guide/src/bindings.md index 18b53d464..04193d921 100644 --- a/guide/src/bindings.md +++ b/guide/src/bindings.md @@ -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 diff --git a/guide/src/distribution.md b/guide/src/distribution.md index f1bea9ed7..a02686329 100644 --- a/guide/src/distribution.md +++ b/guide/src/distribution.md @@ -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`. @@ -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]... @@ -103,7 +102,7 @@ Options: -b, --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 The directory to store the built wheels in. Defaults to a new "wheels" directory in the project's target directory @@ -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 @@ -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` diff --git a/guide/src/local_development.md b/guide/src/local_development.md index 4d1506c02..8e6f64eef 100644 --- a/guide/src/local_development.md +++ b/guide/src/local_development.md @@ -16,7 +16,7 @@ Options: -b, --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 @@ -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 diff --git a/guide/src/tutorial.md b/guide/src/tutorial.md index 49a763339..0f2c3ec53 100644 --- a/guide/src/tutorial.md +++ b/guide/src/tutorial.md @@ -71,7 +71,7 @@ Options: --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 Which kind of bindings to use [possible values: pyo3, rust-cpython, cffi, uniffi, bin] + -b, --bindings Which kind of bindings to use [possible values: pyo3, cffi, uniffi, bin] -h, --help Print help information ``` @@ -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 @@ -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 @@ -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 @@ -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) @@ -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. diff --git a/maturin/import_hook.py b/maturin/import_hook.py index affe3eb9c..0fb31433a 100644 --- a/maturin/import_hook.py +++ b/maturin/import_hook.py @@ -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 """ diff --git a/setup.py b/setup.py index 50d15be8c..4ce8c4468 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ def finalize_options(self): author="konstin", author_email="konstin@mailbox.org", 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", diff --git a/src/main.rs b/src/main.rs index a5aae5df2..7f671f210 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 @@ -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")] diff --git a/tests/cmd/maturin.stdout b/tests/cmd/maturin.stdout index 25c7ec597..0dae24da2 100644 --- a/tests/cmd/maturin.stdout +++ b/tests/cmd/maturin.stdout @@ -1,5 +1,5 @@ -Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as -python packages +Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python +packages Usage: maturin[EXE]