dev #10
|  | @ -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
						
					
				 | ||||
|         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)) | ||||
| 
 | ||||
|  |  | |||
|  | @ -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="", | ||||
|  |  | |||
|  | @ -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
						
					
				 
				
					
						张泊明518370910136
						commented  
 `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
						
					
				 
				
					
						张泊明518370910136
						commented  should loop through  should loop through `conf_stage.parsers` here and update the `with` field according to the parser name. 
				
					
						李衍志523370910113
						commented  I think its already implemented in each of the  I think its already implemented in each of the `fix_parsers` functions 
				
					
						张泊明518370910136
						commented  No, do not find the parser in the  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`. 
				
					
						李衍志523370910113
						commented  resolved. resolved. 
				
					
						张泊明518370910136
						commented  Use a dict to store parser name, field, function to process. 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)
``` 
				
					
						李衍志523370910113
						commented  resolved. resolved. | ||||
|     fix_dummy(task_stage, conf_stage) | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  Do we need to support both kinds of names? Do we need to support both kinds of names? 
				
					
						李衍志523370910113
						commented  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 
				
					
						张泊明518370910136
						commented  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 
				
					
						李衍志523370910113
						commented  ok, then removed. ok, then removed. | ||||
|     fix_keyword(task_stage, conf_stage) | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  underscore underscore 
				
					
						李衍志523370910113
						commented  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
						
					
				 
				
					
						张泊明518370910136
						commented  -> ```
    if task_stage.parsers is not None:
        for parser in task_stage.parsers:
```
->
```
for parser in task_stage.parsers or []:
``` 
				
					
						李衍志523370910113
						commented  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
						
					
				 
				
					
						张泊明518370910136
						commented  these fields do not exist now these fields do not exist now 
				
					
						李衍志523370910113
						commented  resolved resolved 
				
					
						张泊明518370910136
						commented  
			
				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
						
					
				 
				
					
						张泊明518370910136
						commented  move  move `continue` to the other branch to reduce nesting 
				
					
						张泊明518370910136
						commented  I mean I mean
```
if parser not in keyword_parser:
    continue
```
```
if getattr(task_stage, parser, None) is None:
    continue
````
```
if score != score_:
    continue
```` 
				
					
						李衍志523370910113
						commented  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
						
					
				 
				
					
						张泊明518370910136
						commented  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
						
					
				 
				
					
						张泊明518370910136
						commented  Just pass  Just pass `conf_stage.executor` to this function rather then the whole `conf_stage`. | ||||
|     return conf_stage | ||||
|     return | ||||
|  |  | |||
Make this
Path.home()default to/home/tt. For now, create a const for this dir.fixed