Fixed #18 : Parsing and evaluating Python
This commit is contained in:
+33
-13
@@ -10,21 +10,21 @@ from caching.Cache import Cache
|
||||
from caching.IncCache import IncCache
|
||||
from common.utils import get_logger_name, get_sub_classes, import_module_and_sub_module
|
||||
from core.BuiltinConcepts import BuiltinConcepts
|
||||
from core.ErrorContext import ErrorContext
|
||||
from core.Event import Event
|
||||
from core.ExecutionContext import ContextHint, ExecutionContext, ExecutionContextActions
|
||||
from core.ExecutionContext import ContextHint, ExecutionContext, ContextActions
|
||||
from core.ReturnValue import ReturnValue
|
||||
from core.concept import Concept, ConceptMetadata
|
||||
from core.error import ErrorContext
|
||||
from ontologies.SheerkaOntologyManager import SheerkaOntologyManager
|
||||
from server.authentication import User
|
||||
|
||||
EXECUTE_STEPS = [
|
||||
ExecutionContextActions.BEFORE_PARSING,
|
||||
ExecutionContextActions.PARSING,
|
||||
ExecutionContextActions.AFTER_PARSING,
|
||||
ExecutionContextActions.BEFORE_EVALUATION,
|
||||
ExecutionContextActions.EVALUATION,
|
||||
ExecutionContextActions.AFTER_EVALUATION
|
||||
ContextActions.BEFORE_PARSING,
|
||||
ContextActions.PARSING,
|
||||
ContextActions.AFTER_PARSING,
|
||||
ContextActions.BEFORE_EVALUATION,
|
||||
ContextActions.EVALUATION,
|
||||
ContextActions.AFTER_EVALUATION
|
||||
]
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ class Sheerka:
|
||||
self.om = SheerkaOntologyManager(self, root_folder)
|
||||
# self.builtin_cache, self.builtin_cache_by_class_name = self.get_builtins_classes_as_dict()
|
||||
|
||||
self.initialize_bind_methods()
|
||||
self.initialize_caching()
|
||||
self.initialize_evaluators()
|
||||
self.initialize_services()
|
||||
@@ -133,7 +134,7 @@ class Sheerka:
|
||||
with ExecutionContext(self.name,
|
||||
event,
|
||||
self,
|
||||
ExecutionContextActions.INIT_SHEERKA,
|
||||
ContextActions.INIT_SHEERKA,
|
||||
None,
|
||||
desc="Initializing Sheerka.") as exec_context:
|
||||
if self.om.current_sdp().first_time:
|
||||
@@ -165,6 +166,14 @@ class Sheerka:
|
||||
|
||||
return res
|
||||
|
||||
def initialize_bind_methods(self):
|
||||
"""
|
||||
Add some methods to the list of available methods
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
self.bind_service_method(self.name, self.echo, False)
|
||||
|
||||
@staticmethod
|
||||
def initialize_logging(is_debug, root_folder):
|
||||
if is_debug:
|
||||
@@ -206,9 +215,9 @@ class Sheerka:
|
||||
"""
|
||||
self.init_log.info("Initializing services")
|
||||
|
||||
import_module_and_sub_module('core.services')
|
||||
base_class = "core.services.BaseService.BaseService"
|
||||
services = [service(self) for service in get_sub_classes("core.services", base_class)]
|
||||
import_module_and_sub_module('services')
|
||||
base_class = "services.BaseService.BaseService"
|
||||
services = [service(self) for service in get_sub_classes("services", base_class)]
|
||||
services.sort(key=attrgetter("order"))
|
||||
for service in services:
|
||||
if hasattr(service, "initialize"):
|
||||
@@ -282,7 +291,7 @@ class Sheerka:
|
||||
with ExecutionContext(user.email,
|
||||
event,
|
||||
self,
|
||||
ExecutionContextActions.EVALUATE_USER_INPUT,
|
||||
ContextActions.EVALUATE_USER_INPUT,
|
||||
command,
|
||||
desc=f"Evaluating '{command}'",
|
||||
global_hints=self.global_context_hints.copy()) as exec_context:
|
||||
@@ -322,3 +331,14 @@ class Sheerka:
|
||||
return a.id == b[3:-1]
|
||||
|
||||
return a.key == b
|
||||
|
||||
def echo(self, msg):
|
||||
"""
|
||||
test function
|
||||
:param msg:
|
||||
:type msg:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
return msg
|
||||
|
||||
Reference in New Issue
Block a user