Skip to content

Commit 4a79fc6

Browse files
author
mityax
committed
update: update default pyo3 version from 0.18.3 to 0.21.2
1 parent 28f15e7 commit 4a79fc6

File tree

10 files changed

+20
-15
lines changed

10 files changed

+20
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# rustimport - Import Rust directly from Python!
22

33
<p align=center>
4-
<a target="_blank" href="https://www.python.org/downloads/" title="Python version"><img src="https://img.shields.io/badge/python-%3E=_3.6-green.svg"></a>
4+
<a target="_blank" href="https://www.python.org/downloads/" title="Python version"><img src="https://img.shields.io/badge/python-%3E=_3.8-green.svg"></a>
55
<a target="_blank" href="https://pypi.org/project/rustimport/" title="PyPI version"><img src="https://img.shields.io/pypi/v/rustimport?logo=pypi"></a>
66
<a target="_blank" href="LICENSE" title="License: MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg"></a></a>
77
</p>
@@ -93,7 +93,7 @@ features = [ "extension-module",]
9393
3. It generated a code block exporting your method and appended it to the end of your file:
9494
```rust
9595
#[pymodule]
96-
fn somecode(_py: Python, m: &PyModule) -> PyResult<()> {
96+
fn somecode(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
9797
m.add_function(wrap_pyfunction!(square, m)?)?;
9898
Ok(())
9999
}

examples/singlefile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//: # "cdylib" is necessary to produce a shared library for Python to import from.
2626
//:
2727
//: [dependencies]
28-
//: pyo3 = { version = "0.16.2", features = ["extension-module"] }
28+
//: pyo3 = { version = "0.21.2", features = ["extension-module"] }
2929

3030
use pyo3::prelude::*;
3131

@@ -40,7 +40,7 @@ fn sum_as_string(a: usize, b: usize) -> String {
4040
// The name of this function must match the `lib.name` setting in the cargo manifest,
4141
// else Python will not be able to import the module.
4242
#[pymodule]
43-
fn singlefile(_py: Python, m: &PyModule) -> PyResult<()> {
43+
fn singlefile(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
4444
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
4545
Ok(())
4646
}

examples/singlefile_manifest_only_templating.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn try_divide(a: usize, b: usize) -> PyResult<usize> {
1818

1919
/// A Python module implemented in Rust.
2020
#[pymodule]
21-
fn singlefile_manifest_only_templating(_py: Python, m: &PyModule) -> PyResult<()> {
21+
fn singlefile_manifest_only_templating(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
2222
m.add_function(wrap_pyfunction!(try_divide, m)?)?;
2323
Ok(())
2424
}

examples/string_sum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ name = "string_sum"
1616
crate-type = ["cdylib"]
1717

1818
[dependencies]
19-
pyo3 = { version = "0.16.2", features = ["extension-module"] }
19+
pyo3 = { version = "0.21.2", features = ["extension-module"] }

examples/string_sum/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
1010
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
1111
/// import the module.
1212
#[pymodule]
13-
fn string_sum(_py: Python, m: &PyModule) -> PyResult<()> {
13+
fn string_sum(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
1414
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
1515
Ok(())
1616
}

examples/test_crate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ name = "test_crate"
2525
crate-type = ["cdylib"]
2626

2727
[dependencies]
28-
pyo3 = { version = "0.16.2", features = ["extension-module"] }
28+
pyo3 = { version = "0.21.2", features = ["extension-module"] }

examples/test_crate/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn say_hello() -> String {
1212
// #[pyfunction] and all structs annotated with #[pyclass].
1313
//
1414
//#[pymodule]
15-
//fn test_crate(_py: Python, m: &PyModule) -> PyResult<()> {
15+
//fn test_crate(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
1616
// m.add_function(wrap_pyfunction!(say_hello, m)?)?;
1717
// Ok(())
1818
//}

examples/test_workspace/crate_c/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ name = "crate_c"
2525
crate-type = ["cdylib"]
2626

2727
[dependencies]
28-
pyo3 = { version = "0.18.3", features = ["extension-module"] }
28+
pyo3 = { version = "0.21.2", features = ["extension-module"] }
2929
crate_b = { path = "../crate_b" }

rustimport/__main__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import List
77

88
from rustimport import build_all, build_filepath, settings
9+
from rustimport.pre_processing import PyO3Template
910

1011
rust_lib_template = """// rustimport:pyo3
1112
@@ -21,7 +22,7 @@
2122
// #[pyfunction] and all structs annotated with #[pyclass].
2223
//
2324
//#[pymodule]
24-
//fn {{EXTENSION_NAME}}(_py: Python, m: &PyModule) -> PyResult<()> {
25+
//fn {{EXTENSION_NAME}}(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
2526
// m.add_function(wrap_pyfunction!(say_hello, m)?)?;
2627
// Ok(())
2728
//}
@@ -54,7 +55,7 @@
5455
crate-type = ["cdylib"]
5556
5657
[dependencies]
57-
pyo3 = { version = "0.18.3", features = ["extension-module"] }
58+
pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
5859
"""
5960

6061

@@ -75,7 +76,9 @@ def create_extension(name: str, cwd: str = '.'):
7576
with open(os.path.join(src_dir, 'lib.rs'), 'w+') as f:
7677
f.write(rust_lib_template.replace('{{EXTENSION_NAME}}', name))
7778
with open(os.path.join(path, 'Cargo.toml'), 'w+') as f:
78-
f.write(cargo_toml_template.replace('{{EXTENSION_NAME}}', name))
79+
f.write(cargo_toml_template
80+
.replace('{{EXTENSION_NAME}}', name)
81+
.replace('{{PYO3_VERSION}}', PyO3Template.PYO3_VERSION))
7982
with open(os.path.join(path, '.rustimport'), 'w+') as f:
8083
f.write("This is a marker-file to make this crate importable by rustimport.")
8184

rustimport/pre_processing/pyo3_template.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class PyO3Template(Template):
9+
PYO3_VERSION = "0.21.2"
10+
911
def process(self) -> Template.TemplatingResult:
1012
return Template.TemplatingResult(
1113
cargo_manifest=self.__generate_manifest(),
@@ -25,7 +27,7 @@ def __generate_manifest(self) -> bytes:
2527
'crate-type': ['cdylib'],
2628
},
2729
'dependencies': {
28-
'pyo3': {'version': '0.18.3', 'features': ['extension-module']}
30+
'pyo3': {'version': PyO3Template.PYO3_VERSION, 'features': ['extension-module']}
2931
}
3032
})
3133

@@ -43,7 +45,7 @@ def __generate_pymodule(self) -> bytes:
4345

4446
res = [
4547
b'#[pymodule]',
46-
b'fn ' + self.lib_name.encode() + b'(_py: Python, m: &PyModule) -> PyResult<()> {',
48+
b'fn ' + self.lib_name.encode() + b"(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {",
4749
*[
4850
b' m.add_function(wrap_pyfunction!(' + func.group(1) + b', m)?)?;'
4951
for func in functions

0 commit comments

Comments
 (0)