centralize commands (#28)

This commit is contained in:
Josh Thomas 2024-12-12 22:51:35 -06:00 committed by GitHub
parent b13d19a4bf
commit b993e35460
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 23 deletions

View file

@ -1,5 +1,6 @@
use crate::packaging::{Packages, PackagingError};
use djls_ipc::v1::*;
use djls_ipc::IpcCommand;
use djls_ipc::{ProcessError, PythonProcess, TransportError};
use serde::Deserialize;
use std::fmt;
@ -90,22 +91,12 @@ pub struct Python {
impl Python {
pub fn setup(python: &mut PythonProcess) -> Result<Self, PythonError> {
let request = messages::Request {
command: Some(messages::request::Command::PythonGetEnvironment(
python::GetEnvironmentRequest {},
)),
};
let response = python.send(request).map_err(PythonError::Transport)?;
let response = python::GetEnvironmentRequest::execute(python)?;
match response.result {
Some(messages::response::Result::PythonGetEnvironment(response)) => response
.python
.ok_or_else(|| PythonError::Process(ProcessError::Response))
.map(Into::into),
Some(messages::response::Result::Error(e)) => {
Err(PythonError::Process(ProcessError::Health(e.message)))
}
_ => Err(PythonError::Process(ProcessError::Response)),
}
}