dynamic imports

This commit is contained in:
elleven11 2023-04-11 22:54:40 -04:00
parent a427869f1a
commit e07aa1d253

View File

@ -1,32 +1,33 @@
from typing import List
from .executor_types import ExecuteResult, Executor
from .leetcode_env.leetcode_env.utils import SubmissionFormatter
from .leetcode_env.leetcode_env.environment import LeetCodeEnv
from .leetcode_env.leetcode_env.leetcode_types import ProgrammingLanguage, LeetCodeSubmission
from .leetcode_env.leetcode_env.utils import id_from_slug
class LeetExecutor(Executor):
from .leetcode_env.leetcode_env.utils import SubmissionFormatter
from .leetcode_env.leetcode_env.leetcode_types import ProgrammingLanguage
def __init__(self, lang: ProgrammingLanguage, executor: Executor, formatter: SubmissionFormatter):
from .leetcode_env.leetcode_env.environment import LeetCodeEnv
self.lang = lang
self.executor = executor
self.formatter = formatter
self.env = LeetCodeEnv()
def execute(self, func: str, tests: List[str], timeout: int = 5) -> ExecuteResult:
return self.executor.execute(func, tests, timeout)
def evaluate(self, name: str, func: str, test: str, timeout: int = 5) -> bool:
from .leetcode_env.leetcode_env.utils import id_from_slug
from .leetcode_env.leetcode_env.leetcode_types import LeetCodeSubmission
submission = LeetCodeSubmission(
code = self.formatter.to_leetcode(func),
lang = self.lang,
question_id = id_from_slug(name, self.env.api_instance),
question_slug = name,
timeout = timeout
code=self.formatter.to_leetcode(func),
lang=self.lang,
question_id=id_from_slug(name, self.env.api_instance),
question_slug=name,
timeout=timeout
)
_, reward, _, _ = self.env.step(submission)
return reward