-
Notifications
You must be signed in to change notification settings - Fork 868
auto-initialize: new feature to control initializing Python #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,27 +85,28 @@ jobs: | |
run: echo LD_LIBRARY_PATH=${pythonLocation}/lib >> $GITHUB_ENV | ||
|
||
- name: Build docs | ||
run: cargo doc --features "num-bigint num-complex hashbrown" --verbose --target ${{ matrix.platform.rust-target }} | ||
run: cargo doc --no-default-features --features "macros num-bigint num-complex hashbrown" --verbose --target ${{ matrix.platform.rust-target }} | ||
|
||
- name: Build without default features | ||
- name: Build (no features) | ||
run: cargo build --no-default-features --verbose --target ${{ matrix.platform.rust-target }} | ||
|
||
- name: Build with default features | ||
run: cargo build --features "num-bigint num-complex hashbrown" --verbose --target ${{ matrix.platform.rust-target }} | ||
- name: Build (all additive features) | ||
run: cargo build --no-default-features --features "macros num-bigint num-complex hashbrown" --verbose --target ${{ matrix.platform.rust-target }} | ||
|
||
# Run tests (except on PyPy, because no embedding API). | ||
- if: matrix.python-version != 'pypy-3.6' | ||
name: Test | ||
run: cargo test --features "num-bigint num-complex hashbrown" --target ${{ matrix.platform.rust-target }} | ||
run: cargo test --no-default-features --features "macros num-bigint num-complex hashbrown" --target ${{ matrix.platform.rust-target }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's automatically included in tests because I put this in
However, that's also the reason why Because in the future what I've done here will work correctly in the future, I'm going to keep the code mostly as-is for the moment and introduce a hack to avoid the immediate issue with a TODO to tidy it up once we bump MSRV in the future (probably to Rust 1.52). |
||
|
||
# Run tests again, but in abi3 mode | ||
- if: matrix.python-version != 'pypy-3.6' | ||
name: Test (abi3) | ||
run: cargo test --no-default-features --features "abi3,macros" --target ${{ matrix.platform.rust-target }} | ||
run: cargo test --no-default-features --features "abi3 macros num-bigint num-complex hashbrown" --target ${{ matrix.platform.rust-target }} | ||
|
||
# Run tests again, for abi3-py36 (the minimal Python version) | ||
- if: (matrix.python-version != 'pypy-3.6') && (matrix.python-version != '3.6') | ||
name: Test (abi3-py36) | ||
run: cargo test --no-default-features --features "abi3-py36,macros" --target ${{ matrix.platform.rust-target }} | ||
run: cargo test --no-default-features --features "abi3-py36 macros num-bigint num-complex hashbrown" --target ${{ matrix.platform.rust-target }} | ||
|
||
- name: Test proc-macro code | ||
run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml --target ${{ matrix.platform.rust-target }} | ||
|
@@ -125,6 +126,9 @@ jobs: | |
env: | ||
RUST_BACKTRACE: 1 | ||
RUSTFLAGS: "-D warnings" | ||
# TODO: this is a hack to workaround compile_error! warnings about auto-initialize on PyPy | ||
# Once cargo's `resolver = "2"` is stable (~ MSRV Rust 1.52), remove this. | ||
PYO3_CI: 1 | ||
|
||
coverage: | ||
needs: [fmt] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Features Reference | ||
|
||
PyO3 provides a number of Cargo features to customise functionality. This chapter of the guide provides detail on each of them. | ||
|
||
By default, the `macros` and `auto-initialize` features are enabled. | ||
|
||
## Features for extension module authors | ||
|
||
### `extension-module` | ||
|
||
This feature is required when building a Python extension module using PyO3. | ||
|
||
It tells PyO3's build script to skip linking against `libpython.so` on Unix platforms, where this must not be done. | ||
|
||
See the [building and distribution](building_and_distribution.md#linking) section for further detail. | ||
|
||
### `abi3` | ||
|
||
This feature is used when building Python extension modules to create wheels which are compatible with multiple Python versions. | ||
|
||
It restricts PyO3's API to a subset of the full Python API which is guaranteed by [PEP 384](https://www.python.org/dev/peps/pep-0384/) to be forwards-compatible with future Python versions. | ||
|
||
See the [building and distribution](building_and_distribution.md#py_limited_apiabi3) section for further detail. | ||
|
||
### `abi3-py36` / `abi3-py37` / `abi3-py38` / `abi3-py39` | ||
|
||
These features are an extension of the `abi3` feature to specify the exact minimum Python version which the multiple-version-wheel will support. | ||
|
||
See the [building and distribution](building_and_distribution.md#minimum-python-version-for-abi3) section for further detail. | ||
|
||
## Features for embedding Python in Rust | ||
|
||
### `auto-initalize` | ||
|
||
This feature changes [`Python::with_gil`](https://docs.rs/pyo3/latest/pyo3/struct.Python.html#method.with_gil) and [`Python::acquire_gil`](https://docs.rs/pyo3/latest/pyo3/struct.Python.html#method.acquire_gil) to automatically initialize a Python interpreter (by calling [`prepare_freethreaded_python`](https://docs.rs/pyo3/latest/pyo3/fn.prepare_freethreaded_python.html)) if needed. | ||
|
||
This feature is not needed for extension modules, but for compatibility it is enabled by default until at least the PyO3 0.14 release. | ||
|
||
> This feature is enabled by default. To disable it, set `default-features = false` for the `pyo3` entry in your Cargo.toml. | ||
|
||
## Advanced Features | ||
|
||
### `macros` | ||
|
||
This feature enables a dependency on the `pyo3-macros` crate, which provides the procedural macros portion of PyO3's API: | ||
|
||
- `#[pymodule]` | ||
- `#[pyfunction]` | ||
- `#[pyclass]` | ||
- `#[pymethods]` | ||
- `#[pyproto]` | ||
- `#[derive(FromPyObject)]` | ||
|
||
It also provides the `py_run!` macro. | ||
|
||
These macros require a number of dependencies which may not be needed by users who just need PyO3 for Python FFI. Disabling this feature enables faster builds for those users, as these dependencies will not be built if this feature is disabled. | ||
|
||
> This feature is enabled by default. To disable it, set `default-features = false` for the `pyo3` entry in your Cargo.toml. | ||
|
||
### `nightly` | ||
|
||
The `nightly` feature needs the nightly Rust compiler. This allows PyO3 to use Rust's unstable specialization feature to apply the following optimizations: | ||
- `FromPyObject` for `Vec` and `[T;N]` can perform a `memcpy` when the object supports the Python buffer protocol. | ||
- `ToBorrowedObject` can skip a reference count increase when the provided object is a Python native type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that
auto-initialize
andmacros
are enabled in this build, though I don't know why 😕There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because of the
Cargo.toml
changes - see other comment.