fix: glue for js and py

This commit is contained in:
əlemi 2024-09-11 18:07:55 +02:00
parent 94e52a86f4
commit 2f68006d07
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 67 additions and 21 deletions

50
Cargo.lock generated
View file

@ -242,6 +242,7 @@ dependencies = [
"napi-derive", "napi-derive",
"pyo3", "pyo3",
"pyo3-build-config 0.19.2", "pyo3-build-config 0.19.2",
"serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
@ -388,6 +389,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "erased-serde"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24e2389d65ab4fab27dc2a5de7b191e1f6617d1f1c8855c0dc569c94a4cbb18d"
dependencies = [
"serde",
"typeid",
]
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.9" version = "0.3.9"
@ -862,11 +873,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a52f529509c236114a5cf5bb3c0c06ff0695ad45d718256930ec2416edf3817" checksum = "5a52f529509c236114a5cf5bb3c0c06ff0695ad45d718256930ec2416edf3817"
dependencies = [ dependencies = [
"bstr", "bstr",
"erased-serde",
"mlua-sys", "mlua-sys",
"mlua_derive", "mlua_derive",
"num-traits", "num-traits",
"parking_lot", "parking_lot",
"rustc-hash", "rustc-hash",
"serde",
"serde-value",
] ]
[[package]] [[package]]
@ -1020,6 +1034,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "ordered-float"
version = "2.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "overload" name = "overload"
version = "0.1.1" version = "0.1.1"
@ -1521,18 +1544,28 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.205" version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde-value"
version = "1.0.205" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c"
dependencies = [
"ordered-float",
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1939,6 +1972,12 @@ dependencies = [
"static_assertions", "static_assertions",
] ]
[[package]]
name = "typeid"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e13db2e0ccd5e14a544e8a246ba2312cd25223f616442d7f2cb0e3db614236e"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.12"
@ -1970,6 +2009,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"serde",
] ]
[[package]] [[package]]

View file

@ -7,10 +7,19 @@ class Driver:
""" """
def stop(self) -> None: ... def stop(self) -> None: ...
class Config:
"""
Configuration data structure for codemp clients
"""
username: str
password: str
host: Optional[str]
port: Optional[int]
tls: Optional[bool]
def init() -> Driver: ... def init() -> Driver: ...
def set_logger(logger_cb: Callable[[str], None], debug: bool) -> bool: ... def set_logger(logger_cb: Callable[[str], None], debug: bool) -> bool: ...
def connect(host: str, username: str, password: str) -> Promise[Client]: ... def connect(config: Config) -> Promise[Client]: ...
class Promise[T]: class Promise[T]:
""" """

View file

@ -3,11 +3,8 @@ use crate::{Client, Workspace};
#[napi] #[napi]
/// connect to codemp servers and return a client session /// connect to codemp servers and return a client session
pub async fn connect(addr: Option<String>, username: String, password: String) -> napi::Result<crate::Client>{ pub async fn connect(config: crate::api::Config) -> napi::Result<crate::Client>{
let client = crate::Client::connect(addr.as_deref().unwrap_or("http://code.mp:50053"), username, password) Ok(crate::Client::connect(config).await?)
.await?;
Ok(client)
} }
#[napi] #[napi]

View file

@ -5,14 +5,14 @@ use pyo3::prelude::*;
#[pymethods] #[pymethods]
impl Client { impl Client {
#[new] // #[new]
fn __new__( // fn __new__(
host: String, // host: String,
username: String, // username: String,
password: String, // password: String,
) -> crate::errors::ConnectionResult<Self> { // ) -> crate::errors::ConnectionResult<Self> {
super::tokio().block_on(Client::connect(host, username, password)) // super::tokio().block_on(Client::connect(host, username, password))
} // }
// #[pyo3(name = "join_workspace")] // #[pyo3(name = "join_workspace")]
// async fn pyjoin_workspace(&self, workspace: String) -> JoinHandle<crate::Result<Workspace>> { // async fn pyjoin_workspace(&self, workspace: String) -> JoinHandle<crate::Result<Workspace>> {

View file

@ -150,8 +150,8 @@ fn init() -> PyResult<Driver> {
} }
#[pyfunction] #[pyfunction]
fn connect(host: String, username: String, password: String) -> PyResult<Promise> { fn connect(config: crate::api::Config) -> PyResult<Promise> {
a_sync!(Client::connect(host, username, password).await) a_sync!(Client::connect(config).await)
} }
#[pyfunction] #[pyfunction]