fix: find repo.toml recursively
All checks were successful
build / build (push) Successful in 2m23s

This commit is contained in:
张泊明518370910136 2025-02-25 14:05:00 -05:00
parent 67d2fcc4e4
commit ab5bfc6cfe
GPG Key ID: D47306D7062CDA9D
3 changed files with 25 additions and 16 deletions

View File

@ -59,19 +59,24 @@ def convert(
Convert given dir of JOJ3 toml config files to JOJ3 json config files Convert given dir of JOJ3 toml config files to JOJ3 json config files
""" """
logger.info(f"Converting files in {root.absolute()}") logger.info(f"Converting files in {root.absolute()}")
repo_toml_path = root / "repo.toml" for repo_toml_path in root.glob("**/repo.toml"):
repo_obj = rtoml.loads( repo_path = repo_toml_path.parent
repo_toml_path.read_text() if repo_toml_path.exists() else "" repo_obj = rtoml.loads(repo_toml_path.read_text())
) for task_toml_path in repo_path.glob("**/*.toml"):
for task_toml_path in root.glob("**/*.toml"): if repo_toml_path == task_toml_path:
toml_name = task_toml_path.name.removesuffix(".toml") continue
if toml_name == "repo": toml_name = task_toml_path.name.removesuffix(".toml")
continue result_json_path = task_toml_path.parent / f"{toml_name}.json"
result_json_path = task_toml_path.parent / f"{toml_name}.json" logger.info(
logger.info(f"Converting {task_toml_path} to {result_json_path}") 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)) task_obj = rtoml.loads(task_toml_path.read_text())
result_dict = result_model.model_dump(by_alias=True, exclude_none=True) repo_conf = repo.Config(**repo_obj)
with result_json_path.open("w") as result_file: repo_conf.path = repo_toml_path
json.dump(result_dict, result_file, ensure_ascii=False, indent=4) task_conf = task.Config(**task_obj)
result_file.write("\n") 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)
result_file.write("\n")

View File

@ -1,3 +1,4 @@
from pathlib import Path
from typing import List, Optional from typing import List, Optional
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -11,6 +12,7 @@ class Files(BaseModel):
class Config(BaseModel): class Config(BaseModel):
path: Path = Path(".")
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]

View File

@ -1,4 +1,5 @@
from datetime import datetime from datetime import datetime
from pathlib import Path
from typing import List, Optional from typing import List, Optional
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -32,6 +33,7 @@ class Release(BaseModel):
class Config(BaseModel): class Config(BaseModel):
path: Path = Path(".")
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