Skip to content

Commit

Permalink
Bump pyo3 to 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays committed Dec 16, 2021
1 parent f694477 commit 3a26428
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ jobs:
latest=$(git tag -l | tail -1)
cargo_v=$(grep -m 1 -oP 'version = "(.*)"' Cargo.toml | sed -rn 's/.*"(.*)"/v\1/p')
pyproject_v=$(grep -m 1 -oP 'version = "(.*)"' pyproject.toml | sed -rn 's/.*"(.*)"/v\1/p')
setup_v=$(grep -m 1 -oP 'version="(.*)"' setup.py | sed -rn 's/.*"(.*)"/v\1/p')
if [ ! $latest = $cargo_v ]; then
echo "Latest tag doesnt match Cargo.toml version - failing build."
exit 1
elif [ ! $latest = $pyproject_v ]; then
echo "Latest tag doesnt match pyproject.toml version - failing build."
exit 1
elif [ ! $latest = $setup_v ]; then
echo "Latest tag doesnt match setup.py version - failing build."
exit 1
fi
echo "Tags match: $latest"
exit 0
build:
Expand Down Expand Up @@ -91,7 +88,7 @@ jobs:
rustup default stable &&
rustup show
CIBW_BEFORE_BUILD_LINUX: >
pip install -U setuptools-rust &&
python -m pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y &&
rustup show
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "piston_rspy"
description = "Python bindings for piston_rs."
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Jonxslays"]
readme = "README.md"
Expand All @@ -17,7 +17,7 @@ name = "piston_rspy"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.14", features = ["extension-module"] }
pyo3-asyncio = { version = "0.14", features = ["tokio-runtime"] }
pyo3 = { version = "0.15", features = ["extension-module"] }
pyo3-asyncio = { version = "0.15", features = ["tokio-runtime"] }
tokio = { version = "1" }
piston_rs = "^0.4.0"
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[project]
name = "piston_rspy"
version = "0.3.0"
version = "0.3.1"
description = "Python bindings for piston_rs."
readme = "README.md"
documentation = "https://jonxslays.github.io/piston_rspy/piston_rspy/"
author = "Jonxslays"
documentation = "https://jonxslays.github.io/piston_rspy/piston_rspy"
issue-tracker = "https://github.com/Jonxslays/piston_rspy/issues"
repository = "https://github.com/Jonxslays/piston_rspy"
url = "https://github.com/Jonxslays/piston_rspy"
requires-python = ">=3.7,<3.11"
Expand Down
33 changes: 25 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import annotations

import typing

from setuptools import setup
from setuptools_rust import Binding, RustExtension, Strip # type: ignore

Expand All @@ -7,19 +11,32 @@
with open("README.md") as r:
long_description = r.read()

with open("pyproject.toml") as f:
meta: dict[str, typing.Any] = {}

for line in f.readlines():
if line.startswith("\n"):
break

if line.startswith("[project]"):
continue

k, v = line.split(" = ")
meta[k] = v.strip().replace("\"", "")

setup(
name="piston_rspy",
version="0.3.0",
description="Python bindings for piston_rs.",
author="Jonxslays",
name=meta["name"],
version=meta["version"],
description=meta["description"],
author=meta["author"],
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
url="https://github.com/Jonxslays/piston_rspy",
url=meta["url"],
project_urls={
"Documentation": "https://jonxslays.github.io/piston_rspy/piston_rspy",
"Source": "https://github.com/Jonxslays/piston_rspy",
"Bug Tracker": "https://github.com/Jonxslays/piston_rspy/issues",
"Documentation":meta["documentation"],
"Source": meta["repository"],
"Bug Tracker": meta["issue-tracker"],
},
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
34 changes: 16 additions & 18 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use pyo3::prelude::*;
use pyo3::types::PyList;
use pyo3::PyObjectProtocol;
use std::collections::HashMap;

Expand Down Expand Up @@ -121,22 +120,23 @@ impl Client {
fn fetch_runtimes<'a>(&self, py: Python<'a>) -> PyResult<&'a PyAny> {
let client = self.inner.clone();

pyo3_asyncio::tokio::future_into_py(py, async move {
match client.fetch_runtimes().await {
Ok(runtimes) => Ok(Python::with_gil(|py| {
PyList::new(
py,
pyo3_asyncio::tokio::future_into_py_with_locals::<_, Vec<Runtime>>(
py,
pyo3_asyncio::tokio::get_current_locals(py)?,
async move {
match client.fetch_runtimes().await {
Ok(runtimes) => Ok(Python::with_gil(|_| {
runtimes
.iter()
.map(|r| Runtime::from_runtime(r.to_owned()).into_py(py)),
)
.into()
})),
Err(e) => Err(Python::with_gil(|_| {
pyo3::exceptions::PyRuntimeError::new_err(format!("{:?}", e))
})),
}
})
.map(|r| Runtime::from_runtime(r.to_owned()))
.collect()
})),
Err(e) => Err(Python::with_gil(|_| {
pyo3::exceptions::PyRuntimeError::new_err(format!("{:?}", e))
})),
}
},
)
}

/// **async**: Executes code using a given executor. This is an http request.
Expand All @@ -160,9 +160,7 @@ impl Client {

pyo3_asyncio::tokio::future_into_py(py, async move {
match client.execute(&exec).await {
Ok(response) => Ok(Python::with_gil(|py| {
ExecResponse::from_response(response).into_py(py)
})),
Ok(response) => Ok(Python::with_gil(|_| ExecResponse::from_response(response))),
Err(e) => Err(Python::with_gil(|_| {
pyo3::exceptions::PyRuntimeError::new_err(format!("{:?}", e))
})),
Expand Down

0 comments on commit 3a26428

Please sign in to comment.