diff --git a/Cargo.toml b/Cargo.toml index 1855224..efbc275 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ napi = { version = "2.16", features = ["full"], optional = true } napi-derive = { version="2.16", optional = true} # glue (python) -pyo3 = { version = "0.22", features = ["extension-module", "experimental-async"], optional = true} +pyo3 = { version = "0.22", features = ["extension-module", "abi3-py38"], optional = true} # extra async-trait = { version = "0.1", optional = true } diff --git a/dist/py/pyproject.toml b/dist/py/pyproject.toml index 98a8bd4..f059255 100644 --- a/dist/py/pyproject.toml +++ b/dist/py/pyproject.toml @@ -1,18 +1,18 @@ [project] name = "codemp" -version = "0.0.1" +version = "0.0.5" description = "code multiplexer" -requires-python = ">=3.8" +requires-python = ">= 3.8" license = "GPL-3.0-only" keywords = ["codemp", "cooperative", "rust", "python"] authors = [ - { name = "Camillo Schenone", email = "cschen@codemp.dev" }, + { name = "cschen", email = "cschen@codemp.dev" }, { name = "alemi", email = "me@alemi.dev" }, { name = "zaaarf", email = "me@zaaarf.foo" }, { name = "frelodev", email = "frelodev@gmail.com" }, ] maintainers = [ - { name = "Camillo Schenone", email = "cschen@codemp.dev" }, + { name = "cschen", email = "cschen@codemp.dev" }, ] classifiers = [ "Programming Language :: Python" diff --git a/src/ffi/python/controllers.rs b/src/ffi/python/controllers.rs index 08c09ce..580cb02 100644 --- a/src/ffi/python/controllers.rs +++ b/src/ffi/python/controllers.rs @@ -3,8 +3,8 @@ use crate::api::Cursor; use crate::api::TextChange; use crate::buffer::Controller as BufferController; use crate::cursor::Controller as CursorController; +use pyo3::exceptions::PyValueError; use pyo3::prelude::*; -use pyo3::types::PyFunction; use super::Promise; use crate::a_sync_allow_threads; @@ -49,15 +49,18 @@ impl CursorController { } #[pyo3(name = "callback")] - fn pycallback(&self, py: Python, cb: Py) { - py.allow_threads(move || { - self.callback(move |ctl| { - Python::with_gil(|py| { - // TODO what to do with this error? - let _ = cb.call1(py, (ctl,)); - }) + fn pycallback(&self, py: Python, cb: PyObject) -> PyResult<()> { + if !cb.bind_borrowed(py).is_callable() { + return Err(PyValueError::new_err("The object passed must be callable.")); + } + + self.callback(move |ctl| { + Python::with_gil(|py| { + // TODO what to do with this error? + let _ = cb.call1(py, (ctl,)); }) - }) + }); + Ok(()) } #[pyo3(name = "clear_callback")] @@ -116,15 +119,18 @@ impl BufferController { } #[pyo3(name = "callback")] - fn pycallback(&self, py: Python, cb: Py) { - py.allow_threads(move || { - self.callback(move |ctl| { - Python::with_gil(|py| { - // TODO what to do with this error? - let _ = cb.call1(py, (ctl,)); - }) + fn pycallback(&self, py: Python, cb: PyObject) -> PyResult<()> { + if !cb.bind_borrowed(py).is_callable() { + return Err(PyValueError::new_err("The object passed must be callable.")); + } + + self.callback(move |ctl| { + Python::with_gil(|py| { + // TODO what to do with this error? + let _ = cb.call1(py, (ctl,)); }) - }) + }); + Ok(()) } #[pyo3(name = "clear_callback")] diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 088b556..9833663 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -13,11 +13,8 @@ use crate::{ Client, Workspace, }; +use pyo3::exceptions::{PyConnectionError, PyRuntimeError, PySystemError}; use pyo3::prelude::*; -use pyo3::{ - exceptions::{PyConnectionError, PyRuntimeError, PySystemError}, - types::PyFunction, -}; use std::sync::OnceLock; use tokio::sync::{mpsc, oneshot}; @@ -158,7 +155,10 @@ fn connect(host: String, username: String, password: String) -> PyResult, debug: bool) -> bool { +fn set_logger(py: Python, logging_cb: PyObject, debug: bool) -> bool { + if !logging_cb.bind_borrowed(py).is_callable() { + return false; + } let (tx, mut rx) = mpsc::unbounded_channel(); let level = if debug { tracing::Level::DEBUG