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