add protobuf transport and refactor to support (#24)

This commit is contained in:
Josh Thomas 2024-12-11 20:28:57 -06:00 committed by GitHub
parent b3e0ee7b6e
commit 643a47953e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 406 additions and 74 deletions

View file

@ -1,4 +1,4 @@
use djls_ipc::{parse_json_response, JsonResponse, PythonProcess, TransportError};
use djls_ipc::{JsonResponse, PythonProcess, TransportError, TransportMessage, TransportResponse};
use serde::Deserialize;
use std::collections::HashMap;
use std::fmt;
@ -78,10 +78,18 @@ impl ImportCheck {
python: &mut PythonProcess,
modules: Option<Vec<String>>,
) -> Result<bool, PackagingError> {
let response = python.send("has_import", modules)?;
let response = parse_json_response(response)?;
let check = Self::try_from(response)?;
Ok(check.can_import)
let message = TransportMessage::Json("has_import".to_string());
let response = python.send(message, modules)?;
match response {
TransportResponse::Json(json_str) => {
let json_response: JsonResponse = serde_json::from_str(&json_str)?;
let check = Self::try_from(json_response)?;
Ok(check.can_import)
}
_ => Err(PackagingError::Transport(TransportError::Process(
"Unexpected response type".to_string(),
))),
}
}
}

View file

@ -1,5 +1,5 @@
use crate::packaging::{Packages, PackagingError};
use djls_ipc::{parse_json_response, JsonResponse, PythonProcess, TransportError};
use djls_ipc::{JsonResponse, PythonProcess, TransportError, TransportMessage, TransportResponse};
use serde::Deserialize;
use std::fmt;
use std::path::PathBuf;
@ -72,9 +72,17 @@ impl TryFrom<JsonResponse> for Python {
impl Python {
pub fn setup(python: &mut PythonProcess) -> Result<Self, PythonError> {
let response = python.send("python_setup", None)?;
let response = parse_json_response(response)?;
Ok(Self::try_from(response)?)
let message = TransportMessage::Json("python_setup".to_string());
let response = python.send(message, None)?;
match response {
TransportResponse::Json(json_str) => {
let json_response: JsonResponse = serde_json::from_str(&json_str)?;
Ok(Self::try_from(json_response)?)
}
_ => Err(PythonError::Transport(TransportError::Process(
"Unexpected response type".to_string(),
))),
}
}
}