Enhanced sheerka.update_concept() logs

This commit is contained in:
2019-12-27 11:33:16 +01:00
parent 26daae4acf
commit 21da87393f
5 changed files with 49 additions and 20 deletions
+25 -15
View File
@@ -367,7 +367,7 @@ class Sheerka(Concept):
sub_context = execution_context.push(step=step)
sub_context.log(logger or self.log, f"{step=}, context='{sub_context}'")
copy = return_values[:] if hasattr(return_values, "__iter__") else return_values
copy = return_values[:] if hasattr(return_values, "__iter__") else [return_values]
if step == BuiltinConcepts.PARSING:
return_values = self._call_parsers(sub_context, return_values, logger)
@@ -428,6 +428,7 @@ class Sheerka(Concept):
concept_lexer_parser = self.parsers[CONCEPT_LEXER_PARSER_CLASS]()
sub_context = context.push(self.name, desc=f"Initializing concept definition for {concept}")
sub_context.concepts[concept.key] = concept # the concept is not in the real cache yet
sub_context.log_new(logger)
init_ret_value = concept_lexer_parser.initialize(sub_context, concepts_definitions)
if not init_ret_value.status:
return self.ret(self.create_new_concept.__name__, False, ErrorConcept(init_ret_value.value))
@@ -494,7 +495,6 @@ class Sheerka(Concept):
:param logger:
:return:
"""
# steps = [BuiltinConcepts.BEFORE_PARSING, BuiltinConcepts.PARSING, BuiltinConcepts.AFTER_PARSING]
steps = [BuiltinConcepts.BEFORE_PARSING, BuiltinConcepts.PARSING, BuiltinConcepts.AFTER_PARSING]
for part_key in ConceptParts:
source = getattr(concept.metadata, part_key.value)
@@ -503,8 +503,10 @@ class Sheerka(Concept):
# I refuse empty strings for performance matters, I don't want to handle useless NOPConcepts
continue
else:
sub_context = context.push(desc=f"Initializing AST for {part_key}")
sub_context.log_new(logger)
to_parse = self.ret(context.who, True, self.new(BuiltinConcepts.USER_INPUT, body=source))
concept.cached_asts[part_key] = self.execute(context, to_parse, steps, logger)
concept.cached_asts[part_key] = self.execute(sub_context, to_parse, steps, logger)
for prop in concept.props:
if concept.props[prop].value:
@@ -512,6 +514,8 @@ class Sheerka(Concept):
context.who,
True,
self.new(BuiltinConcepts.USER_INPUT, body=concept.props[prop].value))
sub_context = context.push(desc=f"Initializing AST for property {prop}")
sub_context.log_new(logger)
concept.cached_asts[prop] = self.execute(context, to_parse, steps)
# Updates the cache of concepts when possible
@@ -533,11 +537,17 @@ class Sheerka(Concept):
:return: value of the evaluation or error
"""
logger = logger or self.log
if concept.metadata.is_evaluated:
return concept
def _resolve(resolve_context, return_value):
r = self.execute(resolve_context, return_value, CONCEPT_EVALUATION_STEPS, logger or self.log)
def _resolve(return_value, desc, obj):
context.log(logger, desc, self.evaluate_concept.__name__)
sub_context = context.push(desc=desc, obj=obj)
sub_context.add_preprocess(self.get_evaluator_name("Concept"), return_body=True)
sub_context.log_new(logger)
r = self.execute(sub_context, return_value, CONCEPT_EVALUATION_STEPS, logger)
return core.builtin_helpers.expect_one(context, r)
# WHERE condition should already be validated by the parser.
@@ -548,6 +558,7 @@ class Sheerka(Concept):
#
if len(concept.cached_asts) == 0:
context.log(logger, "concept asts are not initialized. Initializing.", self.evaluate_concept.__name__)
self.initialize_concept_asts(context, concept, logger)
# to make sure of the order, it don't use ConceptParts.get_parts()
@@ -557,9 +568,7 @@ class Sheerka(Concept):
for metadata_to_eval in all_metadata_to_eval:
if metadata_to_eval == "props":
for prop_name in (p for p in concept.props if p in concept.cached_asts):
sub_context = context.push(desc=f"Evaluating property '{prop_name}'")
sub_context.add_preprocess(self.get_evaluator_name("Concept"), return_body=True)
res = _resolve(sub_context, concept.cached_asts[prop_name])
res = _resolve(concept.cached_asts[prop_name], f"Evaluating property '{prop_name}'", None)
if res.status:
concept.set_prop(prop_name, res.value)
else:
@@ -571,9 +580,7 @@ class Sheerka(Concept):
part_key = ConceptParts(metadata_to_eval)
if part_key in concept.cached_asts and concept.cached_asts[part_key] is not None:
sub_context = context.push(desc=f"Evaluating '{part_key}'", obj=concept)
sub_context.add_preprocess(self.get_evaluator_name("Concept"), return_body=True)
res = _resolve(sub_context, concept.cached_asts[part_key])
res = _resolve(concept.cached_asts[part_key], f"Evaluating '{part_key}'", concept)
if res.status:
setattr(concept.metadata, metadata_to_eval, res.value)
else:
@@ -833,10 +840,13 @@ class Sheerka(Concept):
self.log.info(defs)
def dump_desc(self, concept_name):
c = self.get(concept_name)
if self.isinstance(c, BuiltinConcepts.UNKNOWN_CONCEPT):
self.log.error("Concept unknown")
return False
if isinstance(concept_name, Concept):
c = concept_name
else:
c = self.get(concept_name)
if self.isinstance(c, BuiltinConcepts.UNKNOWN_CONCEPT):
self.log.error("Concept unknown")
return False
self.log.info(f"name : {c.name}")
self.log.info(f"bnf : {c.metadata.definition}")