Fixed RET functionnality misbehaviour

This commit is contained in:
2020-07-08 13:35:18 +02:00
parent c4399d631c
commit b768eaa95d
14 changed files with 113 additions and 29 deletions
+8 -3
View File
@@ -3,7 +3,8 @@ import time
from core.builtin_concepts import BuiltinConcepts
from core.sheerka.services.sheerka_service import BaseService
CONCEPTS_FILE = "_concepts.txt"
CONCEPTS_FILE = "_concepts_lite.txt"
CONCEPTS_FILE_ALL_CONCEPTS = "_concepts.txt"
class SheerkaAdmin(BaseService):
@@ -37,15 +38,19 @@ class SheerkaAdmin(BaseService):
return self.sheerka.cache_manager.caches[name].cache.copy()
def restore(self):
def restore(self, concept_file=CONCEPTS_FILE):
"""
Restore the state with all previous valid concept definitions
:return:
"""
if concept_file == "full":
concept_file = CONCEPTS_FILE_ALL_CONCEPTS
try:
start = time.time_ns()
self.sheerka.during_restore = True
with open(CONCEPTS_FILE, "r") as f:
with open(concept_file, "r") as f:
for line in f.readlines():
line = line.strip()
if line == "" or line.startswith("#"):
@@ -43,6 +43,16 @@ class SheerkaEvaluateConcept(BaseService):
return None
@staticmethod
def apply_ret(concept):
"""
Check if a concept has its RET part defined
If True, returns it
:param concept:
:return:
"""
return concept.get_value(ConceptParts.RET) if ConceptParts.RET in concept.values else concept
def manage_infinite_recursion(self, context):
"""
We look for the fist parent that has a body that means something
@@ -189,7 +199,7 @@ class SheerkaEvaluateConcept(BaseService):
evaluated = self.evaluate_concept(sub_context, to_resolve)
sub_context.add_values(return_values=evaluated)
if evaluated.key == to_resolve.key:
return evaluated
return self.apply_ret(evaluated)
else:
error = evaluated
@@ -324,9 +334,9 @@ class SheerkaEvaluateConcept(BaseService):
concept.init_key() # only does it if needed
concept.metadata.is_evaluated = "body" in all_metadata_to_eval
# # update the cache for concepts with no variable
# if len(concept.metadata.variables) == 0:
# self.sheerka.cache_manager.put(self.sheerka.CONCEPTS_BY_ID_ENTRY, concept.id, concept)
# update the cache for concepts with no variable
if len(concept.metadata.variables) == 0:
self.sheerka.cache_manager.put(self.sheerka.CONCEPTS_BY_ID_ENTRY, concept.id, concept)
return concept
+15 -4
View File
@@ -434,11 +434,22 @@ class SheerkaFilter(BaseService):
pass
def pipe_inspect(self, iterable, path, when=None):
compiled = self.get_compiled("inspect", path)
"""
Follow the path
:param iterable:
:param path:
:param when:
:return:
"""
# quick and dirty implementation as it does not handle dictionaries items
for item in iterable:
try:
context = {} if is_primitive(item) else as_bag(item)
context["self"] = item
yield eval(compiled, context)
props = path.split(".")
for prop in props:
compiled = self.get_compiled("inspect", prop)
context = {} if is_primitive(item) else as_bag(item)
item = eval(compiled, context)
yield item
except Exception as ex:
yield ex
+10
View File
@@ -6,6 +6,16 @@ import re
from core.tokenizer import TokenKind
def my_debug(*args):
with open("debug.txt", "a") as f:
for arg in args:
if isinstance(arg, list):
for item in arg:
f.write(f"{item}\n")
else:
f.write(f"{arg}\n")
def sysarg_to_string(argv):
"""
Transform a list of strings into a single string