From 9e4e0dbbe01dfe06ee5fcb41f3b2d01f13d04789 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Mon, 22 Feb 2021 22:34:09 +0000 Subject: [PATCH] auto-initialize: remove from default features --- CHANGELOG.md | 1 + Cargo.toml | 2 +- guide/src/features.md | 8 ++------ guide/src/migration.md | 6 ++++++ src/gil.rs | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e0e8f08083..f67ed39d0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Change `PyTimeAcces::get_fold()` to return a `bool` instead of a `u8`. [#1397](https://github.com/PyO3/pyo3/pull/1397) - Deprecate FFI definition `PyCFunction_Call` for Python 3.9 and later. [#1425](https://github.com/PyO3/pyo3/pull/1425) - Deprecate FFI definitions `PyModule_GetFilename`. [#1425](https://github.com/PyO3/pyo3/pull/1425) +- The `auto-initialize` feature is no longer enabled by default. [#1443](https://github.com/PyO3/pyo3/pull/1443) ### Removed - Remove deprecated exception names `BaseException` etc. [#1426](https://github.com/PyO3/pyo3/pull/1426) diff --git a/Cargo.toml b/Cargo.toml index 20f586fae4c..9419c71c69f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ pyo3 = { path = ".", default-features = false, features = ["macros", "auto-initi serde_json = "1.0.61" [features] -default = ["macros", "auto-initialize"] +default = ["macros"] # Enables macros: #[pyclass], #[pymodule], #[pyfunction] etc. macros = ["pyo3-macros", "indoc", "inventory", "paste", "unindent"] diff --git a/guide/src/features.md b/guide/src/features.md index 8a6e98a4145..7a1bfd5e27d 100644 --- a/guide/src/features.md +++ b/guide/src/features.md @@ -34,11 +34,7 @@ See the [building and distribution](building_and_distribution.md#minimum-python- 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. - -If you choose not to enable this feature, you should call `pyo3::prepare_freethreaded_python()` before attempting to call any other Python APIs. - -> This feature is enabled by default. To disable it, set `default-features = false` for the `pyo3` entry in your Cargo.toml. +If you do not enable this feature, you should call `pyo3::prepare_freethreaded_python()` before attempting to call any other Python APIs. ## Advanced Features @@ -67,7 +63,7 @@ The `nightly` feature needs the nightly Rust compiler. This allows PyO3 to use R ### `serde` -The `serde` feature enables (de)serialization of Py objects via [serde](https://serde.rs/). +The `serde` feature enables (de)serialization of Py objects via [serde](https://serde.rs/). This allows to use [`#[derive(Serialize, Deserialize)`](https://serde.rs/derive.html) on structs that hold references to `#[pyclass]` instances ```rust diff --git a/guide/src/migration.md b/guide/src/migration.md index dd742b0bc50..9e2ae2ba99c 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -3,6 +3,12 @@ This guide can help you upgrade code through breaking changes from one PyO3 version to the next. For a detailed list of all changes, see the [CHANGELOG](changelog.md). +## from 0.13.* to 0.14 + +### `auto-initialize` feature is now opt-in + +For projects embedding Python in Rust, PyO3 no longer automatically initalizes a Python interpreter on the first call to `Python::with_gil` (or `Python::acquire_gil`) unless the [`auto-initalize` feature](features.md#auto-initalize) is enabled. + ## from 0.12.* to 0.13 ### Minimum Rust version increased to Rust 1.45 diff --git a/src/gil.rs b/src/gil.rs index 4593f960808..bf33bed30da 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -217,7 +217,7 @@ impl GILGuard { cfg_if::cfg_if! { if #[cfg(all(feature = "auto-initialize", Py_SHARED, not(PyPy)))] { prepare_freethreaded_python(); - } else if #[cfg(all(feature = "auto-initialize", not(feature = "extension-module"), not(Py_SHARED), not(__pyo3_ci)))] { + } else if #[cfg(all(feature = "auto-initialize", not(Py_SHARED), not(__pyo3_ci)))] { compile_error!(concat!( "The `auto-initialize` feature is not supported when linking Python ", "statically instead of with a shared library.\n\n", @@ -229,7 +229,7 @@ impl GILGuard { "Alternatively, compile PyO3 using a Python distribution which contains a shared ", "libary." )); - } else if #[cfg(all(feature = "auto-initialize", not(feature = "extension-module"), PyPy, not(__pyo3_ci)))] { + } else if #[cfg(all(feature = "auto-initialize", PyPy, not(__pyo3_ci)))] { compile_error!(concat!( "The `auto-initialize` feature is not supported by PyPy.\n\n", "Please disable the `auto-initialize` feature, for example by entering the following ",