From 56ecd35e460758dd18a5a24e3cc0e0831f289911 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Tue, 4 Mar 2025 15:16:18 -0500 Subject: [PATCH] refactor: use dict instead of set for consistent order --- joj3_config_generator/convert.py | 4 ++-- joj3_config_generator/processers/task.py | 10 ++++---- tests/convert/basic/task.json | 30 ++++++++++++------------ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/joj3_config_generator/convert.py b/joj3_config_generator/convert.py index 419094e..28791b0 100644 --- a/joj3_config_generator/convert.py +++ b/joj3_config_generator/convert.py @@ -1,5 +1,5 @@ import os -from typing import Set +from typing import Dict from joj3_config_generator.models import joj1, repo, result, task from joj3_config_generator.models.const import CACHE_ROOT, JOJ3_CONFIG_ROOT @@ -27,7 +27,7 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config: # Construct health check stage if not repo_conf.force_skip_health_check_on_test or not current_test: result_conf.stage.stages.append(get_health_check_stage(repo_conf)) - cached: Set[str] = set() + cached: Dict[str, None] = {} # Convert each stage in the task configuration for task_stage in task_conf.stages: result_conf.stage.stages.append(get_conf_stage(task_conf, task_stage, cached)) diff --git a/joj3_config_generator/processers/task.py b/joj3_config_generator/processers/task.py index 2fd9200..38e94e3 100644 --- a/joj3_config_generator/processers/task.py +++ b/joj3_config_generator/processers/task.py @@ -1,6 +1,6 @@ import re import shlex -from typing import Any, Callable, Dict, List, Set, Tuple +from typing import Any, Callable, Dict, List, Tuple from joj3_config_generator.models import result, task from joj3_config_generator.models.const import JOJ3_CONFIG_ROOT @@ -9,7 +9,7 @@ from joj3_config_generator.models.const import JOJ3_CONFIG_ROOT def get_conf_stage( task_conf: task.Config, task_stage: task.Stage, - cached: Set[str], + cached: Dict[str, None], ) -> result.StageDetail: conf_stage = result.StageDetail( name=task_stage.name, @@ -55,7 +55,9 @@ def get_processed_dict( return processed_dict -def get_executor_with(task_stage: task.Stage, cached: Set[str]) -> result.ExecutorWith: +def get_executor_with( + task_stage: task.Stage, cached: Dict[str, None] +) -> result.ExecutorWith: file_import = task_stage.files.import_ copy_in_files = [file for file in file_import if file not in cached] file_export = task_stage.files.export @@ -81,7 +83,7 @@ def get_executor_with(task_stage: task.Stage, cached: Set[str]) -> result.Execut cases=[], ) for file in file_export: - cached.add(file) + cached[file] = None return executor_with_config diff --git a/tests/convert/basic/task.json b/tests/convert/basic/task.json index bc821d6..2889357 100644 --- a/tests/convert/basic/task.json +++ b/tests/convert/basic/task.json @@ -222,11 +222,11 @@ } }, "copyInCached": { - "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/ex2": "h7/build/ex2", "h7/build/ex2-asan": "h7/build/ex2-asan", - "h7/build/compile_commands.json": "h7/build/compile_commands.json", "h7/build/ex2-ubsan": "h7/build/ex2-ubsan", - "h7/build/ex2": "h7/build/ex2" + "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/compile_commands.json": "h7/build/compile_commands.json" }, "copyInDir": ".", "copyOut": [ @@ -322,11 +322,11 @@ } }, "copyInCached": { - "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/ex2": "h7/build/ex2", "h7/build/ex2-asan": "h7/build/ex2-asan", - "h7/build/compile_commands.json": "h7/build/compile_commands.json", "h7/build/ex2-ubsan": "h7/build/ex2-ubsan", - "h7/build/ex2": "h7/build/ex2" + "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/compile_commands.json": "h7/build/compile_commands.json" }, "copyInDir": ".", "copyOut": [ @@ -444,11 +444,11 @@ "cpuSetLimit": "", "copyIn": {}, "copyInCached": { - "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/ex2": "h7/build/ex2", "h7/build/ex2-asan": "h7/build/ex2-asan", - "h7/build/compile_commands.json": "h7/build/compile_commands.json", "h7/build/ex2-ubsan": "h7/build/ex2-ubsan", - "h7/build/ex2": "h7/build/ex2" + "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/compile_commands.json": "h7/build/compile_commands.json" }, "copyInDir": ".", "copyOut": [ @@ -587,11 +587,11 @@ "cpuSetLimit": "", "copyIn": {}, "copyInCached": { - "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/ex2": "h7/build/ex2", "h7/build/ex2-asan": "h7/build/ex2-asan", - "h7/build/compile_commands.json": "h7/build/compile_commands.json", "h7/build/ex2-ubsan": "h7/build/ex2-ubsan", - "h7/build/ex2": "h7/build/ex2" + "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/compile_commands.json": "h7/build/compile_commands.json" }, "copyInDir": ".", "copyOut": [ @@ -684,11 +684,11 @@ "cpuSetLimit": "", "copyIn": {}, "copyInCached": { - "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/ex2": "h7/build/ex2", "h7/build/ex2-asan": "h7/build/ex2-asan", - "h7/build/compile_commands.json": "h7/build/compile_commands.json", "h7/build/ex2-ubsan": "h7/build/ex2-ubsan", - "h7/build/ex2": "h7/build/ex2" + "h7/build/ex2-msan": "h7/build/ex2-msan", + "h7/build/compile_commands.json": "h7/build/compile_commands.json" }, "copyInDir": ".", "copyOut": [