dev #10
|  | @ -3,6 +3,7 @@ from typing import Union | |||
| import humanfriendly | ||||
| 
 | ||||
| 
 | ||||
| # FIXME: we don't need to compact for int | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 | ||||
| class Memory(int): | ||||
|     def __new__(cls, value: Union[str, int]) -> "Memory": | ||||
|         if isinstance(value, str): | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| from datetime import datetime, timedelta | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  every field in this file should not be optional. we give an default value here if any field does not exist every field in this file should not be optional. we give an default value here if any field does not exist 
				
					
						张泊明518370910136
						commented  and use underscore naming in this file and use underscore naming in this file 
				
					
						李衍志523370910113
						commented  
 fixed > every field in this file should not be optional. we give an default value here if any field does not exist
fixed 
				
					
						李衍志523370910113
						commented  
 fixed. > and use underscore naming in this file
fixed. | ||||
| from enum import StrEnum | ||||
| from pathlib import Path | ||||
| from typing import Any, Dict, List, Type | ||||
| 
 | ||||
|  | @ -80,6 +81,18 @@ class Limit(BaseModel): | |||
|         raise ValueError("Must be a string") | ||||
| 
 | ||||
| 
 | ||||
| class Parser(StrEnum): | ||||
|     CLANG_TIDY = "clangtidy" | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  deprecated deprecated 
				
					
						李衍志523370910113
						commented  @bomingzh any suggestions on the structure? @bomingzh any suggestions on the structure? 
				
					
						张泊明518370910136
						commented  ```
PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
``` 
				
					
						李衍志523370910113
						commented  fixed with  fixed with `model_config` 
				
					
						张泊明518370910136
						commented  str here need to be a  str here need to be a `StrEnum` now. 
				
					
						李衍志523370910113
						commented  But I guess we don't know the set of case in advance, making it dynamic  But I guess we don't know the set of case in advance, making it dynamic `StrEnum` is meaningless 
				
					
						张泊明518370910136
						commented  line changed, the comment is for  line changed, the comment is for `parsers` | ||||
|     CPPCHECK = "cppcheck" | ||||
|     CPPLINT = "cpplint" | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						李衍志523370910113
						commented  this should be the  this should be the `StrEnum` 
				
					
						张泊明518370910136
						commented  yes yes 
				
					
						李衍志523370910113
						commented  It is supported now. It is supported now. | ||||
|     KEYWORD = "keyword" | ||||
|     RESULT_STATUS = "result-status" | ||||
|     RESULT_DETAIL = "result-detail" | ||||
|     DUMMY = "dummy" | ||||
|     FILE = "file" | ||||
|     DIFF = "diff" | ||||
| 
 | ||||
| 
 | ||||
| class Stage(BaseModel): | ||||
|     name: str = ""  # Stage name | ||||
|     env: List[str] = [] | ||||
|  | @ -88,7 +101,7 @@ class Stage(BaseModel): | |||
|     in_: str = Field("", alias="in") | ||||
|     out_: str = Field("", alias="out") | ||||
|     score: int = 0 | ||||
|     parsers: List[str] = []  # list of parsers | ||||
|     parsers: List[Parser] = []  # list of parsers | ||||
|     limit: Limit = Limit() | ||||
|     dummy: ParserDummy = ParserDummy() | ||||
|     result_status: ParserDummy = Field(ParserDummy(), alias="result-status") | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ from typing import Any, Callable, Dict, List, Tuple | |||
| from joj3_config_generator.models import result, task | ||||
| from joj3_config_generator.models.common import Memory, Time | ||||
| from joj3_config_generator.models.const import JOJ3_CONFIG_ROOT | ||||
| from joj3_config_generator.models.task import Parser as parser_enum | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  
 `ParserEnum` | ||||
| 
 | ||||
| 
 | ||||
| def get_conf_stage( | ||||
|  | @ -32,7 +33,7 @@ def get_conf_stage( | |||
|         if parser in processed_dict: | ||||
|             fn, parser_model = processed_dict[parser] | ||||
| 
					
					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. | ||||
|             fn(parser_model, conf_stage.parsers[idx]) | ||||
| 
					
					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. | ||||
|         elif parser == "diff": | ||||
|         elif parser == parser_enum.DIFF: | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  underscore underscore 
				
					
						李衍志523370910113
						commented  fixed fixed | ||||
|             fix_diff( | ||||
|                 task_stage, | ||||
|                 conf_stage.parsers[idx], | ||||
|  | @ -46,16 +47,18 @@ def get_conf_stage( | |||
| 
 | ||||
| def get_processed_dict( | ||||
|     task_stage: task.Stage, | ||||
| ) -> 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), | ||||
|         "cpplint": (fix_keyword, task_stage.cpplint), | ||||
|         "result-detail": (fix_result_detail, task_stage.result_detail), | ||||
|         "dummy": (fix_dummy, task_stage.dummy), | ||||
|         "result-status": (fix_dummy, task_stage.result_status), | ||||
|         "file": (fix_file, task_stage.file), | ||||
| ) -> Dict[parser_enum, Tuple[Callable[[Any, result.Parser], None], Any]]: | ||||
|     processed_dict: Dict[ | ||||
|         parser_enum, Tuple[Callable[[Any, result.Parser], None], Any] | ||||
|     ] = { | ||||
|         parser_enum.CLANG_TIDY: (fix_keyword, task_stage.clangtidy), | ||||
|         parser_enum.KEYWORD: (fix_keyword, task_stage.keyword), | ||||
|         parser_enum.CPPCHECK: (fix_keyword, task_stage.cppcheck), | ||||
|         parser_enum.CPPLINT: (fix_keyword, task_stage.cpplint), | ||||
|         parser_enum.RESULT_DETAIL: (fix_result_detail, task_stage.result_detail), | ||||
|         parser_enum.DUMMY: (fix_dummy, task_stage.dummy), | ||||
|         parser_enum.RESULT_STATUS: (fix_dummy, task_stage.result_status), | ||||
|         parser_enum.FILE: (fix_file, task_stage.file), | ||||
|     } | ||||
|     return processed_dict | ||||
| 
					
					jon-lee marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
					
						张泊明518370910136
						commented  not necessary not necessary 
				
					
						李衍志523370910113
						commented  resolved. resolved. | ||||
| 
 | ||||
|  |  | |||
what compact?
no int input, should be done already, so it can be removed. I added that several commit before before you removed that 😇