From 67d2fcc4e45e5da331f5c0b65b1bebd2e89d7908 Mon Sep 17 00:00:00 2001
From: Boming Zhang <bomingzh@sjtu.edu.cn>
Date: Tue, 25 Feb 2025 04:15:05 -0500
Subject: [PATCH] feat: dump with exclude_none

---
 joj3_config_generator/main.py | 13 +++++++++++--
 tests/convert/basic/task.json | 26 --------------------------
 tests/convert/utils.py        |  4 +++-
 tests/convert_joj1/utils.py   |  2 +-
 4 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/joj3_config_generator/main.py b/joj3_config_generator/main.py
index 6847a00..9d57dfe 100644
--- a/joj3_config_generator/main.py
+++ b/joj3_config_generator/main.py
@@ -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")
diff --git a/tests/convert/basic/task.json b/tests/convert/basic/task.json
index 294d15c..ca0a8fc 100644
--- a/tests/convert/basic/task.json
+++ b/tests/convert/basic/task.json
@@ -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
diff --git a/tests/convert/utils.py b/tests/convert/utils.py
index 046f715..f51f073 100644
--- a/tests/convert/utils.py
+++ b/tests/convert/utils.py
@@ -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
diff --git a/tests/convert_joj1/utils.py b/tests/convert_joj1/utils.py
index 7732511..74aa1b5 100644
--- a/tests/convert_joj1/utils.py
+++ b/tests/convert_joj1/utils.py
@@ -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