Compare commits
3 Commits
51b68b7c87
...
04da6667c7
Author | SHA1 | Date | |
---|---|---|---|
04da6667c7 | |||
3b0b36c539 | |||
806bb47a61 |
|
@ -1,3 +1,5 @@
|
|||
from typing import List
|
||||
|
||||
from joj3_config_generator.models import joj1, repo, result, task
|
||||
|
||||
|
||||
|
@ -51,6 +53,40 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config:
|
|||
return result_conf
|
||||
|
||||
|
||||
# TODO: implement me
|
||||
# FIXME: LLM generated convert function, only for demostration
|
||||
def convert_joj1(joj1_conf: joj1.Config) -> task.Config:
|
||||
return task.Config(task="", release=task.Release(deadline=None), stages=[])
|
||||
stages = []
|
||||
for language in joj1_conf.languages:
|
||||
# Here you might want to create a stage for each language
|
||||
# You can define a command based on language properties
|
||||
command = f"run {language.language}"
|
||||
# Assuming we don't have explicit files, we will set empty ones or default behavior
|
||||
files = task.Files(import_=[], export=[])
|
||||
# Score can be derived from the first case or set to a default
|
||||
score = 0
|
||||
parsers: List[str] = [] # Define parsers if applicable
|
||||
if joj1_conf.cases:
|
||||
score = sum(
|
||||
case.score for case in joj1_conf.cases
|
||||
) # Sum scores for all cases
|
||||
# Creating a stage for each language
|
||||
stages.append(
|
||||
task.Stage(
|
||||
name=language.language,
|
||||
command=command,
|
||||
files=files,
|
||||
score=score,
|
||||
parsers=parsers,
|
||||
result_detail=task.ParserResultDetail(), # You can customize this further if needed
|
||||
)
|
||||
)
|
||||
# Assuming no deadline is provided in `joj1`, you can set it accordingly
|
||||
release_deadline = (
|
||||
None # Placeholder for future implementation if deadlines are defined
|
||||
)
|
||||
|
||||
return task.Config(
|
||||
task=joj1_conf.languages[0].language if joj1_conf.languages else "Unnamed Task",
|
||||
release=task.Release(deadline=release_deadline),
|
||||
stages=stages,
|
||||
)
|
||||
|
|
|
@ -5,9 +5,11 @@ from pathlib import Path
|
|||
import inquirer
|
||||
import rtoml
|
||||
import typer
|
||||
import yaml
|
||||
|
||||
from joj3_config_generator.convert import convert as convert_conf
|
||||
from joj3_config_generator.models import RepoConfig, TaskConfig
|
||||
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.utils.logger import logger
|
||||
|
||||
app = typer.Typer(add_completion=False)
|
||||
|
@ -31,11 +33,16 @@ def create(toml: typer.FileTextWrite) -> None:
|
|||
|
||||
|
||||
@app.command()
|
||||
def convert_joj1(yaml: typer.FileText, toml: typer.FileTextWrite) -> None:
|
||||
def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> None:
|
||||
"""
|
||||
Convert a JOJ1 yaml config file to JOJ3 toml config file
|
||||
"""
|
||||
logger.info("Converting")
|
||||
logger.info(f"Converting yaml file {yaml_file}")
|
||||
joj1_obj = yaml.safe_load(yaml_file.read())
|
||||
joj1_model = joj1.Config(**joj1_obj)
|
||||
task_model = convert_joj1_conf(joj1_model)
|
||||
result_dict = task_model.model_dump(by_alias=True)
|
||||
toml_file.write(rtoml.dumps(result_dict))
|
||||
|
||||
|
||||
@app.command()
|
||||
|
@ -54,7 +61,7 @@ def convert(root: Path = Path(".")) -> None:
|
|||
task_toml = task_file.read()
|
||||
repo_obj = rtoml.loads(repo_toml)
|
||||
task_obj = rtoml.loads(task_toml)
|
||||
result_model = convert_conf(RepoConfig(**repo_obj), TaskConfig(**task_obj))
|
||||
result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj))
|
||||
result_dict = result_model.model_dump(by_alias=True)
|
||||
with open(result_json_path, "w") as result_file:
|
||||
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
|
||||
|
|
|
@ -11,10 +11,10 @@ def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any]
|
|||
root = os.path.dirname(os.path.realpath(__file__))
|
||||
task_yaml_path = os.path.join(root, case_name, "task.yaml")
|
||||
task_toml_path = os.path.join(root, case_name, "task.toml")
|
||||
with open(task_yaml_path) as repo_file:
|
||||
task_yaml = repo_file.read()
|
||||
with open(task_toml_path) as task_file:
|
||||
task_toml = task_file.read()
|
||||
with open(task_yaml_path) as f:
|
||||
task_yaml = f.read()
|
||||
with open(task_toml_path) as f:
|
||||
task_toml = f.read()
|
||||
joj1_obj = yaml.safe_load(task_yaml)
|
||||
task_obj = rtoml.loads(task_toml)
|
||||
return joj1.Config(**joj1_obj), task_obj
|
||||
|
|
Loading…
Reference in New Issue
Block a user