#[cfg(feature = "python-renderer")]
use crate::backend::BuildContext;
#[cfg(feature = "python-renderer")]
use crate::config::model::PythonConfig;
#[cfg(feature = "python-renderer")]
use crate::renderer::{ImageRenderer, PythonRenderer};
use super::FactoryError;
#[cfg(feature = "python-renderer")]
pub fn build(
cfg: &PythonConfig,
ctx: &BuildContext,
) -> Result<Box<dyn ImageRenderer>, FactoryError> {
let python_ctx = ctx.python().ok_or_else(|| FactoryError::BuildFailed {
backend: "python".to_string(),
source: anyhow::anyhow!("PythonContext is required for Python backend"),
})?;
let interpreter = python_ctx
.interpreter
.as_deref()
.map(|p| {
p.to_str().ok_or_else(|| FactoryError::BuildFailed {
backend: "python".to_string(),
source: anyhow::anyhow!("Interpreter path contains invalid UTF-8"),
})
})
.transpose()?;
let renderer = PythonRenderer::new(&cfg.script_path, interpreter);
Ok(Box::new(renderer))
}
#[cfg(not(feature = "python-renderer"))]
pub fn build(
_cfg: &crate::config::model::PythonConfig,
_ctx: &crate::backend::BuildContext,
) -> Result<Box<dyn crate::renderer::ImageRenderer>, FactoryError> {
Err(FactoryError::BuildFailed {
backend: "python".to_string(),
source: anyhow::anyhow!(
"Python backend not available (feature 'python-renderer' not enabled)"
),
})
}