This commit is contained in:
parent
67d2fcc4e4
commit
ab5bfc6cfe
|
@ -59,18 +59,23 @@ def convert(
|
|||
Convert given dir of JOJ3 toml config files to JOJ3 json config files
|
||||
"""
|
||||
logger.info(f"Converting files in {root.absolute()}")
|
||||
repo_toml_path = root / "repo.toml"
|
||||
repo_obj = rtoml.loads(
|
||||
repo_toml_path.read_text() if repo_toml_path.exists() else ""
|
||||
)
|
||||
for task_toml_path in root.glob("**/*.toml"):
|
||||
toml_name = task_toml_path.name.removesuffix(".toml")
|
||||
if toml_name == "repo":
|
||||
for repo_toml_path in root.glob("**/repo.toml"):
|
||||
repo_path = repo_toml_path.parent
|
||||
repo_obj = rtoml.loads(repo_toml_path.read_text())
|
||||
for task_toml_path in repo_path.glob("**/*.toml"):
|
||||
if repo_toml_path == task_toml_path:
|
||||
continue
|
||||
toml_name = task_toml_path.name.removesuffix(".toml")
|
||||
result_json_path = task_toml_path.parent / f"{toml_name}.json"
|
||||
logger.info(f"Converting {task_toml_path} to {result_json_path}")
|
||||
logger.info(
|
||||
f"Converting {repo_toml_path} & {task_toml_path} to {result_json_path}"
|
||||
)
|
||||
task_obj = rtoml.loads(task_toml_path.read_text())
|
||||
result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj))
|
||||
repo_conf = repo.Config(**repo_obj)
|
||||
repo_conf.path = repo_toml_path
|
||||
task_conf = task.Config(**task_obj)
|
||||
task_conf.path = task_toml_path
|
||||
result_model = convert_conf(repo_conf, task_conf)
|
||||
result_dict = result_model.model_dump(by_alias=True, exclude_none=True)
|
||||
with result_json_path.open("w") as result_file:
|
||||
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
@ -11,6 +12,7 @@ class Files(BaseModel):
|
|||
|
||||
|
||||
class Config(BaseModel):
|
||||
path: Path = Path(".")
|
||||
teaching_team: List[str]
|
||||
max_size: float = Field(..., ge=0)
|
||||
release_tags: List[str]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
@ -32,6 +33,7 @@ class Release(BaseModel):
|
|||
|
||||
|
||||
class Config(BaseModel):
|
||||
path: Path = Path(".")
|
||||
task: str # Task name (e.g., hw3 ex5)
|
||||
release: Release # Release configuration
|
||||
stages: List[Stage] # list of stage configurations
|
||||
|
|
Loading…
Reference in New Issue
Block a user