From 6b5d941eb1bc8f7b99eeed0123e31d6763ea470f Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 2 Mar 2025 15:01:31 -0500 Subject: [PATCH] chore: move path to const --- joj3_config_generator/convert.py | 5 +++-- joj3_config_generator/main.py | 4 ++-- joj3_config_generator/models/const.py | 6 ++++++ joj3_config_generator/processers/repo.py | 9 ++++---- joj3_config_generator/processers/task.py | 26 ++++++++---------------- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/joj3_config_generator/convert.py b/joj3_config_generator/convert.py index fa4a7aa..0b811ee 100644 --- a/joj3_config_generator/convert.py +++ b/joj3_config_generator/convert.py @@ -2,6 +2,7 @@ import os from typing import List from joj3_config_generator.models import joj1, repo, result, task +from joj3_config_generator.models.const import CACHE_ROOT, JOJ3_CONFIG_ROOT from joj3_config_generator.processers.repo import ( get_healthcheck_config, get_teapot_stage, @@ -22,10 +23,10 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config: result_conf = result.Config( name=task_conf.task.name, # exact folder difference specified by type - log_path=f"/home/tt/.cache/joj3/{task_conf.task.type_}.log", + log_path=str(CACHE_ROOT / "joj3" / f"{task_conf.task.type_}.log"), expire_unix_timestamp=int(task_conf.release.end_time.timestamp()), effective_unix_timestamp=int(task_conf.release.begin_time.timestamp()), - actor_csv_path="/home/tt/.config/joj/students.csv", # students.csv position + actor_csv_path=str(JOJ3_CONFIG_ROOT / "students.csv"), # students.csv position max_total_score=repo_conf.max_total_score, stage=result.Stage(sandbox_token=repo_conf.sandbox_token), ) diff --git a/joj3_config_generator/main.py b/joj3_config_generator/main.py index 05d5c07..c8f0ccf 100644 --- a/joj3_config_generator/main.py +++ b/joj3_config_generator/main.py @@ -10,6 +10,7 @@ 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 from joj3_config_generator.models import joj1, repo, task +from joj3_config_generator.models.const import JOJ3_CONFIG_ROOT from joj3_config_generator.utils.logger import logger app = typer.Typer(add_completion=False) @@ -50,8 +51,7 @@ def convert( root: Annotated[ Path, typer.Argument( - help="root directory of config files, " - "located at /home/tt/.config/joj in JTC" + help=f"root directory of config files, located at {JOJ3_CONFIG_ROOT} in JTC" ), ] = Path(".") ) -> None: diff --git a/joj3_config_generator/models/const.py b/joj3_config_generator/models/const.py index 87e9a5a..8bea45b 100644 --- a/joj3_config_generator/models/const.py +++ b/joj3_config_generator/models/const.py @@ -1,5 +1,11 @@ +from pathlib import Path + from joj3_config_generator.models.common import Memory, Time DEFAULT_CPU_LIMIT = Time("1s") DEFAULT_MEMORY_LIMIT = Memory("128m") DEFAULT_FILE_LIMIT = Memory("32m") + +JOJ3_CONFIG_ROOT = Path("/home/tt/.config/joj") +TEAPOT_CONFIG_ROOT = Path("/home/tt/.config/teapot") +CACHE_ROOT = Path("/home/tt/.cache") diff --git a/joj3_config_generator/processers/repo.py b/joj3_config_generator/processers/repo.py index 5b2270d..ebe4bf6 100644 --- a/joj3_config_generator/processers/repo.py +++ b/joj3_config_generator/processers/repo.py @@ -3,13 +3,14 @@ from pathlib import Path from typing import List from joj3_config_generator.models import repo, result +from joj3_config_generator.models.const import CACHE_ROOT, TEAPOT_CONFIG_ROOT def get_teapot_stage(repo_conf: repo.Config) -> result.StageDetail: args = [ "/usr/local/bin/joint-teapot", "joj3-all-env", - "/home/tt/.config/teapot/teapot.env", + str(TEAPOT_CONFIG_ROOT / "teapot.env"), "--grading-repo-name", repo_conf.grading_repo_name, "--max-total-score", @@ -23,7 +24,7 @@ def get_teapot_stage(repo_conf: repo.Config) -> result.StageDetail: with_=result.ExecutorWith( default=result.Cmd( args=args, - env=["LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"], + env=[f"LOG_FILE_PATH={CACHE_ROOT}/joint-teapot-debug.log"], ), cases=[], ), @@ -58,7 +59,7 @@ def get_debug_args(repo_conf: repo.Config) -> List[str]: return [ "/usr/local/bin/joint-teapot", "joj3-check-env", - "/home/tt/.config/teapot/teapot.env", + str(TEAPOT_CONFIG_ROOT / "teapot.env"), "--grading-repo-name", repo_conf.grading_repo_name, "--group-config", @@ -80,7 +81,7 @@ def get_healthcheck_config(repo_conf: repo.Config) -> result.StageDetail: ), result.OptionalCmd( args=get_debug_args(repo_conf), - env=["LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"], + env=[f"LOG_FILE_PATH={CACHE_ROOT}/joint-teapot-debug.log"], ), ], ), diff --git a/joj3_config_generator/processers/task.py b/joj3_config_generator/processers/task.py index 2c8567b..41c91f7 100644 --- a/joj3_config_generator/processers/task.py +++ b/joj3_config_generator/processers/task.py @@ -3,6 +3,7 @@ import shlex from typing import List, Tuple from joj3_config_generator.models import result, task +from joj3_config_generator.models.const import JOJ3_CONFIG_ROOT def get_conf_stage( @@ -36,22 +37,9 @@ def get_conf_stage( def get_executor_with_config( task_stage: task.Stage, cached: List[str] ) -> Tuple[result.ExecutorWith, List[str]]: - file_import = ( - task_stage.files.import_ - if hasattr(task_stage, "files") - and hasattr(task_stage.files, "import_") - and (task_stage.files is not None) - and (task_stage.files.import_ is not None) - else [] - ) + file_import = task_stage.files.import_ copy_in_files = [file for file in file_import if file not in cached] - file_export = ( - task_stage.files.export - if hasattr(task_stage, "files") - and hasattr(task_stage.files, "export") - and (task_stage.files is not None) - else [] - ) + file_export = task_stage.files.export copy_out_files = ["stdout", "stderr"] executor_with_config = result.ExecutorWith( default=result.Cmd( @@ -61,7 +49,7 @@ def get_executor_with_config( else [] ), copy_in={ - file: result.LocalFile(src=f"/home/tt/.config/joj/{file}") + file: result.LocalFile(src=str(JOJ3_CONFIG_ROOT / file)) # all copyin files store in this tools folder # are there any corner cases for file in copy_in_files @@ -213,7 +201,7 @@ def fix_diff( stage_cases.append( result.OptionalCmd( stdin=result.LocalFile( - src=f"/home/tt/.config/joj/{task_conf.task.type_}/{stdin}", + src=str(JOJ3_CONFIG_ROOT / task_conf.task.type_ / stdin), ), args=(shlex.split(command) if command is not None else None), cpu_limit=cpu_limit, @@ -236,7 +224,9 @@ def fix_diff( result.DiffOutputConfig( score=diff_output.score, file_name="stdout", - answer_path=f"/home/tt/.config/joj/{task_conf.task.type_}/{stdout}", + answer_path=str( + JOJ3_CONFIG_ROOT / task_conf.task.type_ / stdout + ), force_quit_on_diff=diff_output.forcequit, always_hide=diff_output.hide, compare_space=not diff_output.ignorespaces,