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 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
@ -45,7 +46,15 @@ def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> N
@app.command() @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 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}") logger.info(f"Converting {task_toml_path} to {result_json_path}")
task_obj = rtoml.loads(task_toml_path.read_text()) task_obj = rtoml.loads(task_toml_path.read_text())
result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj)) 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: with result_json_path.open("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)
result_file.write("\n") result_file.write("\n")

View File

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

View File

@ -26,5 +26,7 @@ def read_convert_files(
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).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 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: def load_case(case_name: str) -> None:
joj1, expected_result = read_convert_joj1_files(case_name) 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 assert result == expected_result