summaryrefslogtreecommitdiff
path: root/yaksh/language_registry.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/language_registry.py')
-rw-r--r--yaksh/language_registry.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py
index ee311ec..512e2f5 100644
--- a/yaksh/language_registry.py
+++ b/yaksh/language_registry.py
@@ -1,21 +1,31 @@
from settings import code_evaluators
import importlib
+import json
registry = None
# def set_registry():
# global registry
# registry = _LanguageRegistry()
-
-def _set_registry():
+
+def get_registry(): #@@@get_evaluator_registry
global registry
if registry is None:
registry = _LanguageRegistry()
return registry
-
-def get_registry():
- registry = _set_registry()
- return registry
+
+def unpack_json(json_data):
+ data = json.loads(json_data)
+ return data
+
+def create_evaluator_instance(language, test_case_type, json_data, in_dir):
+ """Create instance of relevant EvaluateCode class based on language"""
+ # set_registry()
+ registry = get_registry()
+ cls = registry.get_class(language, test_case_type) #@@@get_evaluator_for_language
+ instance = cls(in_dir)
+ # instance = cls.from_json(language, json_data, in_dir)
+ return instance
class _LanguageRegistry(object):
def __init__(self):
@@ -24,12 +34,13 @@ class _LanguageRegistry(object):
self._register[language] = None
# Public Protocol ##########
- def get_class(self, language):
+ def get_class(self, language, test_case_type):
""" Get the code evaluator class for the given language """
if not self._register.get(language):
self._register[language] = code_evaluators.get(language)
- cls = self._register[language]
+ test_case_register = self._register[language]
+ cls = test_case_register.get(test_case_type)
module_name, class_name = cls.rsplit(".", 1)
# load the module, will raise ImportError if module cannot be loaded
get_module = importlib.import_module(module_name)