-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.py
41 lines (34 loc) · 1.3 KB
/
factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from .lua_executor import LuaExecutor
from .py_executor import PyExecutor
from .rs_executor import RsExecutor
from .executor_types import Executor
from .leet_executor import LeetExecutor
def executor_factory(lang: str, is_leet: bool = False) -> Executor:
base = base_executor_factory(lang)
if is_leet:
return leet_executor_factory(lang)
else:
return base
def leet_executor_factory(lang: str) -> Executor:
from .leetcode_env.leetcode_env.leetcode_types import ProgrammingLanguage
from .leetcode_env.leetcode_env.utils import PySubmissionFormatter, RsSubmissionFormatter
pl = None
sf = None
if lang == "py" or lang == "python":
pl = ProgrammingLanguage.PYTHON3
sf = PySubmissionFormatter
elif lang == "rs" or lang == "rust":
pl = ProgrammingLanguage.RUST
sf = RsSubmissionFormatter
else:
raise ValueError(f"Invalid language for leetcode executor: {lang}")
return LeetExecutor(pl, base_executor_factory(lang), sf)
def base_executor_factory(lang: str) -> Executor:
if lang == "py" or lang == "python":
return PyExecutor()
elif lang == "rs" or lang == "rust":
return RsExecutor()
elif lang == "lua":
return LuaExecutor()
else:
raise ValueError(f"Invalid language for executor: {lang}")