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 b76b62e commit 8293a4c
Show file tree
Hide file tree
Showing 14 changed files with 2,324 additions and 13 deletions.
1,401 changes: 1,401 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name = "etcd-client-py"
version = "0.1.1"
edition = "2021"
authors = ["Lablup Inc."]
readme = "./README.md"

[lib]
name = "etcd_client"
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
build:
maturin build

install:
maturin build
pip install .

test:
python -m pytest

fmt:
cargo fmt

lint:
cargo clippy
Binary file added __pycache__/etcd_client_py.cpython-311.pyc
Binary file not shown.
53 changes: 53 additions & 0 deletions etcd_client.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Type hints for Native Rust Extension
"""

from typing import Any, Final, Optional

class Client:
""" """

def __init__(self, endpoints: list[str]) -> None:
""" """
def connect(self) -> "Client":
""" """
def __aenter__(self) -> "Communicator":
""" """

class Watch:
""" """

class Communicator:
def get(self, key: str) -> str:
""" """
def get_prefix(self, key: str) -> dict:
""" """
def keys_prefix(self, key: str) -> list[str]:
""" """
def delete(self, key: str) -> None:
""" """
def delete_prefix(self, key: str) -> None:
""" """
def put(self, key: str, value: str) -> None:
""" """
def watch(self, key: str) -> "Watch":
""" """
def watch_prefix(self, key: str) -> "Watch":
""" """

class Event:
""" """

def __init__(
key: str, value: str, event: "EventType", prev_value: Optional[str]
) -> None: ...

class EventType:
""" """

PUT: Final[Any]
"""
"""
DELETE: Final[Any]
"""
"""
3 changes: 3 additions & 0 deletions manual-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from etcd_client import Client

etcd = Client(["http://localhost:2379"])
Empty file added py.typed
Empty file.
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
python_files = */tests/*.py
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
maturin==1.3.2
pytest==7.3.1
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::collections::HashMap;
use std::sync::Arc;

use etcd_client::Client as RustClient;
use etcd_client::Error as RustError;
use etcd_client::Event as RustEvent;
use etcd_client::EventType as RustEventType;
use etcd_client::WatchStream as RustStream;
use etcd_client::{DeleteOptions, GetOptions, WatchOptions};
use ::etcd_client::Client as RustClient;
use ::etcd_client::Error as RustError;
use ::etcd_client::Event as RustEvent;
use ::etcd_client::EventType as RustEventType;
use ::etcd_client::WatchStream as RustStream;
use ::etcd_client::{DeleteOptions, GetOptions, WatchOptions};
use pyo3::create_exception;
use pyo3::exceptions::{PyException, PyStopAsyncIteration};
use pyo3::prelude::*;
Expand All @@ -28,7 +28,7 @@ impl From<Error> for PyErr {

#[pyclass]
#[derive(PartialEq, Eq, Clone)]
struct EventType(RustEventType);
pub struct EventType(RustEventType);

#[pymethods]
impl EventType {
Expand All @@ -41,7 +41,7 @@ impl EventType {

#[pyclass]
#[derive(PartialEq, Eq, Clone)]
struct Event {
pub struct Event {
key: String,
value: String,
prev_value: Option<String>,
Expand Down Expand Up @@ -78,7 +78,7 @@ impl From<RustEvent> for Event {

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

Expand Down Expand Up @@ -114,7 +114,7 @@ impl Client {
}

#[pyclass]
struct Communicator(Arc<Mutex<RustClient>>);
pub struct Communicator(Arc<Mutex<RustClient>>);

#[pymethods]
impl Communicator {
Expand Down Expand Up @@ -266,7 +266,7 @@ impl Stream {

#[pyclass]
#[derive(Clone)]
struct Watch {
pub struct Watch {
client: Arc<Mutex<RustClient>>,
key: String,
options: Option<WatchOptions>,
Expand Down Expand Up @@ -325,10 +325,11 @@ impl Watch {
}

#[pymodule]
#[pyo3(name = "etcd_client")]
fn init(_py: Python<'_>, module: &PyModule) -> PyResult<()> {
fn etcd_client(_py: Python<'_>, module: &PyModule) -> PyResult<()> {
module.add_class::<Client>()?;
module.add_class::<Event>()?;
module.add_class::<EventType>()?;
module.add_class::<Communicator>()?;
module.add_class::<Watch>()?;
Ok(())
}
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 8293a4c

Please sign in to comment.