Compare commits

...

8 Commits

Author SHA1 Message Date
c19801f9a1 fix: conflict with master
Some checks failed
build / build (push) Failing after 2m32s
2025-02-27 09:49:16 +08:00
ab5bfc6cfe
fix: find repo.toml recursively
All checks were successful
build / build (push) Successful in 2m23s
2025-02-25 14:05:00 -05:00
67d2fcc4e4
feat: dump with exclude_none
All checks were successful
build / build (push) Successful in 2m26s
2025-02-25 04:15:05 -05:00
68628c0eae
feat: convert toml files recursively
All checks were successful
build / build (push) Successful in 2m28s
2025-02-25 03:47:50 -05:00
73f2581a31
ci: use local checkout
All checks were successful
build / build (push) Successful in 4m22s
2025-02-25 03:12:25 -05:00
bddb67decf
test: allow non-exist toml file input
All checks were successful
build / build (push) Successful in 2m36s
2025-02-24 22:36:08 -05:00
2bf1a225b6
docs(README): list pdm run
All checks were successful
build / build (push) Successful in 2m28s
2025-02-24 20:53:09 -05:00
acbcda9565
ci: only use runs-on
All checks were successful
build / build (push) Successful in 2m31s
2025-02-09 13:26:19 -05:00
14 changed files with 114 additions and 136 deletions

View File

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out repository code - name: Check out repository code
uses: https://gitea.com/BoYanZh/checkout@focs uses: actions/checkout@focs
- name: Display Python3 version - name: Display Python3 version
run: python3 --version run: python3 --version
- name: Install PDM - name: Install PDM

View File

@ -15,6 +15,7 @@
3. Change dir to the repo, `cd JOJ3-config-generator` 3. Change dir to the repo, `cd JOJ3-config-generator`
4. Install deps by `pdm install && pdm run pre-commit install` 4. Install deps by `pdm install && pdm run pre-commit install`
5. Run the cli app by `pdm run app --help` 5. Run the cli app by `pdm run app --help`
<<<<<<< HEAD
## How to use? ## How to use?
@ -28,3 +29,6 @@
```shell ```shell
joj3-config-generator convert -d -c /home/tt/.config/joj/ -r immutable_files joj3-config-generator convert -d -c /home/tt/.config/joj/ -r immutable_files
``` ```
=======
6. Check other commands or scripts with `pdm run --list`
>>>>>>> master

View File

@ -22,9 +22,7 @@ from joj3_config_generator.processers.task import (
) )
def convert( def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config:
repo_conf: repo.Config, task_conf: task.Config, repo_root: Path
) -> result.Config:
# Create the base ResultConf object # Create the base ResultConf object
result_conf = result.Config( result_conf = result.Config(
name=task_conf.task.name, name=task_conf.task.name,
@ -49,7 +47,7 @@ def convert(
not repo_conf.force_skip_heatlh_check_on_test not repo_conf.force_skip_heatlh_check_on_test
or os.environ.get("PYTEST_CURRENT_TEST") is None or os.environ.get("PYTEST_CURRENT_TEST") is None
): ):
healthcheck_stage = get_healthcheck_config(repo_conf, repo_root) healthcheck_stage = get_healthcheck_config(repo_conf)
result_conf.stage.stages.append(healthcheck_stage) result_conf.stage.stages.append(healthcheck_stage)
stages: List[str] = [] stages: List[str] = []
# Convert each stage in the task configuration # Convert each stage in the task configuration
@ -86,9 +84,7 @@ def distribute_json(folder_path: str, repo_obj: Any, repo_conf: Path) -> None:
with open(toml_file_path) as toml_file: with open(toml_file_path) as toml_file:
task_toml = toml_file.read() task_toml = toml_file.read()
task_obj = rtoml.loads(task_toml) task_obj = rtoml.loads(task_toml)
result_model = convert( result_model = convert(repo.Config(**repo_obj), task.Config(**task_obj))
repo.Config(**repo_obj), task.Config(**task_obj), repo_conf
)
result_dict = result_model.model_dump(by_alias=True, exclude_none=True) result_dict = result_model.model_dump(by_alias=True, exclude_none=True)
with open(json_file_path, "w") as result_file: with open(json_file_path, "w") as result_file:

View File

@ -1,21 +1,37 @@
import json import json
import os
from pathlib import Path from pathlib import Path
from typing import Any, Dict
import inquirer
import rtoml import rtoml
import typer import typer
import yaml import yaml
from typing_extensions import Annotated
from joj3_config_generator.convert import convert as convert_conf from joj3_config_generator.convert import convert as convert_conf
from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf
from joj3_config_generator.convert import distribute_json
from joj3_config_generator.models import joj1, repo, task from joj3_config_generator.models import joj1, repo, task
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)
@app.command()
def create(toml: typer.FileTextWrite) -> None:
"""
Create a new JOJ3 toml config file
"""
logger.info("Creating")
questions = [
inquirer.List(
"size",
message="What size do you need?",
choices=["Jumbo", "Large", "Standard", "Medium", "Small", "Micro"],
),
]
answers = inquirer.prompt(questions)
logger.info(answers)
@app.command() @app.command()
def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> None: def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> None:
""" """
@ -25,60 +41,42 @@ def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> N
joj1_obj = yaml.safe_load(yaml_file.read()) joj1_obj = yaml.safe_load(yaml_file.read())
joj1_model = joj1.Config(**joj1_obj) joj1_model = joj1.Config(**joj1_obj)
task_model = convert_joj1_conf(joj1_model) task_model = convert_joj1_conf(joj1_model)
result_dict = task_model.model_dump(by_alias=True, exclude_none=True) result_dict = task_model.model_dump(by_alias=True)
toml_file.write(rtoml.dumps(result_dict)) toml_file.write(rtoml.dumps(result_dict))
@app.command() @app.command()
def convert( def convert(
root: Path = typer.Option( root: Annotated[
Path("."), Path,
"--conf-root", typer.Argument(
"-c", help="root directory of config files, "
help="This is where you want to put all your 'task.toml' type folders, default choice for your input can be '/home/tt/.config/joj/'", "located at /home/tt/.config/joj in JTC"
), ),
repo_path: Path = typer.Option( ] = Path(".")
Path("."),
"--repo-root",
"-r",
help="This would be where you put your 'repo.toml' file as well as your 'immutable files', they should all be at same place, default choice for your input can be 'immutable_files', which is the folder at the position '/home/tt/.config/joj/'",
),
distribute: bool = typer.Option(
False, "--distribute", "-d", help="This flag determine whether to distribute"
),
) -> None: ) -> None:
"""
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()}")
if distribute is False: for repo_toml_path in root.glob("**/repo.toml"):
repo_toml_path = os.path.join(repo_path.absolute(), "basic", "repo.toml") repo_path = repo_toml_path.parent
else: repo_obj = rtoml.loads(repo_toml_path.read_text())
repo_toml_path = os.path.join("/home/tt/.config/joj", repo_path, "repo.toml") for task_toml_path in repo_path.glob("**/*.toml"):
repo_toml_path = os.path.join(repo_path, "repo.toml") if repo_toml_path == task_toml_path:
with open(repo_toml_path, encoding=None) as repo_file: continue
repo_toml = repo_file.read() toml_name = task_toml_path.name.removesuffix(".toml")
repo_obj = rtoml.loads(repo_toml) result_json_path = task_toml_path.parent / f"{toml_name}.json"
if distribute is False: logger.info(
task_toml_path = os.path.join(root.absolute(), "basic", "task.toml") f"Converting {repo_toml_path} & {task_toml_path} to {result_json_path}"
result_json_path = os.path.join(root.absolute(), "basic", "task.json") )
task_obj = rtoml.loads(task_toml_path.read_text())
with open(task_toml_path, encoding=None) as task_file: repo_conf = repo.Config(**repo_obj)
task_toml = task_file.read() repo_conf.path = repo_toml_path
task_conf = task.Config(**task_obj)
task_obj = rtoml.loads(task_toml) task_conf.path = task_toml_path
result_model = convert_conf( result_model = convert_conf(repo_conf, task_conf)
repo.Config(**repo_obj), task.Config(**task_obj), repo_path result_dict = result_model.model_dump(by_alias=True, exclude_none=True)
) with result_json_path.open("w") as result_file:
result_dict = result_model.model_dump(by_alias=True, exclude_none=True) json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
result_file.write("\n")
with open(result_json_path, "w", encoding=None) as result_file:
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
result_file.write("\n")
# distribution on json
# need a get folder path function
else:
folder_path = "/home/tt/.config/joj"
folder_path = f"{Path.home()}/Desktop/engr151-joj/home/tt/.config/joj/homework"
folder_path = f"{Path.home()}/Desktop/FOCS/JOJ3-config-generator/tests/convert/"
# to be used in real action
folder_path = f"{root}"
distribute_json(folder_path, repo_obj, repo_path)

View File

@ -1,4 +1,5 @@
from typing import List from pathlib import Path
from typing import List, Optional
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -21,3 +22,4 @@ class Config(BaseModel):
max_total_score: int = Field(100) max_total_score: int = Field(100)
force_skip_heatlh_check_on_test: bool = False force_skip_heatlh_check_on_test: bool = False
groups: Groups = Groups() groups: Groups = Groups()
path: Path = Path(".")

View File

@ -1,7 +1,8 @@
from datetime import datetime from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional, Type from typing import Any, Dict, List, Optional, Type
from pydantic import BaseModel, Field, model_serializer, model_validator from pydantic import BaseModel, Field, model_validator
class ParserResultDetail(BaseModel): class ParserResultDetail(BaseModel):
@ -109,4 +110,5 @@ class Task(BaseModel):
class Config(BaseModel): class Config(BaseModel):
task: Task task: Task
release: Release release: Release
path: Path = Path(".")
stages: List[Stage] # list of stage configurations stages: List[Stage] # list of stage configurations

View File

@ -37,7 +37,7 @@ def get_teapot_stage(repo_conf: repo.Config) -> result.StageDetail:
return stage_conf return stage_conf
def get_healthcheck_args(repo_conf: repo.Config, repo_root: Path) -> str: def get_healthcheck_args(repo_conf: repo.Config) -> str:
repoSize = repo_conf.max_size repoSize = repo_conf.max_size
immutable = repo_conf.files.immutable immutable = repo_conf.files.immutable
repo_size = f"-repoSize={str(repoSize)} " repo_size = f"-repoSize={str(repoSize)} "
@ -59,7 +59,7 @@ def get_healthcheck_args(repo_conf: repo.Config, repo_root: Path) -> str:
for meta in required_files: for meta in required_files:
args = args + meta args = args + meta
args = args + get_hash(immutable, repo_root) args = args + get_hash(immutable, repo_conf)
args = args + immutable_files args = args + immutable_files
@ -84,9 +84,7 @@ def get_debug_args(repo_conf: repo.Config) -> str:
return args return args
def get_healthcheck_config( def get_healthcheck_config(repo_conf: repo.Config) -> result.StageDetail:
repo_conf: repo.Config, repo_root: Path
) -> result.StageDetail:
healthcheck_stage = result.StageDetail( healthcheck_stage = result.StageDetail(
name="healthcheck", name="healthcheck",
group="", group="",
@ -96,7 +94,7 @@ def get_healthcheck_config(
default=result.Cmd(), default=result.Cmd(),
cases=[ cases=[
result.OptionalCmd( result.OptionalCmd(
args=shlex.split(get_healthcheck_args(repo_conf, repo_root)), args=shlex.split(get_healthcheck_args(repo_conf)),
), ),
result.OptionalCmd( result.OptionalCmd(
args=shlex.split(get_debug_args(repo_conf)), args=shlex.split(get_debug_args(repo_conf)),
@ -122,7 +120,7 @@ def calc_sha256sum(file_path: str) -> str:
def get_hash( def get_hash(
immutable_files: list[str], repo_root: Path immutable_files: list[str], repo_conf: repo.Config
) -> str: # input should be a list ) -> str: # input should be a list
# FIXME: should be finalized when get into the server # FIXME: should be finalized when get into the server
current_file_path = Path(__file__).resolve() current_file_path = Path(__file__).resolve()
@ -131,7 +129,7 @@ def get_hash(
file_path = f"{project_root}/tests/immutable_file/" file_path = f"{project_root}/tests/immutable_file/"
# file_path = "{Path.home()}/.cache/immutable" # file_path = "{Path.home()}/.cache/immutable"
# to be use # to be use
# file_path = f"/home/tt/.config/joj/{repo_root}/" # file_path = repo_conf.path
immutable_hash = [] immutable_hash = []
for i, file in enumerate(immutable_files): for i, file in enumerate(immutable_files):
immutable_files[i] = file_path + file.rsplit("/", 1)[-1] immutable_files[i] = file_path + file.rsplit("/", 1)[-1]

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "test", "sandboxToken": "",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,11 +60,8 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=50.5", "-repoSize=10",
"-meta=README.md", "-checkFileSumList=-checkFileNameList="
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -86,7 +83,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"joj=1000:24,run=1000:24,=100:24" "=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
@ -159,11 +156,11 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"tests/homework/h7/.clang-tidy": { "tests/homework/h7/.clang-tidy": {
"src": "/home/tt/.config/joj/tools/tests/homework/h7/.clang-tidy", "src": "/home/tt/.config/joj/tests/homework/h7/.clang-tidy",
"max": 419430400 "max": 419430400
}, },
"h7/build/compile_commands.json": { "h7/build/compile_commands.json": {
"src": "/home/tt/.config/joj/tools/h7/build/compile_commands.json", "src": "/home/tt/.config/joj/h7/build/compile_commands.json",
"max": 419430400 "max": 419430400
} }
}, },

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "test", "sandboxToken": "",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,11 +60,8 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=50.5", "-repoSize=10",
"-meta=README.md", "-checkFileSumList=-checkFileNameList="
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -86,7 +83,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"joj=1000:24,run=1000:24,=100:24" "=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "test", "sandboxToken": "",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,11 +60,8 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=50.5", "-repoSize=10",
"-meta=README.md", "-checkFileSumList=-checkFileNameList="
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -86,7 +83,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"joj=1000:24,run=1000:24,=100:24" "=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "test", "sandboxToken": "",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,11 +60,8 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=50.5", "-repoSize=10",
"-meta=README.md", "-checkFileSumList=-checkFileNameList="
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -86,7 +83,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"joj=1000:24,run=1000:24,=100:24" "=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
@ -150,7 +147,7 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"h7/build/ex2-asan": { "h7/build/ex2-asan": {
"src": "/home/tt/.config/joj/tools/h7/build/ex2-asan", "src": "/home/tt/.config/joj/h7/build/ex2-asan",
"max": 419430400 "max": 419430400
} }
}, },

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "test", "sandboxToken": "",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,11 +60,8 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=50.5", "-repoSize=10",
"-meta=README.md", "-checkFileSumList=-checkFileNameList="
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -86,7 +83,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"joj=1000:24,run=1000:24,=100:24" "=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
@ -157,7 +154,7 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"tools/filelength": { "tools/filelength": {
"src": "/home/tt/.config/joj/tools/tools/filelength", "src": "/home/tt/.config/joj/tools/filelength",
"max": 419430400 "max": 419430400
} }
}, },

View File

@ -1,5 +1,4 @@
import json import json
import os
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
@ -12,24 +11,22 @@ from joj3_config_generator.models import repo, task
def read_convert_files( def read_convert_files(
case_name: str, case_name: str,
) -> Tuple[repo.Config, task.Config, Dict[str, Any]]: ) -> Tuple[repo.Config, task.Config, Dict[str, Any]]:
root = os.path.dirname(os.path.realpath(__file__)) root = Path(__file__).resolve().parent
repo_toml_path = os.path.join(root, case_name, "repo.toml") repo_toml_path = root / case_name / "repo.toml"
with open(repo_toml_path) as f: repo_toml = repo_toml_path.read_text() if repo_toml_path.exists() else ""
repo_toml = f.read() task_toml_path = root / case_name / "task.toml"
task_toml_path = os.path.join(root, case_name, "task.toml") task_toml = task_toml_path.read_text() if task_toml_path.exists() else ""
with open(task_toml_path) as f: result = json.loads((root / case_name / "task.json").read_text())
task_toml = f.read() return (
result_json_path = os.path.join(root, case_name, "task.json") repo.Config(**rtoml.loads(repo_toml)),
with open(result_json_path) as f: task.Config(**rtoml.loads(task_toml)),
result: Dict[str, Any] = json.load(f) result,
repo_obj = rtoml.loads(repo_toml) )
task_obj = rtoml.loads(task_toml)
return repo.Config(**repo_obj), task.Config(**task_obj), result
def load_case(case_name: str) -> None: def load_case(case_name: str) -> None:
repo, task, expected_result = read_convert_files(case_name) repo, task, expected_result = read_convert_files(case_name)
result = convert(repo, task, repo_root=Path(".")).model_dump( result = convert(repo, task).model_dump(
mode="json", by_alias=True, exclude_none=True mode="json", by_alias=True, exclude_none=True
) )
assert result == expected_result assert result == expected_result

View File

@ -1,4 +1,4 @@
import os from pathlib import Path
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
import rtoml import rtoml
@ -9,16 +9,12 @@ from joj3_config_generator.models import joj1
def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any]]: def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any]]:
root = os.path.dirname(os.path.realpath(__file__)) root = Path(__file__).resolve().parent
task_yaml_path = os.path.join(root, case_name, "task.yaml") task_yaml_path = root / case_name / "task.yaml"
with open(task_yaml_path) as f: task_yaml = task_yaml_path.read_text()
task_yaml = f.read() task_toml_path = root / case_name / "task.toml"
task_toml_path = os.path.join(root, case_name, "task.toml") task_toml = task_toml_path.read_text()
with open(task_toml_path) as f: return joj1.Config(**yaml.safe_load(task_yaml)), rtoml.loads(task_toml)
task_toml = f.read()
joj1_obj = yaml.safe_load(task_yaml)
task_obj = rtoml.loads(task_toml)
return joj1.Config(**joj1_obj), task_obj
def load_case(case_name: str) -> None: def load_case(case_name: str) -> None: