style: make it python 3.6 compatible
This commit is contained in:
parent
dd357cf39c
commit
74579cd539
|
@ -4,17 +4,17 @@ from joj3_config_generator.models import (
|
||||||
ExecutorConfig,
|
ExecutorConfig,
|
||||||
ExecutorWithConfig,
|
ExecutorWithConfig,
|
||||||
ParserConfig,
|
ParserConfig,
|
||||||
Repo,
|
RepoConfig,
|
||||||
ResultConfig,
|
ResultConfig,
|
||||||
Stage,
|
Stage,
|
||||||
StageConfig,
|
StageConfig,
|
||||||
Task,
|
TaskConfig,
|
||||||
TeapotConfig,
|
TeapotConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# FIXME: LLM generated convert function, only for demostration
|
# FIXME: LLM generated convert function, only for demostration
|
||||||
def convert(repo_conf: Repo, task_conf: Task) -> ResultConfig:
|
def convert(repo_conf: RepoConfig, task_conf: TaskConfig) -> ResultConfig:
|
||||||
# Create the base ResultConf object
|
# Create the base ResultConf object
|
||||||
result_conf = ResultConfig(
|
result_conf = ResultConfig(
|
||||||
name=task_conf.task,
|
name=task_conf.task,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import rtoml
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
from joj3_config_generator.convert import convert as convert_conf
|
from joj3_config_generator.convert import convert as convert_conf
|
||||||
from joj3_config_generator.models import Repo, Task
|
from joj3_config_generator.models import RepoConfig, TaskConfig
|
||||||
from joj3_config_generator.utils.logger import logger
|
from joj3_config_generator.utils.logger import logger
|
||||||
|
|
||||||
app = typer.Typer(add_completion=False)
|
app = typer.Typer(add_completion=False)
|
||||||
|
@ -54,7 +54,7 @@ def convert(root: Path = Path(".")) -> None:
|
||||||
task_toml = task_file.read()
|
task_toml = task_file.read()
|
||||||
repo_obj = rtoml.loads(repo_toml)
|
repo_obj = rtoml.loads(repo_toml)
|
||||||
task_obj = rtoml.loads(task_toml)
|
task_obj = rtoml.loads(task_toml)
|
||||||
result_model = convert_conf(Repo(**repo_obj), Task(**task_obj))
|
result_model = convert_conf(RepoConfig(**repo_obj), TaskConfig(**task_obj))
|
||||||
result_dict = result_model.model_dump(by_alias=True)
|
result_dict = result_model.model_dump(by_alias=True)
|
||||||
with open(result_json_path, "w") as result_file:
|
with open(result_json_path, "w") as result_file:
|
||||||
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
|
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from joj3_config_generator.models.joj1 import Case as Case
|
from joj3_config_generator.models.joj1 import Case as Case
|
||||||
from joj3_config_generator.models.joj1 import JOJ1Config as JOJ1Config
|
from joj3_config_generator.models.joj1 import JOJ1Config as JOJ1Config
|
||||||
from joj3_config_generator.models.joj1 import Language as Language
|
from joj3_config_generator.models.joj1 import Language as Language
|
||||||
from joj3_config_generator.models.repo import Repo as Repo
|
from joj3_config_generator.models.repo import RepoConfig as RepoConfig
|
||||||
|
from joj3_config_generator.models.repo import RepoFiles as RepoFiles
|
||||||
from joj3_config_generator.models.result import Cmd as Cmd
|
from joj3_config_generator.models.result import Cmd as Cmd
|
||||||
from joj3_config_generator.models.result import CmdFile as CmdFile
|
from joj3_config_generator.models.result import CmdFile as CmdFile
|
||||||
from joj3_config_generator.models.result import ExecutorConfig as ExecutorConfig
|
from joj3_config_generator.models.result import ExecutorConfig as ExecutorConfig
|
||||||
|
@ -11,4 +12,4 @@ from joj3_config_generator.models.result import ResultConfig as ResultConfig
|
||||||
from joj3_config_generator.models.result import Stage as Stage
|
from joj3_config_generator.models.result import Stage as Stage
|
||||||
from joj3_config_generator.models.result import StageConfig as StageConfig
|
from joj3_config_generator.models.result import StageConfig as StageConfig
|
||||||
from joj3_config_generator.models.result import TeapotConfig as TeapotConfig
|
from joj3_config_generator.models.result import TeapotConfig as TeapotConfig
|
||||||
from joj3_config_generator.models.task import Task as Task
|
from joj3_config_generator.models.task import TaskConfig as TaskConfig
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
@ -24,5 +24,5 @@ class Case(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class JOJ1Config(BaseModel):
|
class JOJ1Config(BaseModel):
|
||||||
languages: list[Language]
|
languages: List[Language]
|
||||||
cases: list[Case]
|
cases: List[Case]
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
from typing import Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
class RepoFiles(BaseModel):
|
class RepoFiles(BaseModel):
|
||||||
whitelist_patterns: list[str]
|
whitelist_patterns: List[str]
|
||||||
whitelist_file: Optional[str]
|
whitelist_file: Optional[str]
|
||||||
required: list[str]
|
required: List[str]
|
||||||
immutable: list[str]
|
immutable: List[str]
|
||||||
|
|
||||||
|
|
||||||
class Repo(BaseModel):
|
class RepoConfig(BaseModel):
|
||||||
teaching_team: list[str]
|
teaching_team: List[str]
|
||||||
max_size: float = Field(..., ge=0)
|
max_size: float = Field(..., ge=0)
|
||||||
release_tags: list[str]
|
release_tags: List[str]
|
||||||
files: RepoFiles
|
files: RepoFiles
|
||||||
sandbox_token: str
|
sandbox_token: str
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Any, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
import rtoml
|
import rtoml
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
@ -17,8 +17,8 @@ class CmdFile(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class Cmd(BaseModel):
|
class Cmd(BaseModel):
|
||||||
args: list[str]
|
args: List[str]
|
||||||
env: list[str] = []
|
env: List[str] = []
|
||||||
stdin: Optional[CmdFile] = None
|
stdin: Optional[CmdFile] = None
|
||||||
stdout: Optional[CmdFile] = None
|
stdout: Optional[CmdFile] = None
|
||||||
stderr: Optional[CmdFile] = None
|
stderr: Optional[CmdFile] = None
|
||||||
|
@ -33,8 +33,8 @@ class Cmd(BaseModel):
|
||||||
copy_in: dict[str, CmdFile] = Field({}, serialization_alias="copyIn")
|
copy_in: dict[str, CmdFile] = Field({}, serialization_alias="copyIn")
|
||||||
copy_in_cached: dict[str, str] = Field({}, serialization_alias="copyInCached")
|
copy_in_cached: dict[str, str] = Field({}, serialization_alias="copyInCached")
|
||||||
copy_in_dir: str = Field(".", serialization_alias="copyInDir")
|
copy_in_dir: str = Field(".", serialization_alias="copyInDir")
|
||||||
copy_out: list[str] = Field([], serialization_alias="copyOut")
|
copy_out: List[str] = Field([], serialization_alias="copyOut")
|
||||||
copy_out_cached: list[str] = Field([], serialization_alias="copyOutCached")
|
copy_out_cached: List[str] = Field([], serialization_alias="copyOutCached")
|
||||||
copy_out_max: int = Field(0, serialization_alias="copyOutMax")
|
copy_out_max: int = Field(0, serialization_alias="copyOutMax")
|
||||||
copy_out_dir: str = Field("", serialization_alias="copyOutDir")
|
copy_out_dir: str = Field("", serialization_alias="copyOutDir")
|
||||||
tty: bool = False
|
tty: bool = False
|
||||||
|
@ -44,8 +44,8 @@ class Cmd(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class OptionalCmd(BaseModel):
|
class OptionalCmd(BaseModel):
|
||||||
args: Optional[list[str]] = None
|
args: Optional[List[str]] = None
|
||||||
env: Optional[list[str]] = None
|
env: Optional[List[str]] = None
|
||||||
stdin: Optional[CmdFile] = None
|
stdin: Optional[CmdFile] = None
|
||||||
stdout: Optional[CmdFile] = None
|
stdout: Optional[CmdFile] = None
|
||||||
stderr: Optional[CmdFile] = None
|
stderr: Optional[CmdFile] = None
|
||||||
|
@ -62,8 +62,8 @@ class OptionalCmd(BaseModel):
|
||||||
None, serialization_alias="copyInCached"
|
None, serialization_alias="copyInCached"
|
||||||
)
|
)
|
||||||
copy_in_dir: Optional[str] = Field(None, serialization_alias="copyInDir")
|
copy_in_dir: Optional[str] = Field(None, serialization_alias="copyInDir")
|
||||||
copy_out: Optional[list[str]] = Field(None, serialization_alias="copyOut")
|
copy_out: Optional[List[str]] = Field(None, serialization_alias="copyOut")
|
||||||
copy_out_cached: Optional[list[str]] = Field(
|
copy_out_cached: Optional[List[str]] = Field(
|
||||||
None, serialization_alias="copyOutCached"
|
None, serialization_alias="copyOutCached"
|
||||||
)
|
)
|
||||||
copy_out_max: Optional[int] = Field(None, serialization_alias="copyOutMax")
|
copy_out_max: Optional[int] = Field(None, serialization_alias="copyOutMax")
|
||||||
|
@ -84,12 +84,12 @@ class Stage(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
group: str
|
group: str
|
||||||
executor: "ExecutorConfig"
|
executor: "ExecutorConfig"
|
||||||
parsers: list["ParserConfig"]
|
parsers: List["ParserConfig"]
|
||||||
|
|
||||||
|
|
||||||
class ExecutorWithConfig(BaseModel):
|
class ExecutorWithConfig(BaseModel):
|
||||||
default: Cmd
|
default: Cmd
|
||||||
cases: list[OptionalCmd]
|
cases: List[OptionalCmd]
|
||||||
|
|
||||||
|
|
||||||
class ExecutorConfig(BaseModel):
|
class ExecutorConfig(BaseModel):
|
||||||
|
@ -110,7 +110,7 @@ class StageConfig(BaseModel):
|
||||||
output_path: str = Field(
|
output_path: str = Field(
|
||||||
"/tmp/joj3_result.json", serialization_alias="outputPath"
|
"/tmp/joj3_result.json", serialization_alias="outputPath"
|
||||||
) # nosec: B108
|
) # nosec: B108
|
||||||
stages: list[Stage]
|
stages: List[Stage]
|
||||||
|
|
||||||
|
|
||||||
class TeapotConfig(BaseModel):
|
class TeapotConfig(BaseModel):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ class ParserResultDetail(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class Files(BaseModel):
|
class Files(BaseModel):
|
||||||
import_: list[str] = Field(alias="import")
|
import_: List[str] = Field(alias="import")
|
||||||
export: list[str]
|
export: List[str]
|
||||||
|
|
||||||
|
|
||||||
class Stage(BaseModel):
|
class Stage(BaseModel):
|
||||||
|
@ -21,7 +21,7 @@ class Stage(BaseModel):
|
||||||
command: str # Command to run
|
command: str # Command to run
|
||||||
files: Files # Files to import and export
|
files: Files # Files to import and export
|
||||||
score: int # Score for the task
|
score: int # Score for the task
|
||||||
parsers: list[str] # list of parsers
|
parsers: List[str] # list of parsers
|
||||||
result_detail: ParserResultDetail = (
|
result_detail: ParserResultDetail = (
|
||||||
ParserResultDetail()
|
ParserResultDetail()
|
||||||
) # for result-detail parser
|
) # for result-detail parser
|
||||||
|
@ -31,7 +31,7 @@ class Release(BaseModel):
|
||||||
deadline: Optional[datetime] # RFC 3339 formatted date-time with offset
|
deadline: Optional[datetime] # RFC 3339 formatted date-time with offset
|
||||||
|
|
||||||
|
|
||||||
class Task(BaseModel):
|
class TaskConfig(BaseModel):
|
||||||
task: str # Task name (e.g., hw3 ex5)
|
task: str # 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
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import os
|
import os
|
||||||
from typing import Any
|
from typing import Any, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from joj3_config_generator.models import Repo, Task
|
from joj3_config_generator.models import RepoConfig, TaskConfig
|
||||||
from tests.utils import read_convert_files
|
from tests.utils import read_convert_files
|
||||||
|
|
||||||
|
|
||||||
def get_test_cases() -> list[tuple[str, Repo, Task, dict[str, Any]]]:
|
def get_test_cases() -> List[tuple[str, RepoConfig, TaskConfig, dict[str, Any]]]:
|
||||||
test_cases = []
|
test_cases = []
|
||||||
tests_dir = os.path.dirname(os.path.realpath(__file__))
|
tests_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
for dir_name in os.listdir(tests_dir):
|
for dir_name in os.listdir(tests_dir):
|
||||||
|
@ -19,5 +19,7 @@ def get_test_cases() -> list[tuple[str, Repo, Task, dict[str, Any]]]:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=get_test_cases(), ids=lambda x: x[0])
|
@pytest.fixture(params=get_test_cases(), ids=lambda x: x[0])
|
||||||
def test_case(request: pytest.FixtureRequest) -> tuple[Repo, Task, dict[str, Any]]:
|
def test_case(
|
||||||
|
request: pytest.FixtureRequest,
|
||||||
|
) -> tuple[RepoConfig, TaskConfig, dict[str, Any]]:
|
||||||
return request.param[1:] # return repo, task, expected_result
|
return request.param[1:] # return repo, task, expected_result
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from joj3_config_generator.convert import convert
|
from joj3_config_generator.convert import convert
|
||||||
from joj3_config_generator.models import Repo, Task
|
from joj3_config_generator.models import RepoConfig, TaskConfig
|
||||||
|
|
||||||
|
|
||||||
def test_convert(test_case: tuple[Repo, Task, dict[str, Any]]) -> None:
|
def test_convert(test_case: tuple[RepoConfig, TaskConfig, dict[str, Any]]) -> None:
|
||||||
repo, task, expected_result = test_case
|
repo, task, expected_result = test_case
|
||||||
result = convert(repo, task).model_dump(by_alias=True)
|
result = convert(repo, task).model_dump(by_alias=True)
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
|
@ -4,10 +4,10 @@ from typing import Any
|
||||||
|
|
||||||
import rtoml
|
import rtoml
|
||||||
|
|
||||||
from joj3_config_generator.models import Repo, Task
|
from joj3_config_generator.models import RepoConfig, TaskConfig
|
||||||
|
|
||||||
|
|
||||||
def read_convert_files(root: str) -> tuple[Repo, Task, dict[str, Any]]:
|
def read_convert_files(root: str) -> tuple[RepoConfig, TaskConfig, dict[str, Any]]:
|
||||||
repo_toml_path = os.path.join(root, "repo.toml")
|
repo_toml_path = os.path.join(root, "repo.toml")
|
||||||
task_toml_path = os.path.join(root, "task.toml")
|
task_toml_path = os.path.join(root, "task.toml")
|
||||||
result_json_path = os.path.join(root, "task.json")
|
result_json_path = os.path.join(root, "task.json")
|
||||||
|
@ -19,4 +19,4 @@ def read_convert_files(root: str) -> tuple[Repo, Task, dict[str, Any]]:
|
||||||
expected_result: dict[str, Any] = json.load(result_file)
|
expected_result: dict[str, Any] = json.load(result_file)
|
||||||
repo_obj = rtoml.loads(repo_toml)
|
repo_obj = rtoml.loads(repo_toml)
|
||||||
task_obj = rtoml.loads(task_toml)
|
task_obj = rtoml.loads(task_toml)
|
||||||
return Repo(**repo_obj), Task(**task_obj), expected_result
|
return RepoConfig(**repo_obj), TaskConfig(**task_obj), expected_result
|
||||||
|
|
Loading…
Reference in New Issue
Block a user