fix(python): fixed the type hints, adapted glue to latest workspace, uniformed names in the glue

chore: forgot a file
This commit is contained in:
cschen 2024-08-09 09:14:27 +02:00
parent 53cd0068b5
commit 264dd319d3
4 changed files with 53 additions and 49 deletions

53
dist/py/codemp.pyi vendored
View file

@ -1,65 +1,66 @@
from typing import Tuple
def init_logger(debug: bool | None) -> PyLogger: ...
def codemp_init() -> Client: ...
class PyLogger:
async def message(self) -> str | None: ...
def __init__(self, debug) -> None: ...
async def listen(self) -> str | None: ...
class CodempTextChange:
start_incl: int
end_excl: int
class TextChange:
start: int
end: int
content: str
def is_deletion(self) -> bool: ...
def is_addition(self) -> bool: ...
def is_empty(self) -> bool: ...
def apply(self, txt: str) -> str: ...
def from_diff(self, before: str, after: str) -> CodempTextChange: ...
def from_diff(self, before: str, after: str) -> TextChange: ...
def index_to_rowcol(self, txt: str, index: int) -> Tuple[int, int]: ...
class CodempBufferController:
class BufferController:
def content(self) -> str: ...
def send(self, start: int, end: int, txt: str) -> None: ...
async def try_recv(self) -> CodempTextChange | None: ...
async def recv(self) -> CodempTextChange: ...
async def try_recv(self) -> TextChange | None: ...
async def recv(self) -> TextChange: ...
async def poll(self) -> None: ...
class CodempCursor:
class Cursor:
start: Tuple[int, int]
end: Tuple[int, int]
buffer: str
user: str # can be an empty string
class CodempCursorController:
class CursorController:
def send(self, path: str, start: Tuple[int, int], end: Tuple[int, int]) -> None: ...
def try_recv(self) -> CodempCursor | None: ...
async def recv(self) -> CodempCursor: ...
def try_recv(self) -> Cursor | None: ...
async def recv(self) -> Cursor: ...
async def poll(self) -> None: ...
def stop(self) -> bool: ...
class CodempWorkspace:
class Workspace:
async def create(self, path: str) -> None: ...
async def attach(self, path: str) -> CodempBufferController: ...
async def attach(self, path: str) -> BufferController: ...
def detach(self, path: str) -> bool: ...
async def fetch_buffers(self) -> None: ...
async def fetch_users(self) -> None: ...
async def list_buffer_users(self, path: str) -> list[str]: ...
async def delete(self, path: str) -> None: ...
def id(self) -> str: ...
def cursor(self) -> CodempCursorController: ...
def buffer_by_name(self, path: str) -> CodempBufferController: ...
def cursor(self) -> CursorController: ...
def buffer_by_name(self, path: str) -> BufferController | None: ...
def buffer_list(self) -> list[str]: ...
def filetree(self) -> list[str]: ...
class Client:
def __init__(self) -> None: ...
async def connect(self, host: str) -> None: ...
async def login(self, user: str, password: str, workspace: str | None) -> None: ...
async def join_workspace(self, workspace: str) -> CodempWorkspace: ...
async def get_workspace(self, id: str) -> CodempWorkspace: ...
async def user_id(self) -> str: ...
def __init__(self, host: str, username: str, password: str) -> None: ...
async def join_workspace(self, workspace: str) -> Workspace: ...
def leave_workspace(self, workspace: str) -> bool: ...
def get_workspace(self, id: str) -> Workspace: ...
def active_workspaces(self) -> list[str]: ...
def user_id(self) -> str: ...

View file

@ -1,7 +1,6 @@
use crate::workspace::Workspace;
use crate::Client;
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyList, PyString};
// #[pyfunction]
// pub fn codemp_init<'a>(py: Python<'a>) -> PyResult<Py<Client>> {
@ -28,8 +27,8 @@ impl Client {
}
#[pyo3(name = "leave_workspace")]
fn pyleave_workspace<'p>(&'p self, py: Python<'p>, id: String) -> &PyBool {
PyBool::new(py, self.leave_workspace(id.as_str()))
fn pyleave_workspace(&self, id: String) -> bool {
self.leave_workspace(id.as_str())
}
// join a workspace
@ -42,12 +41,12 @@ impl Client {
}
#[pyo3(name = "active_workspaces")]
fn pyactive_workspaces<'p>(&'p self, py: Python<'p>) -> &PyList {
PyList::new(py, self.active_workspaces())
fn pyactive_workspaces(&self) -> Vec<String> {
self.active_workspaces()
}
#[pyo3(name = "user_id")]
fn pyuser_id<'p>(&'p self, py: Python<'p>) -> &PyString {
PyString::new(py, self.user_id().to_string().as_str())
fn pyuser_id(&self) -> String {
self.user_id().to_string()
}
}

View file

@ -5,8 +5,10 @@ pub mod workspace;
use std::sync::Arc;
use crate::{
api::Cursor, api::TextChange, buffer::Controller as BufferController,
cursor::Controller as CursorController, Client, Workspace,
api::{Cursor, TextChange},
buffer::Controller as BufferController,
cursor::Controller as CursorController,
Client, Workspace,
};
use pyo3::exceptions::{PyConnectionError, PyRuntimeError, PySystemError};
use pyo3::prelude::*;
@ -88,14 +90,16 @@ impl PyLogger {
#[pymodule]
fn codemp(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Client>()?;
m.add_class::<PyLogger>()?;
m.add_class::<Workspace>()?;
m.add_class::<CursorController>()?;
m.add_class::<TextChange>()?;
m.add_class::<BufferController>()?;
m.add_class::<Cursor>()?;
m.add_class::<TextChange>()?;
m.add_class::<CursorController>()?;
m.add_class::<Workspace>()?;
m.add_class::<Client>()?;
Ok(())
}

View file

@ -1,11 +1,11 @@
use crate::buffer::Controller as CodempBufferController;
use crate::cursor::Controller as CodempCursorController;
use crate::workspace::Workspace as CodempWorkspace;
use crate::buffer::Controller as BufferController;
use crate::cursor::Controller as CursorController;
use crate::workspace::Workspace;
use pyo3::prelude::*;
use pyo3::types::PyString;
#[pymethods]
impl CodempWorkspace {
impl Workspace {
// join a workspace
#[pyo3(name = "create")]
fn pycreate<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<&'p PyAny> {
@ -21,7 +21,7 @@ impl CodempWorkspace {
let ws = self.clone();
pyo3_asyncio::tokio::future_into_py(py, async move {
let buffctl: CodempBufferController = ws.attach(path.as_str()).await?;
let buffctl: BufferController = ws.attach(path.as_str()).await?;
Python::with_gil(|py| Py::new(py, buffctl))
})
}
@ -29,9 +29,9 @@ impl CodempWorkspace {
#[pyo3(name = "detach")]
fn pydetach(&self, path: String) -> bool {
match self.detach(path.as_str()) {
crate::workspace::DetachResult::NotAttached => false,
crate::workspace::DetachResult::Detaching => true,
crate::workspace::DetachResult::AlreadyDetached => true,
crate::workspace::worker::DetachResult::NotAttached => false,
crate::workspace::worker::DetachResult::Detaching => true,
crate::workspace::worker::DetachResult::AlreadyDetached => true,
}
}
@ -87,7 +87,7 @@ impl CodempWorkspace {
}
#[pyo3(name = "cursor")]
fn pycursor(&self, py: Python<'_>) -> PyResult<Py<CodempCursorController>> {
fn pycursor(&self, py: Python<'_>) -> PyResult<Py<CursorController>> {
Py::new(py, self.cursor())
}
@ -96,7 +96,7 @@ impl CodempWorkspace {
&self,
py: Python<'_>,
path: String,
) -> PyResult<Option<Py<CodempBufferController>>> {
) -> PyResult<Option<Py<BufferController>>> {
let Some(bufctl) = self.buffer_by_name(path.as_str()) else {
return Ok(None);
};