feat: better check toml empty
All checks were successful
build / build (push) Successful in 2m15s
build / trigger-build-image (push) Successful in 13s

This commit is contained in:
张泊明518370910136 2025-10-11 05:30:27 -07:00
parent d819847e8a
commit 4ad897392e
GPG Key ID: D47306D7062CDA9D
2 changed files with 12 additions and 1 deletions

View File

@ -12,6 +12,16 @@ from joj3_config_generator.models.common import Memory, Time
from joj3_config_generator.utils.logger import logger
def is_toml_empty(toml_path: Path) -> bool:
if toml_path.stat().st_size == 0:
return True
try:
data = tomli.loads(toml_path.read_text())
return not data
except tomli.TOMLDecodeError:
return False
def load_joj3_task_toml_answers() -> answer.Answers:
name = inquirer.text("What's the task name?", default="hw0")
language = inquirer.list_input(

View File

@ -13,6 +13,7 @@ from joj3_config_generator.generator import (
create_joj3_task_conf,
)
from joj3_config_generator.loader import (
is_toml_empty,
load_joj1_yaml,
load_joj3_task_toml_answers,
load_joj3_toml,
@ -106,7 +107,7 @@ def convert(
for task_toml_path in repo_toml_path.parent.glob("**/*.toml"):
if repo_toml_path == task_toml_path:
continue
if len(task_toml_path.read_bytes()) == 0:
if is_toml_empty(task_toml_path):
logger.info(f"Skipping empty task toml file {task_toml_path}")
continue
toml_name = task_toml_path.name.removesuffix(".toml")