Compare commits

...

3 Commits

Author SHA1 Message Date
3b40bee13c
test: use tests/convert as root
All checks were successful
build / build (pull_request) Successful in 2m29s
build / build (push) Successful in 2m30s
2025-03-04 15:23:46 -05:00
56ecd35e46
refactor: use dict instead of set for consistent order 2025-03-04 15:16:18 -05:00
e0da740871
style: rename class 2025-03-04 15:11:06 -05:00
7 changed files with 54 additions and 55 deletions

View File

@ -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))

View File

@ -114,7 +114,7 @@ class Executor(BaseModel):
with_: ExecutorWith = Field(..., serialization_alias="with")
class ParserConfig(BaseModel):
class Parser(BaseModel):
name: str
with_: Dict[str, Any] = Field(..., serialization_alias="with")
@ -123,7 +123,7 @@ class StageDetail(BaseModel):
name: str
group: Optional[str] = ""
executor: Executor
parsers: List[ParserConfig]
parsers: List[Parser]
class Stage(BaseModel):

View File

@ -29,7 +29,7 @@ def get_teapot_stage(repo_conf: repo.Config) -> result.StageDetail:
cases=[],
),
),
parsers=[result.ParserConfig(name="log", with_={"msg": "joj3 summary"})],
parsers=[result.Parser(name="log", with_={"msg": "joj3 summary"})],
)
return stage_conf
@ -87,8 +87,8 @@ def get_health_check_stage(repo_conf: repo.Config) -> result.StageDetail:
),
),
parsers=[
result.ParserConfig(name="healthcheck", with_={"score": 1}),
result.ParserConfig(name="debug", with_={"score": 0}),
result.Parser(name="healthcheck", with_={"score": 1}),
result.Parser(name="debug", with_={"score": 0}),
],
)
return health_check_stage

View File

@ -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,
@ -24,10 +24,7 @@ def get_conf_stage(
with_=get_executor_with(task_stage, cached),
),
parsers=(
[
result.ParserConfig(name=parser, with_={})
for parser in task_stage.parsers
]
[result.Parser(name=parser, with_={}) for parser in task_stage.parsers]
),
)
processed_dict = get_processed_dict(task_stage)
@ -44,10 +41,8 @@ def get_conf_stage(
def get_processed_dict(
task_stage: task.Stage,
) -> Dict[str, Tuple[Callable[[Any, result.ParserConfig], None], Any]]:
processed_dict: Dict[
str, Tuple[Callable[[Any, result.ParserConfig], None], Any]
] = {
) -> Dict[str, Tuple[Callable[[Any, result.Parser], None], Any]]:
processed_dict: Dict[str, Tuple[Callable[[Any, result.Parser], None], Any]] = {
"clangtidy": (fix_keyword, task_stage.clangtidy),
"keyword": (fix_keyword, task_stage.keyword),
"cppcheck": (fix_keyword, task_stage.cppcheck),
@ -60,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
@ -86,12 +83,12 @@ 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
def fix_keyword(
keyword_config: task.ParserKeyword, keyword_parser_: result.ParserConfig
keyword_config: task.ParserKeyword, keyword_parser_: result.Parser
) -> None:
keyword_weight: List[result.KeywordConfig] = []
unique_weight = list(set(keyword_config.weight))
@ -114,7 +111,7 @@ def fix_keyword(
def fix_result_detail(
result_detail_parser_config: task.ParserResultDetail,
result_detail_parser: result.ParserConfig,
result_detail_parser: result.Parser,
) -> None:
show_files = []
if result_detail_parser_config.stdout:
@ -134,7 +131,7 @@ def fix_result_detail(
def fix_dummy(
dummy_parser_config: task.ParserDummy, dummy_parser: result.ParserConfig
dummy_parser_config: task.ParserDummy, dummy_parser: result.Parser
) -> None:
# we don't use dummy parser in real application
if dummy_parser_config is None:
@ -149,9 +146,7 @@ def fix_dummy(
return
def fix_file(
file_parser_config: task.ParserFile, file_parser: result.ParserConfig
) -> None:
def fix_file(file_parser_config: task.ParserFile, file_parser: result.Parser) -> None:
file_parser.with_.update(
result.FileConfig(name=file_parser_config.name).model_dump(by_alias=True)
)
@ -160,7 +155,7 @@ def fix_file(
def fix_diff(
task_stage: task.Stage,
task_conf: task.Config,
diff_parser_config: result.ParserConfig,
diff_parser_config: result.Parser,
conf_stage: result.StageDetail,
) -> None:
diff_parser = diff_parser_config

View File

@ -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": [
@ -706,7 +706,7 @@
"cases": [
{
"stdin": {
"src": "/home/tt/.config/joj/case0.in"
"src": "/home/tt/.config/joj/basic/case0.in"
},
"cpuLimit": 500000000,
"clockLimit": 1000000000,
@ -715,7 +715,7 @@
},
{
"stdin": {
"src": "/home/tt/.config/joj/case1.in"
"src": "/home/tt/.config/joj/basic/case1.in"
},
"cpuLimit": 1234567890,
"clockLimit": 2469135780,
@ -736,7 +736,7 @@
{
"score": 5,
"fileName": "stdout",
"answerPath": "/home/tt/.config/joj/case0.out",
"answerPath": "/home/tt/.config/joj/basic/case0.out",
"forceQuitOnDiff": false,
"alwaysHide": false,
"compareSpace": false
@ -748,7 +748,7 @@
{
"score": 5,
"fileName": "stdout",
"answerPath": "/home/tt/.config/joj/case1.out",
"answerPath": "/home/tt/.config/joj/basic/case1.out",
"forceQuitOnDiff": false,
"alwaysHide": false,
"compareSpace": false

View File

@ -64,7 +64,7 @@
"cases": [
{
"stdin": {
"src": "/home/tt/.config/joj/case0.in"
"src": "/home/tt/.config/joj/diff/case0.in"
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
@ -73,7 +73,7 @@
},
{
"stdin": {
"src": "/home/tt/.config/joj/case1.in"
"src": "/home/tt/.config/joj/diff/case1.in"
},
"cpuLimit": 2000000000,
"clockLimit": 4000000000,
@ -94,7 +94,7 @@
{
"score": 5,
"fileName": "stdout",
"answerPath": "/home/tt/.config/joj/case0.out",
"answerPath": "/home/tt/.config/joj/diff/case0.out",
"forceQuitOnDiff": false,
"alwaysHide": false,
"compareSpace": false
@ -106,7 +106,7 @@
{
"score": 5,
"fileName": "stdout",
"answerPath": "/home/tt/.config/joj/case1.out",
"answerPath": "/home/tt/.config/joj/diff/case1.out",
"forceQuitOnDiff": false,
"alwaysHide": false,
"compareSpace": false

View File

@ -11,15 +11,19 @@ from joj3_config_generator.models import repo, task
def read_convert_files(
case_name: str,
) -> Tuple[repo.Config, task.Config, Dict[str, Any]]:
root = Path(__file__).resolve().parent / case_name
repo_toml_path = root / "repo.toml"
root = Path(__file__).resolve().parent
repo_toml_path = root / case_name / "repo.toml"
repo_toml = repo_toml_path.read_text() if repo_toml_path.exists() else ""
task_toml_path = root / "task.toml"
task_toml_path = root / case_name / "task.toml"
task_toml = task_toml_path.read_text() if task_toml_path.exists() else ""
result = json.loads((root / "task.json").read_text())
result = json.loads((root / case_name / "task.json").read_text())
return (
repo.Config(root=root, **rtoml.loads(repo_toml)),
task.Config(root=root, **rtoml.loads(task_toml)),
repo.Config(
root=root, path=repo_toml_path.relative_to(root), **rtoml.loads(repo_toml)
),
task.Config(
root=root, path=task_toml_path.relative_to(root), **rtoml.loads(task_toml)
),
result,
)