Skip to content

Commit 7c99d67

Browse files
authored
Update pyo3 and pyo3-async-runtimes (#64)
1 parent 0a8e8c8 commit 7c99d67

File tree

13 files changed

+81
-64
lines changed

13 files changed

+81
-64
lines changed

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ http-rewriter = { git = "https://github.com/platformatic/http-rewriter" }
3333
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
3434
napi = { version = "3", default-features = false, features = ["napi4", "tokio_rt", "async"], optional = true }
3535
napi-derive = { version = "3", optional = true }
36-
pyo3 = { version = "0.26.0", features = ["experimental-async"] }
37-
pyo3-async-runtimes = { version = "0.26.0", features = ["tokio-runtime"] }
36+
pyo3 = { version = "0.27.2", features = ["experimental-async"] }
37+
pyo3-async-runtimes = { version = "0.27.0", features = ["tokio-runtime"] }
3838
thiserror = "2.0.12"
3939
tokio = { version = "1.45.1", features = ["full"] }
4040
libc = "0.2"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"version": "napi version"
4141
},
4242
"optionalDependencies": {
43-
"@platformatic/python-node-darwin-arm64": "^0.1.4",
44-
"@platformatic/python-node-linux-x64-gnu": "^0.1.4"
43+
"@platformatic/python-node-darwin-arm64": "^2.0.0",
44+
"@platformatic/python-node-linux-x64-gnu": "^2.0.0"
4545
}
4646
}

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/update-version.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ import { readFile, writeFile } from 'fs/promises'
33
const version = process.argv[2].replace(/^v/, '')
44
const packageJson = JSON.parse(await readFile('package.json', 'utf8'))
55
packageJson.version = version
6+
// Update platform-specific deps to match release version
7+
for (const dep of Object.keys(packageJson.optionalDependencies)) {
8+
if (dep.startsWith(packageJson.name)) {
9+
packageJson.optionalDependencies[dep] = `^${version}`
10+
}
11+
}
612
await writeFile('package.json', JSON.stringify(packageJson, null, 2))

src/asgi/http.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use http_handler::{Request, RequestExt, Version};
2+
use pyo3::Borrowed;
23
use pyo3::exceptions::PyValueError;
34
use pyo3::prelude::*;
45
use pyo3::types::{PyAny, PyDict};
@@ -295,9 +296,11 @@ pub enum HttpSendMessage {
295296
},
296297
}
297298

298-
impl<'py> FromPyObject<'py> for HttpSendMessage {
299-
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
300-
let dict = ob.downcast::<PyDict>()?;
299+
impl<'a, 'py> FromPyObject<'a, 'py> for HttpSendMessage {
300+
type Error = PyErr;
301+
302+
fn extract(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
303+
let dict = ob.cast::<PyDict>()?;
301304
let message_type = dict
302305
.get_item("type")?
303306
.ok_or_else(|| PyValueError::new_err("Missing 'type' key in HTTP send message dictionary"))?;
@@ -318,22 +321,22 @@ impl<'py> FromPyObject<'py> for HttpSendMessage {
318321

319322
// Convert headers from list of lists to vec of tuples
320323
let mut headers: Vec<(String, String)> = Vec::new();
321-
if let Ok(headers_list) = headers_py.downcast::<pyo3::types::PyList>() {
324+
if let Ok(headers_list) = headers_py.cast::<pyo3::types::PyList>() {
322325
for item in headers_list.iter() {
323-
if let Ok(header_pair) = item.downcast::<pyo3::types::PyList>()
326+
if let Ok(header_pair) = item.cast::<pyo3::types::PyList>()
324327
&& header_pair.len() == 2
325328
{
326329
let name = header_pair.get_item(0)?;
327330
let value = header_pair.get_item(1)?;
328331

329332
// Convert bytes to string
330-
let name_str = if let Ok(bytes) = name.downcast::<pyo3::types::PyBytes>() {
333+
let name_str = if let Ok(bytes) = name.cast::<pyo3::types::PyBytes>() {
331334
String::from_utf8_lossy(bytes.as_bytes()).to_string()
332335
} else {
333336
name.extract::<String>()?
334337
};
335338

336-
let value_str = if let Ok(bytes) = value.downcast::<pyo3::types::PyBytes>() {
339+
let value_str = if let Ok(bytes) = value.cast::<pyo3::types::PyBytes>() {
337340
String::from_utf8_lossy(bytes.as_bytes()).to_string()
338341
} else {
339342
value.extract::<String>()?

src/asgi/http_method.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::convert::Infallible;
22
use std::str::FromStr;
33

4+
use pyo3::Borrowed;
45
use pyo3::exceptions::PyValueError;
56
use pyo3::prelude::*;
67
use pyo3::types::PyString;
@@ -20,8 +21,10 @@ pub enum HttpMethod {
2021
Connect,
2122
}
2223

23-
impl<'py> FromPyObject<'py> for HttpMethod {
24-
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
24+
impl<'a, 'py> FromPyObject<'a, 'py> for HttpMethod {
25+
type Error = PyErr;
26+
27+
fn extract(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
2528
let method: String = ob.extract()?;
2629
method
2730
.to_uppercase()

src/asgi/http_version.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::convert::Infallible;
22
use std::str::FromStr;
33

4+
use pyo3::Borrowed;
45
use pyo3::exceptions::PyValueError;
56
use pyo3::prelude::*;
67
use pyo3::types::PyString;
@@ -14,8 +15,10 @@ pub enum HttpVersion {
1415
V2_0,
1516
}
1617

17-
impl<'py> FromPyObject<'py> for HttpVersion {
18-
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
18+
impl<'a, 'py> FromPyObject<'a, 'py> for HttpVersion {
19+
type Error = PyErr;
20+
21+
fn extract(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
1922
let version: String = ob.extract()?;
2023
match version.as_str() {
2124
"1" | "1.0" => Ok(HttpVersion::V1_0),

src/asgi/info.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use pyo3::Borrowed;
12
use pyo3::exceptions::PyValueError;
23
use pyo3::prelude::*;
34
use pyo3::types::PyDict;
@@ -35,9 +36,11 @@ impl<'py> IntoPyObject<'py> for AsgiInfo {
3536
}
3637
}
3738

38-
impl<'py> FromPyObject<'py> for AsgiInfo {
39-
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
40-
let dict = ob.downcast::<PyDict>()?;
39+
impl<'a, 'py> FromPyObject<'a, 'py> for AsgiInfo {
40+
type Error = PyErr;
41+
42+
fn extract(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
43+
let dict = ob.cast::<PyDict>()?;
4144
let version: String = dict
4245
.get_item("version")?
4346
.ok_or_else(|| PyValueError::new_err("Missing 'version' key in ASGI info dictionary"))?

src/asgi/lifespan.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use pyo3::Borrowed;
12
use pyo3::exceptions::PyValueError;
23
use pyo3::prelude::*;
34
use pyo3::types::PyDict;
@@ -67,9 +68,11 @@ pub enum LifespanSendMessage {
6768
}
6869

6970
// Only ever converted from Python to Rust.
70-
impl<'py> FromPyObject<'py> for LifespanSendMessage {
71-
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
72-
let dict = ob.downcast::<PyDict>()?;
71+
impl<'a, 'py> FromPyObject<'a, 'py> for LifespanSendMessage {
72+
type Error = PyErr;
73+
74+
fn extract(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
75+
let dict = ob.cast::<PyDict>()?;
7376
let message_type = dict.get_item("type")?.ok_or_else(|| {
7477
PyValueError::new_err("Missing 'type' key in Lifespan send message dictionary")
7578
})?;

0 commit comments

Comments
 (0)