feat: repo & task config model
All checks were successful
build / build (push) Successful in 1m5s

This commit is contained in:
张泊明518370910136 2024-10-20 01:54:55 -04:00
parent 3756380888
commit 228488cbf2
GPG Key ID: D47306D7062CDA9D
4 changed files with 158 additions and 2 deletions

View File

@ -0,0 +1,101 @@
from datetime import datetime
from typing import List, Optional
import rtoml
from pydantic import BaseModel, Field
class RepoFiles(BaseModel):
whitelist_patterns: List[str]
whitelist_file: Optional[str]
required: List[str]
immutable: List[str]
class Repo(BaseModel):
teaching_team: List[str]
max_size: float = Field(..., ge=0)
release_tags: List[str]
files: RepoFiles
class ParserResultDetail(BaseModel):
time: bool = True # Display run time
mem: bool = True # Display memory usage
stderr: bool = False # Display stderr messages
class Files(BaseModel):
import_: List[str] = Field(alias="import")
export: List[str]
class Stage(BaseModel):
name: str # Stage name
command: str # Command to run
files: Files # Files to import and export
score: int # Score for the task
parsers: List[str] # List of parsers
result_detail: ParserResultDetail = (
ParserResultDetail()
) # for result-detail parser
class Release(BaseModel):
deadline: Optional[datetime] # RFC 3339 formatted date-time with offset
class Task(BaseModel):
task: str # Task name (e.g., hw3 ex5)
release: Release # Release configuration
stages: List[Stage] # List of stage configurations
if __name__ == "__main__":
repo_toml = """
teaching_team = [ "prof_john", "ta_alice", "ta_bob" ]
max_size = 50.5
release_tags = [ "v1.0", "v2.0", "final" ]
[files]
whitelist_patterns = [ "*.py", "*.txt", "*.md" ]
whitelist_file = ".whitelist"
required = [ "main.py", "README.md" ]
immutable = [ "config.yaml", "setup.py" ]
"""
task_toml = """
task = "hw3 ex5"
[release]
deadline = "2024-10-18T23:59:00+08:00"
[[stages]]
name = "judge_base"
command = "./matlab-joj ./h3/ex5.m"
score = 100
parsers = [ "diff", "result-detail" ]
files.import = [ "tools/matlab-joj", "tools/matlab_formatter.py" ]
files.export = [ "output/ex5_results.txt", "output/ex5_logs.txt" ]
result_detail.time = false
result_detail.mem = false
result_detail.stderr = true
[[stages]]
name = "judge_base2"
command = "./matlab-joj ./h3/ex5.m"
score = 80
parsers = [ "diff", "result-detail" ]
files.import = [ "tools/matlab-joj", "tools/matlab_formatter.py" ]
files.export = [ "output/ex5_results2.txt", "output/ex5_logs2.txt" ]
result_detail.time = true
result_detail.mem = true
result_detail.stderr = false
"""
repo_obj = rtoml.loads(repo_toml)
task_obj = rtoml.loads(task_toml)
print(Repo(**repo_obj))
print(Task(**task_obj))

View File

@ -5,7 +5,7 @@
groups = ["default", "dev", "lint", "test"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
content_hash = "sha256:07daa7949bf3bbb6729544b8f66c26ea6c033b07c669f98e26c5524501c739fd"
content_hash = "sha256:6757968c6c0d6bac2715cd137f74ac1d5696aae59c2079afe788c8338716646a"
[[metadata.targets]]
requires_python = ">=3.10"
@ -751,6 +751,55 @@ files = [
{file = "rich-13.9.2.tar.gz", hash = "sha256:51a2c62057461aaf7152b4d611168f93a9fc73068f8ded2790f29fe2b5366d0c"},
]
[[package]]
name = "rtoml"
version = "0.11.0"
requires_python = ">=3.8"
summary = ""
groups = ["default"]
marker = "python_version >= \"3.10\""
files = [
{file = "rtoml-0.11.0-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:bbea5538d8e7a495878717743225bf261b097b42b17558d7f6876ec8ff700649"},
{file = "rtoml-0.11.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ec72c71ce1eec6a9a75a59c914644a92afed55625f88086418c8f610646f6c31"},
{file = "rtoml-0.11.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4161c01ee5cbf173382d4a55b26fc0d4a00ce68b9252c51cf6ee1a7b15d7922b"},
{file = "rtoml-0.11.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:ca19e750d2becefe482bd4ddcc3395816a0d1e69fbc562a18a0fe2f4b688ec70"},
{file = "rtoml-0.11.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:398a17548248d06844e125fd748f5fd507819652866e833db4114bd32fda30f6"},
{file = "rtoml-0.11.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cb4c11a82a5ae89a4f5793dceed93e186032f1588e8f7ab3ebc48b8b54665a92"},
{file = "rtoml-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:384a580433edf011d8cdc683996866d0809721b7b9ab055c279a4bd51b5c7300"},
{file = "rtoml-0.11.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c55295fac0e18af5a7b91dc8a308dd50fe0dbf26e439a86ff674290823ed010d"},
{file = "rtoml-0.11.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:b00ea0a3f14af57f1bdbb89b71f59c912d4682f9aa6a1a3a6729d210a599c64f"},
{file = "rtoml-0.11.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2bde7832c792a95d3c2f1a55833d5f5ae745c701ff0c09ad3e935146670403ed"},
{file = "rtoml-0.11.0-cp310-none-win32.whl", hash = "sha256:dc350452dcdd69b5c247d6a6951f4253a5bec93b9da621da96ced4e1edc1d42d"},
{file = "rtoml-0.11.0-cp310-none-win_amd64.whl", hash = "sha256:1836518858936ab435fff23805120760b759c7fa441d7150cdc6744d8d28e0ad"},
{file = "rtoml-0.11.0-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:abf9a0f729040f99c7b1734c433919b19314843d0f1d597f2d82e448e210c60f"},
{file = "rtoml-0.11.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:48a3504d58d9a0178947cf988841f2a771b63bb90155ad20ba4da93318ca2195"},
{file = "rtoml-0.11.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:56421e722d61ff09df0ae1d447ed1f8f109877281a091da1062165093bfe6291"},
{file = "rtoml-0.11.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a1be1b24c51a0a79beaf13e69603a556a165f27c92c93d284408e44686f82fbc"},
{file = "rtoml-0.11.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ec5837a2e0e0e3084d243914c11aff602f6840e5c07a7b2e1ca0c89464ed7079"},
{file = "rtoml-0.11.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:765bb5f226f7694d66af39f23d79b65f6b30744ee1c1396acff303b772f4ba1d"},
{file = "rtoml-0.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd6dfbc1830055290e8ee9f7ffb7465106536f54c1465e08c980c38147e3bcf4"},
{file = "rtoml-0.11.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:068131643b18ee839f1d5798ef5b347d04e101b8b9398b774fc839e6231c63c7"},
{file = "rtoml-0.11.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:042fc83c225b1075b6e717d156c4c7ecdab255127f875f6188fb062d72e59c5f"},
{file = "rtoml-0.11.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:bcab62bbf210434dcab736c658911d0182afe33b3920b051978c04ca442504a9"},
{file = "rtoml-0.11.0-cp311-none-win32.whl", hash = "sha256:8edbf3f0498287557a0a170c9a9331dfb69058729968578c37aad19977ba5722"},
{file = "rtoml-0.11.0-cp311-none-win_amd64.whl", hash = "sha256:d5e3d8d73a220d06bf2359b13572bdbd198e66f45aeac1e84058e448dc34f85e"},
{file = "rtoml-0.11.0-cp311-none-win_arm64.whl", hash = "sha256:806e3893555657012fe89774e62999e8cac50df53a7bd27f7c838f606397c3f7"},
{file = "rtoml-0.11.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:34c4fd6e6465e6de84ac499e19ae3e4b0d4cd3f9763d1a72a75bd2ef4d0e466a"},
{file = "rtoml-0.11.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0095bc482788d39c6c3e2f9f3a6f7a8149ee1cefe624129e2afc90512d8f16b7"},
{file = "rtoml-0.11.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d90b06a36325c9ae6e273669d811aa0e6b8ae41fa9ffe3949f02ef1870dc0ad5"},
{file = "rtoml-0.11.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:902148f2bd13b4c64d2c5ed576910c5a0a2c86dc052f4e31ca1855131ee157c8"},
{file = "rtoml-0.11.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d84bbdad28e24f66b8ad632fb7cbec64b921fdff48bf57f4f7179648726f7e54"},
{file = "rtoml-0.11.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4b1d4d4b8d765cf5228e5def9c39837d5b70c6e51422e05b975898c8a765fd1e"},
{file = "rtoml-0.11.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8b900dcdf2068105b81b1ded3342dad952e3ea7d4a949473a690c686116a1730"},
{file = "rtoml-0.11.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4a491ad282b918292812518a61f432d6becf1b4a965d9c6595b7f00b1b722e61"},
{file = "rtoml-0.11.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d5ccbe43af82f17efed273b517e29febbd8225dab9a314f5728465b61a34781a"},
{file = "rtoml-0.11.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4125260584290461825abac23dafb34048dcbedaf9fafea913b5f0b1691c1ad0"},
{file = "rtoml-0.11.0-cp312-none-win32.whl", hash = "sha256:6e42385f510458f68587051a533cd0161653e1f2b381400a4873eab6f706940b"},
{file = "rtoml-0.11.0-cp312-none-win_amd64.whl", hash = "sha256:fdce3405e50ba73a45acdf36a793e3563da04fc913c53d54852c5d6cf1eb6d25"},
{file = "rtoml-0.11.0-cp312-none-win_arm64.whl", hash = "sha256:affc854919b46555f37d1408cb67f06f7453744bf1c5c1c53b69ed8b5227a28d"},
{file = "rtoml-0.11.0.tar.gz", hash = "sha256:a1d1ec36261c47169934a6c0f713a6cdf917604b3f72a72a809c3a68384255d4"},
]
[[package]]
name = "runs"
version = "1.2.2"

View File

@ -11,6 +11,7 @@ dependencies = [
"loguru>=0.7.2",
"pydantic>=2.9.2",
"inquirer>=3.4.0",
"rtoml>=0.11.0",
]
requires-python = ">=3.6"
authors = [{ name = "JOJ3-dev", email = "joj3@focs.ji.sjtu.edu.cn" }]

View File

@ -3,10 +3,15 @@
from typing import Any
import pytest
@pytest.mark.xfail(strict=True)
def test_generate() -> None:
generate = lambda x: x # TODO: real generate function imported
data_input: dict[Any, Any] = {} # TODO: load real input from some file
data_output: dict[Any, Any] = generate(data_input)
expected_output: dict[Any, Any] = {} # TODO: load real output from some file
expected_output: dict[Any, Any] = {
"a": "b"
} # TODO: load real output from some file
assert data_output == expected_output