Skip to content

Commit 2506a36

Browse files
committed
Update to PyO3 0.14 and bump versions.
1 parent b49a64b commit 2506a36

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "inline-python"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
authors = [
55
"Mara Bos <[email protected]>",
66
"Maarten de Vries <[email protected]>",
@@ -13,8 +13,8 @@ keywords = ["python", "inline", "embed", "macro"]
1313
autoexamples = false
1414

1515
[dependencies]
16-
inline-python-macros = { version = "0.5.0", path = "./macros" }
17-
pyo3 = { version = "0.11.0", default-features = false }
16+
inline-python-macros = { version = "=0.7.0", path = "./macros" }
17+
pyo3 = { version = "0.14.0", default-features = false, features = ["auto-initialize"] }
1818

1919
[workspace]
2020
members = ["examples", "ct-python"]

ct-python/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ct-python"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
authors = ["Mara Bos <[email protected]>"]
55
description = "Execute Python code at compile time to generate Rust code"
66
license = "BSD-2-Clause"
@@ -9,4 +9,4 @@ repository = "https://github.com/fusion-engineering/inline-python/tree/master/ct
99
keywords = ["python", "macro", "generate", "compile-time"]
1010

1111
[dependencies]
12-
inline-python-macros = { version = "0.5.1", path = "../macros" }
12+
inline-python-macros = { version = "=0.7.0", path = "../macros" }

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ path = "rust-fn.rs"
1717

1818
[dependencies]
1919
inline-python = { path = ".." }
20-
pyo3 = "0.11.0"
20+
pyo3 = "0.14.0"

macros/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "inline-python-macros"
3-
version = "0.5.3"
3+
version = "0.7.0"
44
authors = [
55
"Mara Bos <[email protected]>",
66
"Maarten de Vries <[email protected]>",
@@ -16,7 +16,7 @@ proc_macro = true
1616
[dependencies]
1717
proc-macro2 = { version = "1.0", features = ["span-locations"] }
1818
quote = "1.0"
19-
pyo3 = { version = "0.11.0", default-features = false }
19+
pyo3 = { version = "0.14.0", default-features = false, features = ["auto-initialize"] }
2020

2121
[target.'cfg(unix)'.dependencies]
2222
libc = "0.2.71"

macros/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use proc_macro::Span;
22
use proc_macro2::TokenStream;
33
use pyo3::type_object::PyTypeObject;
4-
use pyo3::{AsPyRef, PyAny, PyErr, PyResult, Python, ToPyObject};
4+
use pyo3::{PyAny, PyErr, PyResult, Python, ToPyObject};
55
use quote::{quote, quote_spanned};
66

77
/// Format a nice error message for a python compilation error.
88
pub fn compile_error_msg(py: Python, error: PyErr, tokens: TokenStream) -> TokenStream {
99
let value = error.to_object(py);
1010

1111
if value.is_none(py) {
12-
let error = format!("python: {}", error.ptype.as_ref(py).name());
12+
let error = format!("python: {}", error.ptype(py).name().unwrap());
1313
return quote!(compile_error! {#error});
1414
}
1515

16-
if error.matches(py, pyo3::exceptions::SyntaxError::type_object(py)) {
16+
if error.matches(py, pyo3::exceptions::PySyntaxError::type_object(py)) {
1717
let line: Option<usize> = value.getattr(py, "lineno").ok().and_then(|x| x.extract(py).ok());
1818
let msg: Option<String> = value.getattr(py, "msg").ok().and_then(|x| x.extract(py).ok());
1919
if let (Some(line), Some(msg)) = (line, msg) {
@@ -24,8 +24,8 @@ pub fn compile_error_msg(py: Python, error: PyErr, tokens: TokenStream) -> Token
2424
}
2525
}
2626

27-
if let Some(tb) = &error.ptraceback {
28-
if let Ok((file, line)) = get_traceback_info(tb.as_ref(py)) {
27+
if let Some(tb) = &error.ptraceback(py) {
28+
if let Ok((file, line)) = get_traceback_info(tb) {
2929
if file == Span::call_site().source_file().path().to_string_lossy() {
3030
if let Ok(msg) = value.as_ref(py).str() {
3131
if let Some(span) = span_for_line(tokens, line) {

macros/src/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ fn ensure_libpython_symbols_loaded(py: Python) -> PyResult<()> {
1515
// time with RTLD_GLOBAL enabled.
1616

1717
let sysconfig = py.import("sysconfig")?;
18-
let libdir: String = sysconfig.call1("get_config_var", ("LIBDIR",))?.extract()?;
19-
let so_name: String = sysconfig.call1("get_config_var", ("INSTSONAME",))?.extract()?;
18+
let libdir: String = sysconfig.getattr("get_config_var")?.call1(("LIBDIR",))?.extract()?;
19+
let so_name: String = sysconfig.getattr("get_config_var")?.call1(("INSTSONAME",))?.extract()?;
2020
let path = std::ffi::CString::new(format!("{}/{}", libdir, so_name)).unwrap();
2121
unsafe {
2222
libc::dlopen(path.as_ptr(), libc::RTLD_NOW | libc::RTLD_GLOBAL);
@@ -33,7 +33,7 @@ fn run_and_capture(py: Python, code: PyObject) -> PyResult<String> {
3333
let sys = py.import("sys")?;
3434
let io = py.import("io")?;
3535

36-
let stdout = io.call0("StringIO")?;
36+
let stdout = io.getattr("StringIO")?.call0()?;
3737
let original_stdout = sys.dict().get_item("stdout");
3838
sys.dict().set_item("stdout", stdout)?;
3939

src/context.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::run::run_python_code;
22
use crate::PythonBlock;
3-
use pyo3::{types::PyDict, AsPyRef, FromPyObject, Py, PyObject, PyResult, Python, ToPyObject};
3+
use pyo3::{
4+
types::{PyCFunction, PyDict},
5+
FromPyObject, Py, PyResult, Python, ToPyObject,
6+
};
47

58
/// An execution context for Python code.
69
///
@@ -151,17 +154,17 @@ impl Context {
151154
///
152155
/// This function temporarily acquires the GIL.
153156
/// If you already have the GIL, you can use [`Context::add_wrapped_with_gil`] instead.
154-
pub fn add_wrapped(&self, wrapper: &impl Fn(Python) -> PyObject) {
157+
pub fn add_wrapped(&self, wrapper: &impl Fn(Python) -> PyResult<&PyCFunction>) {
155158
self.add_wrapped_with_gil(Python::acquire_gil().python(), wrapper);
156159
}
157160

158161
/// Add a wrapped #[pyfunction] or #[pymodule] using its own `__name__`.
159162
///
160163
/// See [Context::add_wrapped].
161-
pub fn add_wrapped_with_gil<'p>(&self, py: Python<'p>, wrapper: &impl Fn(Python) -> PyObject) {
162-
let obj = wrapper(py);
163-
let name = obj.getattr(py, "__name__").expect("Missing __name__");
164-
self.set_with_gil(py, name.extract(py).unwrap(), obj)
164+
pub fn add_wrapped_with_gil<'p>(&self, py: Python<'p>, wrapper: &impl Fn(Python) -> PyResult<&PyCFunction>) {
165+
let obj = wrapper(py).unwrap();
166+
let name = obj.getattr("__name__").expect("Missing __name__");
167+
self.set_with_gil(py, name.extract().unwrap(), obj)
165168
}
166169

167170
/// Run Python code using this context.

0 commit comments

Comments
 (0)