From 55da1e84820be631d89c953e2ca10734f7d3ddf4 Mon Sep 17 00:00:00 2001 From: jon-lee Date: Wed, 5 Mar 2025 08:53:38 +0800 Subject: [PATCH] style: more robust code --- joj3_config_generator/processers/task.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/joj3_config_generator/processers/task.py b/joj3_config_generator/processers/task.py index 6b80f58..5ecb884 100644 --- a/joj3_config_generator/processers/task.py +++ b/joj3_config_generator/processers/task.py @@ -1,5 +1,6 @@ import re import shlex +from pathlib import Path from typing import Any, Callable, Dict, List, Tuple from joj3_config_generator.models import result, task @@ -34,7 +35,10 @@ def get_conf_stage( fn(parser_model, conf_stage.parsers[idx]) elif parser == "diff": fix_diff( - task_stage, task_conf, conf_stage.parsers[idx], conf_stage.executor + task_stage, + conf_stage.parsers[idx], + conf_stage.executor, + JOJ3_CONFIG_ROOT / task_conf.path.parent, ) else: continue @@ -154,9 +158,9 @@ def fix_file(file_parser_config: task.ParserFile, file_parser: result.Parser) -> def fix_diff( task_stage: task.Stage, - task_conf: task.Config, diff_parser_config: result.Parser, diff_executor: result.Executor, + base_dir: Path, ) -> None: skip = task_stage.skip cases = task_stage.cases @@ -180,7 +184,7 @@ def fix_diff( stage_cases.append( result.OptionalCmd( stdin=result.LocalFile( - src=str(JOJ3_CONFIG_ROOT / task_conf.path.parent / stdin), + src=str(base_dir / stdin), ), args=shlex.split(command) if command else None, cpu_limit=cpu_limit, @@ -203,9 +207,7 @@ def fix_diff( result.DiffOutputConfig( score=diff_output.score, file_name="stdout", - answer_path=str( - JOJ3_CONFIG_ROOT / task_conf.path.parent / stdout - ), + answer_path=str(base_dir / stdout), force_quit_on_diff=diff_output.force_quit, always_hide=diff_output.hide, compare_space=not diff_output.ignore_spaces,