Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jan 25, 2024
1 parent 8293a4c commit d6371ce
Show file tree
Hide file tree
Showing 16 changed files with 667 additions and 392 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.*.swo
/dist/
/target/
__pycache__/
98 changes: 98 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ name = "etcd_client"
crate-type = ["cdylib"]

[dependencies]
async-recursion = "1.0.5"
etcd-client = "0.10"
pyo3 = { version = "0.18", features = ["extension-module"] }
pyo3 = { version = "0.18", features = ["extension-module", "multiple-pymethods"] }
pyo3-asyncio = { version = "0.18", features = ["tokio-runtime"] }
serde_json = "1.0.111"
tokio = { version = "1", features = ["sync"] }
tokio-stream = "0.1"
url = "2.5.0"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ install:
maturin build
pip install .

test:
python -m pytest
etcd-clear:
etcdctl del "" --from-key=true

fmt:
cargo fmt
Expand Down
4 changes: 4 additions & 0 deletions etcd_client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Communicator:
""" """
def put(self, key: str, value: str) -> None:
""" """
def put_prefix(self, key: str, value: dict) -> None:
""" """
def replace(self, key: str, initial_value: str, new_value: str) -> bool:
""" """
def watch(self, key: str) -> "Watch":
""" """
def watch_prefix(self, key: str) -> "Watch":
Expand Down
3 changes: 0 additions & 3 deletions manual-test.py

This file was deleted.

42 changes: 42 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use etcd_client::Client as RustClient;
use pyo3::prelude::*;
use pyo3::types::PyTuple;
use pyo3_asyncio::tokio::future_into_py;
use std::sync::Arc;
use tokio::sync::Mutex;

use crate::communicator::Communicator;
use crate::error::Error;

#[pyclass]
#[derive(Clone)]
pub struct Client {
endpoints: Vec<String>,
}

#[pymethods]
impl Client {
#[new]
fn new(endpoints: Vec<String>) -> Self {
Self { endpoints }
}

fn connect(&self) -> Self {
self.clone()
}

fn __aenter__<'a>(&'a self, py: Python<'a>) -> PyResult<&'a PyAny> {
let endpoints = self.endpoints.clone();
future_into_py(py, async move {
let result = RustClient::connect(endpoints, None).await;
result
.map(|client| Communicator(Arc::new(Mutex::new(client))))
.map_err(|e| Error(e).into())
})
}

#[pyo3(signature = (*_args))]
fn __aexit__<'a>(&'a self, py: Python<'a>, _args: &PyTuple) -> PyResult<&'a PyAny> {
future_into_py(py, async move { Ok(()) })
}
}
Loading

0 comments on commit d6371ce

Please sign in to comment.