feat: pass test

This commit is contained in:
李衍志523370910113 2024-11-08 00:05:22 +08:00
parent 115f57ab84
commit 08c75756e0
4 changed files with 15 additions and 22 deletions

View File

@ -1,6 +1,5 @@
import hashlib import hashlib
import socket import socket
import tempfile
from joj3_config_generator.models import ( from joj3_config_generator.models import (
Cmd, Cmd,
@ -17,10 +16,6 @@ from joj3_config_generator.models import (
) )
def get_temp_directory() -> str:
return tempfile.mkdtemp(prefix="repo-checker-")
def getGradingRepoName() -> str: def getGradingRepoName() -> str:
host_name = socket.gethostname() host_name = socket.gethostname()
return f"{host_name.split('-')[0]}-joj" return f"{host_name.split('-')[0]}-joj"
@ -53,7 +48,7 @@ def getHealthcheckCmd(repo_conf: Repo) -> Cmd:
else: else:
immutable_files = immutable_files + name + "," immutable_files = immutable_files + name + ","
# FIXME: need to make solution and make things easier to edit with global scope # FIXME: need to make solution and make things easier to edit with global scope
chore = f"/{get_temp_directory}/repo-health-checker -root=. " chore = f"/tmp/repo-health-checker -root=. "
args = "" args = ""
args = args + chore args = args + chore
args = args + repo_size args = args + repo_size
@ -68,9 +63,7 @@ def getHealthcheckCmd(repo_conf: Repo) -> Cmd:
args=args.split(), args=args.split(),
# FIXME: easier to edit within global scope # FIXME: easier to edit within global scope
copy_in={ copy_in={
f"/{get_temp_directory()}/repo-health-checker": CmdFile( f"/tmp/repo-health-checker": result.CmdFile(src=f"/tmp/repo-health-checker")
src=f"/{get_temp_directory()}/repo-health-checker"
)
}, },
) )
return cmd return cmd

View File

@ -8,9 +8,8 @@ import typer
import yaml import yaml
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.lib.task import get_processed_task_obj from joj3_config_generator.models import joj1, repo, result, task
from joj3_config_generator.models import 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)
@ -47,6 +46,7 @@ def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> N
@app.command() @app.command()
def convert(root: Path = Path(".")) -> result.Config:
def convert(root: Path = Path(".")) -> result.Config: def convert(root: Path = Path(".")) -> result.Config:
""" """
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
@ -64,9 +64,11 @@ def convert(root: Path = Path(".")) -> result.Config:
task_obj = rtoml.loads(task_toml) task_obj = rtoml.loads(task_toml)
result_model = convert_conf(Repo(**repo_obj), Task(**task_obj)) result_model = convert_conf(Repo(**repo_obj), Task(**task_obj))
result_dict = result_model.model_dump(by_alias=True) result_dict = result_model.model_dump(by_alias=True)
with open(result_json_path, "w") as result_file: with open(result_json_path, "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")
return result_model return result_model
return result_model

View File

@ -15,10 +15,7 @@
"with": { "with": {
"default": { "default": {
"args": [ "args": [
"/<function", "/tmp/repo-health-checker",
"get_temp_directory",
"at",
"0x7f8686b98180>/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=50.5", "-repoSize=50.5",
"-meta=main.py", "-meta=main.py",
@ -70,8 +67,8 @@
"cpuRateLimit": 0, "cpuRateLimit": 0,
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"//tmp/repo-checker-9jj98lrm/repo-health-checker": { "/tmp/repo-health-checker": {
"src": "//tmp/repo-checker-er4az3r2/repo-health-checker", "src": "/tmp/repo-health-checker",
"content": null, "content": null,
"fileId": null, "fileId": null,
"name": null, "name": null,

View File

@ -3,6 +3,7 @@ import os
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
import rtoml import rtoml
from deepdiff import DeepDiff
from joj3_config_generator.convert import convert from joj3_config_generator.convert import convert
from joj3_config_generator.models import repo, task from joj3_config_generator.models import repo, task
@ -12,13 +13,13 @@ 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 = os.path.dirname(os.path.realpath(__file__))
repo_toml_path = os.path.join(root.absolute(), case_name, "repo.toml") repo_toml_path = os.path.join(root, case_name, "repo.toml")
with open(repo_toml_path) as f: with open(repo_toml_path) as f:
repo_toml = f.read() repo_toml = f.read()
task_toml_path = os.path.join(root.absolute(), case_name, "task.toml") task_toml_path = os.path.join(root, case_name, "task.toml")
with open(task_toml_path) as f: with open(task_toml_path) as f:
task_toml = f.read() task_toml = f.read()
result_json_path = os.path.join(root.absolute(), case_name, "task.json") result_json_path = os.path.join(root, case_name, "task.json")
with open(result_json_path) as f: with open(result_json_path) as f:
result: Dict[str, Any] = json.load(f) result: Dict[str, Any] = json.load(f)
repo_obj = rtoml.loads(repo_toml) repo_obj = rtoml.loads(repo_toml)