Skip to content
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

release: 0.18.1 #2928

Merged
merged 54 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
bed4f9d
Merge #2883
bors[bot] Jan 17, 2023
89d4ae1
rename `wrap_pyfunction` impl to `wrap_pyfunction_impl`
davidhewitt Jan 19, 2023
586fed2
send errors in `__releasebuffer__` to `sys.unraisablehook`
davidhewitt Jan 19, 2023
0c9078a
Merge #2886
bors[bot] Jan 19, 2023
dbb108c
Merge #2893
bors[bot] Jan 19, 2023
255d9ba
tidy up implementation of pyclass `tp_dealloc`
davidhewitt Jan 19, 2023
4d85374
Merge #2895
bors[bot] Jan 19, 2023
16d347d
remove benchmarks from deprecated_pyfunctions
davidhewitt Jan 20, 2023
0362855
make rust benchmarks more similar to the Python ones
davidhewitt Jan 20, 2023
e83803e
add link on how to obtain GIL to guide
davidhewitt Jan 20, 2023
8f0a2bb
Merge #2897
bors[bot] Jan 20, 2023
18081ba
Merge #2896
bors[bot] Jan 20, 2023
fe7b1ee
Update `downcast` documentation
mejrs Jan 24, 2023
e637b39
Fix link for #2879
qbx2 Jan 26, 2023
9004bd2
Merge #2919
bors[bot] Jan 26, 2023
2052269
Update rust 1.67
mejrs Jan 26, 2023
98b1297
Merge #2922
bors[bot] Jan 26, 2023
f38841a
Check to see if object is `None` before traversing
neachdainn Jan 26, 2023
f11290d
Add additional unit test for GC traversal
neachdainn Jan 27, 2023
5667a09
hygiene: fix `#[pymethods(crate = "...")]`
davidhewitt Jan 27, 2023
e4a3d28
refactor docstring generation code
davidhewitt Jan 24, 2023
3c9ace0
add Ellipsis() and is_ellipsis() methods, fix #2906
samuelcolvin Jan 25, 2023
794e19d
Merge #2911
bors[bot] Jan 27, 2023
083dd5f
Merge #2904 #2921
bors[bot] Jan 27, 2023
1a4153f
remove unneeded into_iter calls
davidhewitt Jan 27, 2023
2228f58
added a plugin example that shows how to integrate a Python plugin in…
alexpyattaev Jan 10, 2023
d7601a4
add cargo-generate template for plugin example
davidhewitt Jan 27, 2023
d118ee3
Merge #2923 #2924
bors[bot] Jan 27, 2023
efb8a12
Merge #2873
bors[bot] Jan 27, 2023
cadcaba
Feedback
mejrs Jan 28, 2023
edaba66
Pin trybuild to an MSRV-compatible version
adamreichold Jan 28, 2023
165062e
Merge #2907
bors[bot] Jan 28, 2023
f8e2a26
Warn about unknown config keys in `PYO3_CONFIG_FILE`
messense Jan 29, 2023
3149a80
Merge #2926
bors[bot] Jan 29, 2023
f495322
correct ffi definition of PyIter_Check
davidhewitt Jan 25, 2023
066880e
Added support for PyErr_WriteUnraisable
mitsuhiko Jan 18, 2023
cb38ff0
Merge #2889
bors[bot] Jan 29, 2023
c09dfcd
add PyDict.update() and PyDict.update_if_missing()
samuelcolvin Jan 25, 2023
141cbea
Merge #2912
bors[bot] Feb 3, 2023
26cf9b7
changelog: add missing entry for frozen
davidhewitt Feb 3, 2023
96efb0e
add better error message for Python in signature
davidhewitt Feb 3, 2023
97712a1
Merge #2933
bors[bot] Feb 3, 2023
5bab0e9
use simplified PyIter_Check on CPython 3.7
davidhewitt Feb 3, 2023
864aee0
Merge #2930
bors[bot] Feb 3, 2023
806eed5
Merge #2914
bors[bot] Feb 3, 2023
c709f30
guide: add documentation for trailing option arguments
davidhewitt Feb 3, 2023
9306d56
docs: Precise the abscense of `py: Python` for the #[pyo3(signature)]
jjerphan Jan 29, 2023
4d80475
Merge #2929
bors[bot] Feb 3, 2023
bc1a33f
bump maturin version in getting_started.md
jmhodges Feb 4, 2023
1e4dc54
Merge #2936
bors[bot] Feb 4, 2023
d67a8dc
link against pythonXY_d.dll for debug Python on Windows
davidhewitt Feb 6, 2023
2db351b
Merge #2937
bors[bot] Feb 7, 2023
9e5c845
Merge #2934
bors[bot] Feb 7, 2023
37d377e
release: 0.18.1
davidhewitt Feb 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ To see unreleased changes, please see the [CHANGELOG on the main branch guide](h

<!-- towncrier release notes start -->

## [0.18.1] - 2023-02-07

### Added

- Add `PyErr::write_unraisable()`. [#2889](https://github.com/PyO3/pyo3/pull/2889)
- Add `Python::Ellipsis()` and `PyAny::is_ellipsis()` methods. [#2911](https://github.com/PyO3/pyo3/pull/2911)
- Add `PyDict::update()` and `PyDict::update_if_missing()` methods. [#2912](https://github.com/PyO3/pyo3/pull/2912)

### Changed

- FFI definition `PyIter_Check` on CPython 3.7 is now implemented as `hasattr(type(obj), "__next__")`, which works correctly on all platforms and adds support for `abi3`. [#2914](https://github.com/PyO3/pyo3/pull/2914)
- Warn about unknown config keys in `PYO3_CONFIG_FILE` instead of denying. [#2926](https://github.com/PyO3/pyo3/pull/2926)

### Fixed

- Send errors returned by `__releasebuffer__` to `sys.unraisablehook` rather than causing `SystemError`. [#2886](https://github.com/PyO3/pyo3/pull/2886)
- Fix downcast to `PyIterator` succeeding for Python classes which did not implement `__next__`. [#2914](https://github.com/PyO3/pyo3/pull/2914)
- Fix segfault in `__traverse__` when visiting `None` fields of `Option<T: AsPyPointer>`. [#2921](https://github.com/PyO3/pyo3/pull/2921)
- Fix `#[pymethods(crate = "...")]` option being ignored. [#2923](https://github.com/PyO3/pyo3/pull/2923)
- Link against `pythonXY_d.dll` for debug Python builds on Windows. [#2937](https://github.com/PyO3/pyo3/pull/2937)


## [0.18.0] - 2023-01-17

### Packaging
Expand Down Expand Up @@ -48,7 +70,7 @@ To see unreleased changes, please see the [CHANGELOG on the main branch guide](h
- Accept any iterator in `PySet::new` and `PyFrozenSet::new`. [#2795](https://github.com/PyO3/pyo3/pull/2795)
- Mixing `#[cfg(...)]` and `#[pyo3(...)]` attributes on `#[pyclass]` struct fields will now work. [#2796](https://github.com/PyO3/pyo3/pull/2796)
- Re-enable `PyFunction` on when building for abi3 or PyPy. [#2838](https://github.com/PyO3/pyo3/pull/2838)
- Improve `derive(FromPyObject)` to use `intern!` when applicable for `#[pyo3(item)]`. [#2838](https://github.com/PyO3/pyo3/pull/2838)
- Improve `derive(FromPyObject)` to use `intern!` when applicable for `#[pyo3(item)]`. [#2879](https://github.com/PyO3/pyo3/pull/2879)

### Removed

Expand Down Expand Up @@ -124,6 +146,7 @@ To see unreleased changes, please see the [CHANGELOG on the main branch guide](h
- Add `PyCode` and `PyFrame` high level objects. [#2408](https://github.com/PyO3/pyo3/pull/2408)
- Add FFI definitions `Py_fstring_input`, `sendfunc`, and `_PyErr_StackItem`. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Add `PyDateTime::new_with_fold`, `PyTime::new_with_fold`, `PyTime::get_fold`, and `PyDateTime::get_fold` for PyPy. [#2428](https://github.com/PyO3/pyo3/pull/2428)
- Add `#[pyclass(frozen)]`. [#2448](https://github.com/PyO3/pyo3/pull/2448)
- Accept `#[pyo3(name)]` on enum variants. [#2457](https://github.com/PyO3/pyo3/pull/2457)
- Add `CompareOp::matches` to implement `__richcmp__` as the result of a Rust `std::cmp::Ordering` comparison. [#2460](https://github.com/PyO3/pyo3/pull/2460)
- Add `PySuper` type. [#2486](https://github.com/PyO3/pyo3/pull/2486)
Expand Down Expand Up @@ -1369,7 +1392,8 @@ Yanked

- Initial release

[Unreleased]: https://github.com/pyo3/pyo3/compare/v0.18.0...HEAD
[Unreleased]: https://github.com/pyo3/pyo3/compare/v0.18.1...HEAD
[0.18.1]: https://github.com/pyo3/pyo3/compare/v0.18.0...v0.18.1
[0.18.0]: https://github.com/pyo3/pyo3/compare/v0.17.3...v0.18.0
[0.17.3]: https://github.com/pyo3/pyo3/compare/v0.17.2...v0.17.3
[0.17.2]: https://github.com/pyo3/pyo3/compare/v0.17.1...v0.17.2
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyo3"
version = "0.18.0"
version = "0.18.1"
description = "Bindings to Python interpreter"
authors = ["PyO3 Project and Contributors <https://github.com/PyO3>"]
readme = "README.md"
Expand All @@ -20,10 +20,10 @@ parking_lot = ">= 0.11, < 0.13"
memoffset = "0.8"

# ffi bindings to the python interpreter, split into a separate crate so they can be used independently
pyo3-ffi = { path = "pyo3-ffi", version = "=0.18.0" }
pyo3-ffi = { path = "pyo3-ffi", version = "=0.18.1" }

# support crates for macros feature
pyo3-macros = { path = "pyo3-macros", version = "=0.18.0", optional = true }
pyo3-macros = { path = "pyo3-macros", version = "=0.18.1", optional = true }
indoc = { version = "1.0.3", optional = true }
unindent = { version = "0.1.4", optional = true }

Expand Down Expand Up @@ -56,7 +56,7 @@ rayon = "1.0.2"
widestring = "0.5.1"

[build-dependencies]
pyo3-build-config = { path = "pyo3-build-config", version = "0.18.0", features = ["resolve-config"] }
pyo3-build-config = { path = "pyo3-build-config", version = "0.18.1", features = ["resolve-config"] }

[features]
default = ["macros"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ name = "string_sum"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.18.0", features = ["extension-module"] }
pyo3 = { version = "0.18.1", features = ["extension-module"] }
```

**`src/lib.rs`**
Expand Down Expand Up @@ -137,7 +137,7 @@ Start a new project with `cargo new` and add `pyo3` to the `Cargo.toml` like th

```toml
[dependencies.pyo3]
version = "0.18.0"
version = "0.18.1"
features = ["auto-initialize"]
```

Expand Down
2 changes: 1 addition & 1 deletion benches/bench_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn set_new(b: &mut Bencher<'_>) {
const LEN: usize = 100_000;
// Create Python objects up-front, so that the benchmark doesn't need to include
// the cost of allocating LEN Python integers
let elements: Vec<PyObject> = (0..LEN).into_iter().map(|i| i.into_py(py)).collect();
let elements: Vec<PyObject> = (0..LEN).map(|i| i.into_py(py)).collect();
b.iter(|| {
let pool = unsafe { py.new_pool() };
PySet::new(py, &elements).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish = false
edition = "2018"

[dev-dependencies]
pyo3 = { version = "0.18.0", path = "..", features = ["auto-initialize", "extension-module"] }
pyo3 = { version = "0.18.1", path = "..", features = ["auto-initialize", "extension-module"] }

[[example]]
name = "decorator"
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Below is a brief description of each of these:
| `maturin-starter` | A template project which is configured to use [`maturin`](https://github.com/PyO3/maturin) for development. |
| `setuptools-rust-starter` | A template project which is configured to use [`setuptools_rust`](https://github.com/PyO3/setuptools-rust/) for development. |
| `word-count` | A quick performance comparison between word counter implementations written in each of Rust and Python. |
| `plugin` | Illustrates how to use Python as a scripting language within a Rust application |

## Creating new projects from these examples

Expand Down
2 changes: 1 addition & 1 deletion examples/decorator/.template/pre-script.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable::set("PYO3_VERSION", "0.18.0");
variable::set("PYO3_VERSION", "0.18.1");
file::rename(".template/Cargo.toml", "Cargo.toml");
file::rename(".template/pyproject.toml", "pyproject.toml");
file::rename(".template/tox.ini", "tox.ini");
Expand Down
2 changes: 1 addition & 1 deletion examples/maturin-starter/.template/pre-script.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable::set("PYO3_VERSION", "0.18.0");
variable::set("PYO3_VERSION", "0.18.1");
file::rename(".template/Cargo.toml", "Cargo.toml");
file::rename(".template/pyproject.toml", "pyproject.toml");
file::rename(".template/tox.ini", "tox.ini");
Expand Down
Binary file added examples/plugin/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions examples/plugin/.template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
authors = ["{{authors}}"]
name = "{{project-name}}"
version = "0.1.0"
edition = "2021"

[dependencies]
pyo3 = "{{PYO3_VERSION}}"
plugin_api = { path = "plugin_api" }
17 changes: 17 additions & 0 deletions examples/plugin/.template/plugin_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "plugin_api"
version = "0.1.0"
description = "Plugin API example"
edition = "2021"

[lib]
name = "plugin_api"
crate-type = ["cdylib", "rlib"]

[dependencies]
#!!! Important - DO NOT ENABLE extension-module FEATURE HERE!!!
pyo3 = "{{PYO3_VERSION}}"

[features]
# instead extension-module feature for pyo3 is enabled conditionally when we want to build a standalone extension module to test our plugins without "main" program
extension-module = ["pyo3/extension-module"]
4 changes: 4 additions & 0 deletions examples/plugin/.template/pre-script.rhai
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable::set("PYO3_VERSION", "0.18.1");
file::rename(".template/Cargo.toml", "Cargo.toml");
file::rename(".template/plugin_api/Cargo.toml", "plugin_api/Cargo.toml");
file::delete(".template");
12 changes: 12 additions & 0 deletions examples/plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "plugin_example"
version = "0.1.0"
edition = "2021"


[dependencies]
pyo3={path="../../", features=["macros"]}
plugin_api={path="plugin_api"}


[workspace]
48 changes: 48 additions & 0 deletions examples/plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# plugin

An example of a Rust app that uses Python for a plugin. A Python extension module built using PyO3 and [`maturin`](https://github.com/PyO3/maturin) is used to provide
interface types that can be used to exchange data between Rust and Python. This also deals with how to separately test and load python modules.

# Building and Testing
## Host application
To run the app itself, you only need to run

```shell
cargo run
```
It will build the app, as well as the plugin API, then run the app, load the plugin and show it working.

## Plugin API testing

The plugin API is in a separate crate `plugin_api`, so you can test it separately from the main app.

To build the API only package, first install `maturin`:

```shell
pip install maturin
```

When building the plugin, simply using `maturin develop` will fail to produce a viable extension module due to the features arrangement of PyO3.
Instead, one needs to enable the optional feature as follows:

```shell
cd plugin_api
maturin build --features "extension-module"
```

Alternatively, install nox and run the tests inside an isolated environment:

```shell
nox
```

## Copying this example

Use [`cargo-generate`](https://crates.io/crates/cargo-generate):

```bash
$ cargo install cargo-generate
$ cargo generate --git https://github.com/PyO3/pyo3 examples/plugin
```

(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
5 changes: 5 additions & 0 deletions examples/plugin/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[template]
ignore = [".nox"]

[hooks]
pre = [".template/pre-script.rhai"]
17 changes: 17 additions & 0 deletions examples/plugin/plugin_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "plugin_api"
version = "0.1.0"
description = "Plugin API example"
edition = "2021"

[lib]
name = "plugin_api"
crate-type = ["cdylib", "rlib"]

[dependencies]
#!!! Important - DO NOT ENABLE extension-module FEATURE HERE!!!
pyo3 = { path = "../../../" }

[features]
# instead extension-module feature for pyo3 is enabled conditionally when we want to build a standalone extension module to test our plugins without "main" program
extension-module = ["pyo3/extension-module"]
9 changes: 9 additions & 0 deletions examples/plugin/plugin_api/noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import nox


@nox.session
def python(session):
session.install("-rrequirements-dev.txt")
session.install("maturin")
session.run_always("maturin", "develop", "--features", "extension-module")
session.run("pytest")
14 changes: 14 additions & 0 deletions examples/plugin/plugin_api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build-system]
requires = ["maturin>=0.14,<0.15"]
build-backend = "maturin"

[project]
name = "plugin_api"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]


3 changes: 3 additions & 0 deletions examples/plugin/plugin_api/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest>=3.5.0
pip>=21.3
maturin>=0.14
32 changes: 32 additions & 0 deletions examples/plugin/plugin_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use pyo3::prelude::*;

///this is our Gadget that python plugin code can create, and rust app can then access natively.
#[pyclass]
pub struct Gadget {
#[pyo3(get, set)]
pub prop: usize,
//this field will only be accessible to rust code
pub rustonly: Vec<usize>,
}

#[pymethods]
impl Gadget {
#[new]
fn new() -> Self {
Gadget {
prop: 777,
rustonly: Vec::new(),
}
}

fn push(&mut self, v: usize) {
self.rustonly.push(v);
}
}

/// A Python module for plugin interface types
#[pymodule]
pub fn plugin_api(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<Gadget>()?;
Ok(())
}
22 changes: 22 additions & 0 deletions examples/plugin/plugin_api/tests/test_Gadget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest


@pytest.fixture
def gadget():
import plugin_api as pa

g = pa.Gadget()
return g


def test_creation(gadget):
pass


def test_property(gadget):
gadget.prop = 42
assert gadget.prop == 42


def test_push(gadget):
gadget.push(42)
2 changes: 2 additions & 0 deletions examples/plugin/plugin_api/tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_import():
import plugin_api
12 changes: 12 additions & 0 deletions examples/plugin/python_plugin/gadget_init_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import plugin_api
import rng


def start():
"""create an instance of Gadget, configure it and return to Rust"""
g = plugin_api.Gadget()
g.push(1)
g.push(2)
g.push(3)
g.prop = rng.get_random_number()
return g
3 changes: 3 additions & 0 deletions examples/plugin/python_plugin/rng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def get_random_number():
# verified by the roll of a fair die to be random
return 4
Loading