JOJ3-config-generator/joj3_config_generator/models/repo.py
张泊明518370910136 2c1ad47f14
Some checks failed
build / build (push) Failing after 1m47s
build / trigger-build-image (push) Has been skipped
feat: get grading repo name from cwd
2025-06-14 05:21:35 -04:00

67 lines
2.0 KiB
Python

from pathlib import Path
from typing import List
from pydantic import AliasChoices, BaseModel, Field, model_validator
class Files(BaseModel):
required: List[str] = []
immutable: List[str] = []
class Groups(BaseModel):
name: List[str] = []
max_count: List[int] = Field(
[], validation_alias=AliasChoices("max-count", "max_count")
)
time_period_hour: List[int] = Field(
[], validation_alias=AliasChoices("time-period-hour", "time_period_hour")
)
class Config(BaseModel):
max_size: float = Field(
10, ge=0, validation_alias=AliasChoices("max-size", "max_size")
)
files: Files = Files()
sandbox_token: str = Field(
"", validation_alias=AliasChoices("sandbox-token", "sandbox_token")
)
max_total_score: int = Field(
100, validation_alias=AliasChoices("max-total-score", "max_total_score")
)
force_skip_health_check_on_test: bool = Field(
False,
validation_alias=AliasChoices(
"force-skip-health-check-on-test", "force_skip_health_check_on_test"
),
)
force_skip_teapot_on_test: bool = Field(
False,
validation_alias=AliasChoices(
"force-skip-teapot-on-test", "force_skip_teapot_on_test"
),
)
groups: Groups = Groups()
root: Path = Path(".")
path: Path = Path("repo.toml")
grading_repo_name: str = Field(
"",
validation_alias=AliasChoices("grading-repo-name", "grading_repo_name"),
)
health_check_score: int = Field(
0, validation_alias=AliasChoices("health-check-score", "health_check_score")
)
submitter_in_issue_title: bool = Field(
True,
validation_alias=AliasChoices(
"submitter-in-issue-title", "submitter_in_issue_title"
),
)
@model_validator(mode="after")
def set_grading_repo_name_from_cwd(self) -> "Config":
if not self.grading_repo_name:
self.grading_repo_name = Path.cwd().name
return self