diff --git a/dist/py/src/codemp/codemp.pyi b/dist/py/src/codemp/codemp.pyi index dae26f7..d7eebc8 100644 --- a/dist/py/src/codemp/codemp.pyi +++ b/dist/py/src/codemp/codemp.pyi @@ -7,6 +7,7 @@ class Driver: """ def stop(self) -> None: ... +def get_default_config() -> Config: ... class Config: """ Configuration data structure for codemp clients diff --git a/src/api/config.rs b/src/api/config.rs index 3412512..ad7849e 100644 --- a/src/api/config.rs +++ b/src/api/config.rs @@ -1,7 +1,6 @@ //! # Config //! Data structure defining clients configuration - /// Configuration struct for `codemp` client /// /// username and password are required fields, while everything else is optional @@ -11,7 +10,7 @@ /// http{tls?'s':''}://{host}:{port} #[derive(Clone, Debug)] #[cfg_attr(feature = "js", napi_derive::napi(object))] -#[cfg_attr(feature = "py", pyo3::pyclass(get_all))] +#[cfg_attr(feature = "python", pyo3::pyclass(get_all, set_all))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct Config { /// user identifier used to register, possibly your email @@ -29,7 +28,13 @@ pub struct Config { impl Config { /// construct a new Config object, with given username and password pub fn new(username: String, password: String) -> Self { - Self { username, password, host: None, port: None, tls: None } + Self { + username, + password, + host: None, + port: None, + tls: None, + } } #[inline] diff --git a/src/ffi/python/client.rs b/src/ffi/python/client.rs index f1ca3b5..ffeb3a6 100644 --- a/src/ffi/python/client.rs +++ b/src/ffi/python/client.rs @@ -14,18 +14,6 @@ impl Client { // super::tokio().block_on(Client::connect(host, username, password)) // } - // #[pyo3(name = "join_workspace")] - // async fn pyjoin_workspace(&self, workspace: String) -> JoinHandle> { - // tracing::info!("attempting to join the workspace {}", workspace); - - // let this = self.clone(); - // async { - // tokio() - // .spawn(async move { this.join_workspace(workspace).await }) - // .await - // } - // } - #[pyo3(name = "join_workspace")] fn pyjoin_workspace(&self, py: Python<'_>, workspace: String) -> PyResult { tracing::info!("attempting to join the workspace {}", workspace); diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 54ed174..496f159 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -146,8 +146,18 @@ fn init() -> PyResult { } #[pyfunction] -fn connect(config: crate::api::Config) -> PyResult { - a_sync!(Client::connect(config).await) +fn get_default_config() -> crate::api::Config { + let mut conf = crate::api::Config::new("".to_string(), "".to_string()); + conf.host = Some(conf.host().to_string()); + conf.port = Some(conf.port()); + conf.tls = Some(false); + conf +} + +#[pyfunction] +fn connect(py: Python, config: Py) -> PyResult { + let conf: crate::api::Config = config.extract(py)?; + a_sync!(Client::connect(conf).await) } #[pyfunction] @@ -218,6 +228,7 @@ impl IntoPy for crate::api::User { #[pymodule] fn codemp(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(init, m)?)?; + m.add_function(wrap_pyfunction!(get_default_config, m)?)?; m.add_function(wrap_pyfunction!(connect, m)?)?; m.add_function(wrap_pyfunction!(set_logger, m)?)?; m.add_class::()?;