fix: remove Optional and fix its dependent code
This commit is contained in:
		
							parent
							
								
									5c1eede217
								
							
						
					
					
						commit
						82fa325cf6
					
				|  | @ -1,4 +1,6 @@ | ||||||
| import os | import os | ||||||
|  | from datetime import datetime | ||||||
|  | from pathlib import Path | ||||||
| from typing import List | from typing import List | ||||||
| 
 | 
 | ||||||
| from joj3_config_generator.models import joj1, repo, result, task | from joj3_config_generator.models import joj1, repo, result, task | ||||||
|  | @ -29,6 +31,11 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config: | ||||||
|             if task_conf.release.end_time |             if task_conf.release.end_time | ||||||
|             else -1 |             else -1 | ||||||
|         ), |         ), | ||||||
|  |         effective_unix_timestamp=( | ||||||
|  |             int(task_conf.release.begin_time.timestamp()) | ||||||
|  |             if task_conf.release.begin_time | ||||||
|  |             else -1 | ||||||
|  |         ), | ||||||
|         actor_csv_path="/home/tt/.config/joj/students.csv",  # students.csv position |         actor_csv_path="/home/tt/.config/joj/students.csv",  # students.csv position | ||||||
|         max_total_score=repo_conf.max_total_score, |         max_total_score=repo_conf.max_total_score, | ||||||
|         stage=result.Stage( |         stage=result.Stage( | ||||||
|  | @ -62,9 +69,11 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config: | ||||||
| def convert_joj1(joj1_conf: joj1.Config) -> task.Config: | def convert_joj1(joj1_conf: joj1.Config) -> task.Config: | ||||||
|     stages = [get_joj1_run_stage(joj1_conf)] |     stages = [get_joj1_run_stage(joj1_conf)] | ||||||
|     return task.Config( |     return task.Config( | ||||||
|  |         root=Path(""), | ||||||
|  |         path=Path(""), | ||||||
|         task=task.Task( |         task=task.Task( | ||||||
|             name=(""), |             name=(""), | ||||||
|         ), |         ), | ||||||
|         release=task.Release(end_time=None, begin_time=None), |         release=task.Release(end_time=datetime.now(), begin_time=datetime.now()), | ||||||
|         stages=stages, |         stages=stages, | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| from datetime import datetime | from datetime import datetime | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| from typing import Any, Dict, List, Optional, Type | from typing import Any, Dict, List, Type | ||||||
| 
 | 
 | ||||||
| from pydantic import BaseModel, Field, field_validator, model_validator | from pydantic import BaseModel, Field, field_validator, model_validator | ||||||
| 
 | 
 | ||||||
|  | @ -13,48 +13,48 @@ from joj3_config_generator.models.const import ( | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ParserResultDetail(BaseModel): | class ParserResultDetail(BaseModel): | ||||||
|     time: Optional[bool] = True  # Display run time |     time: bool = True  # Display run time | ||||||
|     mem: Optional[bool] = True  # Display memory usage |     mem: bool = True  # Display memory usage | ||||||
|     stdout: Optional[bool] = False  # Display stdout messages |     stdout: bool = False  # Display stdout messages | ||||||
|     stderr: Optional[bool] = False  # Display stderr messages |     stderr: bool = False  # Display stderr messages | ||||||
|     exitstatus: Optional[bool] = False |     exitstatus: bool = False | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ParserFile(BaseModel): | class ParserFile(BaseModel): | ||||||
|     name: Optional[str] = None |     name: str = "" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ParserLog(BaseModel): | class ParserLog(BaseModel): | ||||||
|     fileName: Optional[str] = None |     file_name: str = Field("", alias="fileName") | ||||||
|     msg: Optional[str] = None |     msg: str = "" | ||||||
|     level: Optional[str] = None |     level: str = "" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ParserDummy(BaseModel): | class ParserDummy(BaseModel): | ||||||
|     comment: Optional[str] = "" |     comment: str = "" | ||||||
|     score: Optional[int] = 0 |     score: int = 0 | ||||||
|     forcequit: Optional[bool] = False |     forcequit: bool = False | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ParserKeyword(BaseModel): | class ParserKeyword(BaseModel): | ||||||
|     keyword: Optional[List[str]] = [] |     keyword: List[str] = [] | ||||||
|     weight: Optional[List[int]] = [] |     weight: List[int] = [] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Outputs(BaseModel): | class Outputs(BaseModel): | ||||||
|     score: Optional[int] = 0 |     score: int = 0 | ||||||
|     ignorespaces: Optional[bool] = True |     ignorespaces: bool = True | ||||||
|     hide: Optional[bool] = False |     hide: bool = False | ||||||
|     forcequit: Optional[bool] = False |     forcequit: bool = False | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ParserDiff(BaseModel): | class ParserDiff(BaseModel): | ||||||
|     output: Optional[Outputs] = Outputs() |     output: Outputs = Outputs() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Files(BaseModel): | class Files(BaseModel): | ||||||
|     import_: Optional[List[str]] = Field([], alias="import") |     import_: List[str] = Field([], alias="import") | ||||||
|     export: Optional[List[str]] = [] |     export: List[str] = [] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Limit(BaseModel): | class Limit(BaseModel): | ||||||
|  | @ -75,30 +75,30 @@ class Limit(BaseModel): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Stage(BaseModel): | class Stage(BaseModel): | ||||||
|     name: Optional[str] = None  # Stage name |     name: str = ""  # Stage name | ||||||
|     env: Optional[List[str]] = None |     env: List[str] = [] | ||||||
|     command: Optional[str] = None  # Command to run |     command: str = ""  # Command to run | ||||||
|     files: Optional[Files] = None |     files: Files = Files() | ||||||
|     in_: Optional[str] = Field(None, alias="in") |     in_: str = Field("", alias="in") | ||||||
|     out_: Optional[str] = Field(None, alias="out") |     out_: str = Field("", alias="out") | ||||||
|     score: Optional[int] = 0 |     score: int = 0 | ||||||
|     parsers: Optional[List[str]] = []  # list of parsers |     parsers: List[str] = []  # list of parsers | ||||||
|     limit: Limit = Limit() |     limit: Limit = Limit() | ||||||
|     dummy: Optional[ParserDummy] = ParserDummy() |     dummy: ParserDummy = ParserDummy() | ||||||
|     result_status: Optional[ParserDummy] = Field(ParserDummy(), alias="result-status") |     result_status: ParserDummy = Field(ParserDummy(), alias="result-status") | ||||||
|     keyword: Optional[ParserKeyword] = ParserKeyword() |     keyword: ParserKeyword = ParserKeyword() | ||||||
|     clangtidy: Optional[ParserKeyword] = ParserKeyword() |     clangtidy: ParserKeyword = ParserKeyword() | ||||||
|     cppcheck: Optional[ParserKeyword] = ParserKeyword() |     cppcheck: ParserKeyword = ParserKeyword() | ||||||
|     cpplint: Optional[ParserKeyword] = ParserKeyword() |     cpplint: ParserKeyword = ParserKeyword() | ||||||
|     result_detail: Optional[ParserResultDetail] = Field( |     result_detail: ParserResultDetail = Field( | ||||||
|         ParserResultDetail(), alias="result-detail" |         ParserResultDetail(), alias="result-detail" | ||||||
|     ) |     ) | ||||||
|     file: Optional[ParserFile] = ParserFile() |     file: ParserFile = ParserFile() | ||||||
|     skip: Optional[List[str]] = [] |     skip: List[str] = [] | ||||||
| 
 | 
 | ||||||
|     # cases related |     # cases related | ||||||
|     cases: Optional[Dict[str, "Stage"]] = None |     cases: Dict[str, "Stage"] = {} | ||||||
|     diff: Optional[ParserDiff] = ParserDiff() |     diff: ParserDiff = ParserDiff() | ||||||
| 
 | 
 | ||||||
|     model_config = {"extra": "allow"} |     model_config = {"extra": "allow"} | ||||||
| 
 | 
 | ||||||
|  | @ -113,20 +113,18 @@ class Stage(BaseModel): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Release(BaseModel): | class Release(BaseModel): | ||||||
|     end_time: Optional[datetime] = None  # RFC 3339 formatted date-time with offset |     end_time: datetime = datetime.now()  # RFC 3339 formatted date-time with offset | ||||||
|     begin_time: Optional[datetime] = None |     begin_time: datetime = datetime.now()  # RFC 3339 formatted date-time with offset | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Task(BaseModel): | class Task(BaseModel): | ||||||
|     type_: Optional[str] = Field( |     type_: str = Field("", serialization_alias="type", validation_alias="type") | ||||||
|         "", serialization_alias="type", validation_alias="type" |  | ||||||
|     ) |  | ||||||
|     name: str |     name: str | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Config(BaseModel): | class Config(BaseModel): | ||||||
|     root: Optional[Path] = None |     root: Path = Path(".") | ||||||
|     path: Optional[Path] = None |     path: Path = Path("task.toml") | ||||||
|     task: Task  # Task name (e.g., hw3 ex5) |     task: Task  # Task name (e.g., hw3 ex5) | ||||||
|     release: Release  # Release configuration |     release: Release  # Release configuration | ||||||
|     stages: List[Stage]  # list of stage configurations |     stages: List[Stage]  # list of stage configurations | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ def get_joj1_run_stage(joj1_config: joj1.Config) -> task.Stage: | ||||||
|         cases_conf.append( |         cases_conf.append( | ||||||
|             task.Stage( |             task.Stage( | ||||||
|                 score=case.score, |                 score=case.score, | ||||||
|                 command=case.execute_args if case.execute_args else None, |                 command=case.execute_args if case.execute_args else "", | ||||||
|                 limit=task.Limit( |                 limit=task.Limit( | ||||||
|                     cpu=Time(case.time) if case.time else DEFAULT_CPU_LIMIT, |                     cpu=Time(case.time) if case.time else DEFAULT_CPU_LIMIT, | ||||||
|                     mem=(Memory(case.memory) if case.memory else DEFAULT_MEMORY_LIMIT), |                     mem=(Memory(case.memory) if case.memory else DEFAULT_MEMORY_LIMIT), | ||||||
|  |  | ||||||
|  | @ -207,8 +207,8 @@ def fix_diff( | ||||||
|             clock_limit = 2 * case_stage.limit.cpu |             clock_limit = 2 * case_stage.limit.cpu | ||||||
|             memory_limit = case_stage.limit.mem |             memory_limit = case_stage.limit.mem | ||||||
|             command = case_stage.command if case_stage.command is not None else None |             command = case_stage.command if case_stage.command is not None else None | ||||||
|             stdin = case_stage.in_ if case_stage.in_ is not None else f"{case}.in" |             stdin = case_stage.in_ if case_stage.in_ != "" else f"{case}.in" | ||||||
|             stdout = case_stage.out_ if case_stage.out_ is not None else f"{case}.out" |             stdout = case_stage.out_ if case_stage.out_ != "" else f"{case}.out" | ||||||
| 
 | 
 | ||||||
|             stage_cases.append( |             stage_cases.append( | ||||||
|                 result.OptionalCmd( |                 result.OptionalCmd( | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| { | { | ||||||
|     "name": "hw7 ex2", |     "name": "hw7 ex2", | ||||||
|     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", |     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", | ||||||
|     "expireUnixTimestamp": -1, |     "expireUnixTimestamp": 1735574399, | ||||||
|     "effectiveUnixTimestamp": -1, |     "effectiveUnixTimestamp": 1735487999, | ||||||
|     "actorCsvPath": "/home/tt/.config/joj/students.csv", |     "actorCsvPath": "/home/tt/.config/joj/students.csv", | ||||||
|     "maxTotalScore": 100, |     "maxTotalScore": 100, | ||||||
|     "stage": { |     "stage": { | ||||||
|  | @ -660,6 +660,7 @@ | ||||||
|                         }, |                         }, | ||||||
|                         "cases": [ |                         "cases": [ | ||||||
|                             { |                             { | ||||||
|  |                                 "args": [], | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" | ||||||
|                                 }, |                                 }, | ||||||
|  | @ -669,6 +670,7 @@ | ||||||
|                                 "procLimit": 50 |                                 "procLimit": 50 | ||||||
|                             }, |                             }, | ||||||
|                             { |                             { | ||||||
|  |                                 "args": [], | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" | ||||||
|                                 }, |                                 }, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| task.name = "hw7 ex2" # task name | task.name = "hw7 ex2" # task name | ||||||
| task.type = "homework/h7/e2" # remove this task type later | task.type = "homework/h7/e2" # remove this task type later | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-12-30 23:59:59+08:00 | release.end_time = 2024-12-30 23:59:59+08:00 | ||||||
| release.begin_time = 2024-12-29 23:59:59+08:00 | release.begin_time = 2024-12-29 23:59:59+08:00 | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| { | { | ||||||
|     "name": "hw7 ex2", |     "name": "hw7 ex2", | ||||||
|     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", |     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", | ||||||
|     "expireUnixTimestamp": -1, |     "expireUnixTimestamp": 1735574399, | ||||||
|     "effectiveUnixTimestamp": -1, |     "effectiveUnixTimestamp": 1735487999, | ||||||
|     "actorCsvPath": "/home/tt/.config/joj/students.csv", |     "actorCsvPath": "/home/tt/.config/joj/students.csv", | ||||||
|     "maxTotalScore": 100, |     "maxTotalScore": 100, | ||||||
|     "stage": { |     "stage": { | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| task.name = "hw7 ex2" # task name | task.name = "hw7 ex2" # task name | ||||||
| task.type = "homework/h7/e2" # remove this task type later | task.type = "homework/h7/e2" # remove this task type later | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-12-30 23:59:59+08:00 | release.end_time = 2024-12-30 23:59:59+08:00 | ||||||
| release.begin_time = 2024-12-29 23:59:59+08:00 | release.begin_time = 2024-12-29 23:59:59+08:00 | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| { | { | ||||||
|     "name": "hw7 ex2", |     "name": "hw7 ex2", | ||||||
|     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", |     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", | ||||||
|     "expireUnixTimestamp": -1, |     "expireUnixTimestamp": 1735574399, | ||||||
|     "effectiveUnixTimestamp": -1, |     "effectiveUnixTimestamp": 1735487999, | ||||||
|     "actorCsvPath": "/home/tt/.config/joj/students.csv", |     "actorCsvPath": "/home/tt/.config/joj/students.csv", | ||||||
|     "maxTotalScore": 100, |     "maxTotalScore": 100, | ||||||
|     "stage": { |     "stage": { | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| task.name = "hw7 ex2" # task name | task.name = "hw7 ex2" # task name | ||||||
| task.type = "homework/h7/e2" # remove this task type later | task.type = "homework/h7/e2" # remove this task type later | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-12-30 23:59:59+08:00 | release.end_time = 2024-12-30 23:59:59+08:00 | ||||||
| release.begin_time = 2024-12-29 23:59:59+08:00 | release.begin_time = 2024-12-29 23:59:59+08:00 | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| { | { | ||||||
|     "name": "hw7 ex2", |     "name": "hw7 ex2", | ||||||
|     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", |     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", | ||||||
|     "expireUnixTimestamp": -1, |     "expireUnixTimestamp": 1735574399, | ||||||
|     "effectiveUnixTimestamp": -1, |     "effectiveUnixTimestamp": 1735487999, | ||||||
|     "actorCsvPath": "/home/tt/.config/joj/students.csv", |     "actorCsvPath": "/home/tt/.config/joj/students.csv", | ||||||
|     "maxTotalScore": 100, |     "maxTotalScore": 100, | ||||||
|     "stage": { |     "stage": { | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| task.name = "hw7 ex2" # task name | task.name = "hw7 ex2" # task name | ||||||
| task.type = "homework/h7/e2" # remove this task type later | task.type = "homework/h7/e2" # remove this task type later | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-12-30 23:59:59+08:00 | release.end_time = 2024-12-30 23:59:59+08:00 | ||||||
| release.begin_time = 2024-12-29 23:59:59+08:00 | release.begin_time = 2024-12-29 23:59:59+08:00 | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| { | { | ||||||
|     "name": "hw7 ex2", |     "name": "hw7 ex2", | ||||||
|     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", |     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", | ||||||
|     "expireUnixTimestamp": -1, |     "expireUnixTimestamp": 1735574399, | ||||||
|     "effectiveUnixTimestamp": -1, |     "effectiveUnixTimestamp": 1735487999, | ||||||
|     "actorCsvPath": "/home/tt/.config/joj/students.csv", |     "actorCsvPath": "/home/tt/.config/joj/students.csv", | ||||||
|     "maxTotalScore": 100, |     "maxTotalScore": 100, | ||||||
|     "stage": { |     "stage": { | ||||||
|  | @ -63,6 +63,7 @@ | ||||||
|                         }, |                         }, | ||||||
|                         "cases": [ |                         "cases": [ | ||||||
|                             { |                             { | ||||||
|  |                                 "args": [], | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case0.in" | ||||||
|                                 }, |                                 }, | ||||||
|  | @ -72,6 +73,7 @@ | ||||||
|                                 "procLimit": 50 |                                 "procLimit": 50 | ||||||
|                             }, |                             }, | ||||||
|                             { |                             { | ||||||
|  |                                 "args": [], | ||||||
|                                 "stdin": { |                                 "stdin": { | ||||||
|                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" |                                     "src": "/home/tt/.config/joj/homework/h7/e2/case1.in" | ||||||
|                                 }, |                                 }, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| task.name = "hw7 ex2" # task name | task.name = "hw7 ex2" # task name | ||||||
| task.type = "homework/h7/e2" # remove this task type later | task.type = "homework/h7/e2" # remove this task type later | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-12-30 23:59:59+08:00 | release.end_time = 2024-12-30 23:59:59+08:00 | ||||||
| release.begin_time = 2024-12-29 23:59:59+08:00 | release.begin_time = 2024-12-29 23:59:59+08:00 | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| { | { | ||||||
|     "name": "hw7 ex2", |     "name": "hw7 ex2", | ||||||
|     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", |     "logPath": "/home/tt/.cache/joj3/homework/h7/e2.log", | ||||||
|     "expireUnixTimestamp": -1, |     "expireUnixTimestamp": 1735574399, | ||||||
|     "effectiveUnixTimestamp": -1, |     "effectiveUnixTimestamp": 1735487999, | ||||||
|     "actorCsvPath": "/home/tt/.config/joj/students.csv", |     "actorCsvPath": "/home/tt/.config/joj/students.csv", | ||||||
|     "maxTotalScore": 100, |     "maxTotalScore": 100, | ||||||
|     "stage": { |     "stage": { | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| task.name = "hw7 ex2" # task name | task.name = "hw7 ex2" # task name | ||||||
| task.type = "homework/h7/e2" # remove this task type later | task.type = "homework/h7/e2" # remove this task type later | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-12-30 23:59:59+08:00 | release.end_time = 2024-12-30 23:59:59+08:00 | ||||||
| release.begin_time = 2024-12-29 23:59:59+08:00 | release.begin_time = 2024-12-29 23:59:59+08:00 | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user