feat: 解决python虚拟环境问题

This commit is contained in:
2026-10-19 23:32:08 +08:00
parent 00a608c149
commit 23565b40a4
15 changed files with 611 additions and 10 deletions
+13
View File
@@ -7,6 +7,7 @@ use croner::Cron;
use sqlx::SqlitePool;
use url::Url;
use crate::python_env::validate_configured_venv;
use crate::{error::ApiResult, tasks::model::*};
use super::repository::{self, ListFilters};
@@ -182,12 +183,22 @@ fn validate_action(action: &TaskAction) -> ApiResult<()> {
match action {
TaskAction::Script {
working_dir,
venv,
interpreter,
script,
args,
env,
} => {
validate_required("action.working_dir", working_dir)?;
if let Some(venv) = venv {
validate_required("action.venv", venv)?;
validate_configured_venv(working_dir, venv).map_err(|error| {
crate::error::ApiError::validation(
"action.venv",
format!("虚拟环境无效: {error}"),
)
})?;
}
validate_required("action.interpreter", interpreter)?;
validate_required("action.script", script)?;
validate_args(args)?;
@@ -319,6 +330,7 @@ mod tests {
fn script_action() -> TaskAction {
TaskAction::Script {
working_dir: "D:\\Projects\\sync".to_owned(),
venv: None,
interpreter: "python.exe".to_owned(),
script: "main.py".to_owned(),
args: vec!["--mode".to_owned(), "full".to_owned()],
@@ -358,6 +370,7 @@ mod tests {
fn rejects_empty_script_path() {
let action = TaskAction::Script {
working_dir: "D:\\Projects\\sync".to_owned(),
venv: None,
interpreter: "python.exe".to_owned(),
script: " ".to_owned(),
args: Vec::new(),