dev #10

Merged
李衍志523370910113 merged 238 commits from dev into master 2025-03-05 16:20:39 +08:00
3 changed files with 24 additions and 43 deletions
Showing only changes of commit b7b7a93677 - Show all commits

View File

@ -4,18 +4,10 @@ from typing import Set
from joj3_config_generator.models import joj1, repo, result, task
from joj3_config_generator.models.const import CACHE_ROOT, JOJ3_CONFIG_ROOT
from joj3_config_generator.processers.repo import (
get_health_check_config,
get_health_check_stage,
get_teapot_stage,
)
from joj3_config_generator.processers.task import (
fix_diff,
fix_dummy,
fix_file,
fix_keyword,
fix_result_detail,
get_conf_stage,
get_executor_with_config,
)
from joj3_config_generator.processers.task import get_conf_stage
def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config:
@ -34,18 +26,11 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config:
current_test = os.environ.get("PYTEST_CURRENT_TEST") is not None
# 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_config(repo_conf))
result_conf.stage.stages.append(get_health_check_stage(repo_conf))
cached: Set[str] = set()
# Convert each stage in the task configuration
for task_stage in task_conf.stages:
jon-lee marked this conversation as resolved Outdated

Make this Path.home() default to /home/tt. For now, create a const for this dir.

Make this `Path.home()` default to `/home/tt`. For now, create a const for this dir.

fixed

fixed
executor_with_config = get_executor_with_config(task_stage, cached)
conf_stage = get_conf_stage(task_stage, executor_with_config)
conf_stage = fix_result_detail(task_stage, conf_stage)
conf_stage = fix_dummy(task_stage, conf_stage)
conf_stage = fix_keyword(task_stage, conf_stage)
conf_stage = fix_file(task_stage, conf_stage)
conf_stage = fix_diff(task_stage, conf_stage, task_conf)
result_conf.stage.stages.append(conf_stage)
result_conf.stage.stages.append(get_conf_stage(task_conf, task_stage, cached))
if not repo_conf.force_skip_teapot_on_test or not current_test:
result_conf.stage.post_stages.append(get_teapot_stage(repo_conf))

View File

@ -67,7 +67,7 @@ def get_teapot_check_args(repo_conf: repo.Config) -> List[str]:
]
def get_health_check_config(repo_conf: repo.Config) -> result.StageDetail:
def get_health_check_stage(repo_conf: repo.Config) -> result.StageDetail:
health_check_stage = result.StageDetail(
name="Health Check",
group="",

View File

@ -7,7 +7,9 @@ from joj3_config_generator.models.const import JOJ3_CONFIG_ROOT
def get_conf_stage(
jon-lee marked this conversation as resolved Outdated

ParserEnum

`ParserEnum`
task_stage: task.Stage, executor_with_config: result.ExecutorWith
task_conf: task.Config,
task_stage: task.Stage,
cached: Set[str],
) -> result.StageDetail:
conf_stage = result.StageDetail(
name=task_stage.name,
@ -20,7 +22,7 @@ def get_conf_stage(
),
executor=result.Executor(
name="sandbox",
with_=executor_with_config,
with_=get_executor_with(task_stage, cached),
),
parsers=(
[
@ -29,12 +31,15 @@ def get_conf_stage(
]
),
)
fix_result_detail(task_stage, conf_stage)
jon-lee marked this conversation as resolved Outdated

should loop through conf_stage.parsers here and update the with field according to the parser name.

should loop through `conf_stage.parsers` here and update the `with` field according to the parser name.

I think its already implemented in each of the fix_parsers functions

I think its already implemented in each of the `fix_parsers` functions

No, do not find the parser in the fix_xxx function. Instead, iterate through the parsers here and decide how to fill in the with.

No, do not find the parser in the `fix_xxx` function. Instead, iterate through the parsers here and decide how to fill in the `with`.

resolved.

resolved.

Use a dict to store parser name, field, function to process.

    process_dict: Dict[
        str, Tuple[Callable[[result.ParserConfig, BaseModel], None], BaseModel]
    ] = {
        "clangtidy": (fix_keyword, task_stage.clangtidy),
        "keyword": (fix_keyword, task_stage.keyword),
        "diff": (fix_diff, task_stage.diff),
    }
    for i, parser in enumerate(task_stage.parsers):
        if parser in process_dict:
            func, parser_model = process_dict[parser]
            func(conf_stage.parsers[i], parser_model)
Use a dict to store parser name, field, function to process. ``` process_dict: Dict[ str, Tuple[Callable[[result.ParserConfig, BaseModel], None], BaseModel] ] = { "clangtidy": (fix_keyword, task_stage.clangtidy), "keyword": (fix_keyword, task_stage.keyword), "diff": (fix_diff, task_stage.diff), } for i, parser in enumerate(task_stage.parsers): if parser in process_dict: func, parser_model = process_dict[parser] func(conf_stage.parsers[i], parser_model) ```

resolved.

resolved.
fix_dummy(task_stage, conf_stage)
jon-lee marked this conversation as resolved Outdated

Do we need to support both kinds of names?

Do we need to support both kinds of names?

probably yes, since it is easy for new ta to type it wrong

probably yes, since it is easy for new ta to type it wrong

parsers name should be a str enum, force them to use the correct names

parsers name should be a str enum, force them to use the correct names

ok, then removed.

ok, then removed.
fix_keyword(task_stage, conf_stage)
jon-lee marked this conversation as resolved Outdated

underscore

underscore

fixed

fixed
fix_file(task_stage, conf_stage)
fix_diff(task_stage, task_conf, conf_stage)
return conf_stage
def get_executor_with_config(
task_stage: task.Stage, cached: Set[str]
) -> result.ExecutorWith:
def get_executor_with(task_stage: task.Stage, cached: Set[str]) -> 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
@ -97,11 +102,9 @@ def fix_keyword(
return conf_stage
def fix_result_detail(
task_stage: task.Stage, conf_stage: result.StageDetail
) -> result.StageDetail:
def fix_result_detail(task_stage: task.Stage, conf_stage: result.StageDetail) -> None:
if "result-detail" not in task_stage.parsers:
return conf_stage
return
result_detail_parser = next(
p for p in conf_stage.parsers if p.name == "result-detail"
)
@ -121,12 +124,8 @@ def fix_result_detail(
).model_dump(by_alias=True)
)
return conf_stage
def fix_dummy(
task_stage: task.Stage, conf_stage: result.StageDetail
) -> result.StageDetail:
def fix_dummy(task_stage: task.Stage, conf_stage: result.StageDetail) -> None:
dummy_parser = [
jon-lee marked this conversation as resolved Outdated
    if task_stage.parsers is not None:
        for parser in task_stage.parsers:

->

for parser in task_stage.parsers or []:
``` if task_stage.parsers is not None: for parser in task_stage.parsers: ``` -> ``` for parser in task_stage.parsers or []: ```

resolved.

resolved.
"dummy",
"result-status",
@ -146,28 +145,25 @@ def fix_dummy(
force_quit_on_not_accepted=task_stage.result_status.force_quit,
).model_dump(by_alias=True)
)
return conf_stage
return
def fix_file(
task_stage: task.Stage, conf_stage: result.StageDetail
) -> result.StageDetail:
def fix_file(task_stage: task.Stage, conf_stage: result.StageDetail) -> None:
file_parser = ["file"]
for parser in task_stage.parsers:
if parser not in file_parser:
continue
bomingzh marked this conversation as resolved Outdated

these fields do not exist now

these fields do not exist now

resolved

resolved
No description provided.
file_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
file_parser_.with_.update({"name": task_stage.file.name})
return conf_stage
def fix_diff(
jon-lee marked this conversation as resolved Outdated

move continue to the other branch to reduce nesting

move `continue` to the other branch to reduce nesting

I mean

if parser not in keyword_parser:
    continue
if getattr(task_stage, parser, None) is None:
    continue
if score != score_:
    continue
I mean ``` if parser not in keyword_parser: continue ``` ``` if getattr(task_stage, parser, None) is None: continue ```` ``` if score != score_: continue ````

fixed.

fixed.
task_stage: task.Stage,
conf_stage: result.StageDetail,
task_conf: task.Config,
) -> result.StageDetail:
conf_stage: result.StageDetail,
) -> None:
if "diff" not in task_stage.parsers:
return conf_stage
return
jon-lee marked this conversation as resolved Outdated

Is it necessary to rename?

Is it necessary to rename?
diff_parser = next((p for p in conf_stage.parsers if p.name == "diff"), None)
skip = task_stage.skip
cases = task_stage.cases
@ -229,4 +225,4 @@ def fix_diff(
diff_parser.with_.update({"name": "diff", "cases": parser_cases})
conf_stage.executor.with_.cases = stage_cases
jon-lee marked this conversation as resolved Outdated

Just pass conf_stage.executor to this function rather then the whole conf_stage.

Just pass `conf_stage.executor` to this function rather then the whole `conf_stage`.
return conf_stage
return