dev #10

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

View File

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

what compact?

what compact?

no int input, should be done already, so it can be removed. I added that several commit before before you removed that 😇

no int input, should be done already, so it can be removed. I added that several commit before before you removed that 😇
class Memory(int):
def __new__(cls, value: Union[str, int]) -> "Memory":
if isinstance(value, str):

View File

@ -1,4 +1,5 @@
from datetime import datetime, timedelta
jon-lee marked this conversation as resolved Outdated

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

and use underscore naming in this file

and use underscore naming in this file

every field in this file should not be optional. we give an default value here if any field does not exist

fixed

> every field in this file should not be optional. we give an default value here if any field does not exist fixed

and use underscore naming in this file

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

deprecated

deprecated

@bomingzh any suggestions on the structure?

@bomingzh any suggestions on the structure?
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/
``` 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/ ```

fixed with model_config

fixed with `model_config`

str here need to be a StrEnum now.

str here need to be a `StrEnum` now.

But I guess we don't know the set of case in advance, making it dynamic StrEnum is meaningless

But I guess we don't know the set of case in advance, making it dynamic `StrEnum` is meaningless

line changed, the comment is for parsers

line changed, the comment is for `parsers`
CPPCHECK = "cppcheck"
CPPLINT = "cpplint"
jon-lee marked this conversation as resolved Outdated

this should be the StrEnum

this should be the `StrEnum`

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

View File

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

ParserEnum

`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

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.
fn(parser_model, conf_stage.parsers[idx])
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.
elif parser == "diff":
elif parser == parser_enum.DIFF:
jon-lee marked this conversation as resolved Outdated

underscore

underscore

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

not necessary

not necessary

resolved.

resolved.