feat: dump with exclude_none
All checks were successful
build / build (push) Successful in 2m26s

This commit is contained in:
张泊明518370910136 2025-02-25 04:15:05 -05:00
parent 68628c0eae
commit 67d2fcc4e4
GPG Key ID: D47306D7062CDA9D
4 changed files with 15 additions and 30 deletions

View File

@ -5,6 +5,7 @@ import inquirer
import rtoml
import typer
import yaml
from typing_extensions import Annotated
from joj3_config_generator.convert import convert as convert_conf
from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf
@ -45,7 +46,15 @@ def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> N
@app.command()
def convert(root: Path = Path(".")) -> None:
def convert(
root: Annotated[
Path,
typer.Argument(
help="root directory of config files, "
"located at /home/tt/.config/joj in JTC"
),
] = Path(".")
) -> None:
"""
Convert given dir of JOJ3 toml config files to JOJ3 json config files
"""
@ -62,7 +71,7 @@ def convert(root: Path = Path(".")) -> None:
logger.info(f"Converting {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))
result_dict = result_model.model_dump(by_alias=True)
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

@ -19,9 +19,6 @@
"./h3/ex5.m"
],
"env": [],
"stdin": null,
"stdout": null,
"stderr": null,
"cpuLimit": 0,
"realCpuLimit": 0,
"clockLimit": 0,
@ -33,22 +30,12 @@
"copyIn": {
"tools/matlab-joj": {
"src": "tools/matlab-joj",
"content": null,
"fileId": null,
"name": null,
"max": null,
"symlink": null,
"streamIn": false,
"streamOut": false,
"pipe": false
},
"tools/matlab_formatter.py": {
"src": "tools/matlab_formatter.py",
"content": null,
"fileId": null,
"name": null,
"max": null,
"symlink": null,
"streamIn": false,
"streamOut": false,
"pipe": false
@ -99,9 +86,6 @@
"./h3/ex5.m"
],
"env": [],
"stdin": null,
"stdout": null,
"stderr": null,
"cpuLimit": 0,
"realCpuLimit": 0,
"clockLimit": 0,
@ -113,22 +97,12 @@
"copyIn": {
"tools/matlab-joj": {
"src": "tools/matlab-joj",
"content": null,
"fileId": null,
"name": null,
"max": null,
"symlink": null,
"streamIn": false,
"streamOut": false,
"pipe": false
},
"tools/matlab_formatter.py": {
"src": "tools/matlab_formatter.py",
"content": null,
"fileId": null,
"name": null,
"max": null,
"symlink": null,
"streamIn": false,
"streamOut": false,
"pipe": false

View File

@ -26,5 +26,7 @@ def read_convert_files(
def load_case(case_name: str) -> None:
repo, task, expected_result = read_convert_files(case_name)
result = convert(repo, task).model_dump(mode="json", by_alias=True)
result = convert(repo, task).model_dump(
mode="json", by_alias=True, exclude_none=True
)
assert result == expected_result

View File

@ -19,5 +19,5 @@ def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any]
def load_case(case_name: str) -> None:
joj1, expected_result = read_convert_joj1_files(case_name)
result = convert_joj1(joj1).model_dump(by_alias=True)
result = convert_joj1(joj1).model_dump(by_alias=True, exclude_none=True)
assert result == expected_result