JOJ3-config-generator/joj3_config_generator/convert.py
张泊明518370910136 10f2d5c94b
All checks were successful
build / build (push) Successful in 2m29s
build / build (pull_request) Successful in 2m28s
style: rename
2025-03-02 14:35:03 -05:00

67 lines
2.4 KiB
Python

import os
from pathlib import Path
from typing import List
from joj3_config_generator.models import joj1, repo, result, task
from joj3_config_generator.processers.joj1 import get_joj1_run_stage
from joj3_config_generator.processers.repo import (
get_healthcheck_config,
get_teapot_stage,
)
from joj3_config_generator.processers.task import (
fix_diff,
fix_dummy,
fix_file,
fix_keyword,
fix_result_detail,
get_conf_stage,
get_executor_with_config,
)
def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config:
# Create the base ResultConf object
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",
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
max_total_score=repo_conf.max_total_score,
stage=result.Stage(sandbox_token=repo_conf.sandbox_token),
)
current_test = os.environ.get("PYTEST_CURRENT_TEST") is not None
# Construct healthcheck stage
if not repo_conf.force_skip_health_check_on_test or not current_test:
result_conf.stage.stages.append(get_healthcheck_config(repo_conf))
cached: List[str] = []
# Convert each stage in the task configuration
for task_stage in task_conf.stages:
executor_with_config, cached = get_executor_with_config(task_stage, cached)
conf_stage = get_conf_stage(task_stage, executor_with_config)
conf_stage = fix_result_detail(task_stage, conf_stage)
conf_stage = fix_dummy(task_stage, conf_stage)
conf_stage = fix_keyword(task_stage, conf_stage)
conf_stage = fix_file(task_stage, conf_stage)
conf_stage = fix_diff(task_stage, conf_stage, task_conf)
result_conf.stage.stages.append(conf_stage)
if not repo_conf.force_skip_teapot_on_test or not current_test:
result_conf.stage.post_stages.append(get_teapot_stage(repo_conf))
return result_conf
def convert_joj1(joj1_conf: joj1.Config) -> task.Config:
stages = [get_joj1_run_stage(joj1_conf)]
return task.Config(
root=Path(""),
path=Path(""),
task=task.Task(
name=(""),
),
release=task.Release(),
stages=stages,
)