|
5 | 5 | import asyncio |
6 | 6 | import logging |
7 | 7 | import uuid |
8 | | -from contextvars import ContextVar |
9 | 8 | from typing import Optional |
10 | 9 |
|
11 | 10 | from efoli import EdifactFormat, EdifactFormatVersion |
|
24 | 23 |
|
25 | 24 |
|
26 | 25 | try: |
27 | | - import inject |
28 | | - from ahbicht.content_evaluation.evaluationdatatypes import EvaluatableData, EvaluatableDataProvider |
29 | | - from ahbicht.content_evaluation.evaluator_factory import create_content_evaluation_result_based_evaluators |
| 26 | + from ahbicht.content_evaluation.ahb_context import AhbContext |
30 | 27 | from ahbicht.content_evaluation.expression_check import is_valid_expression |
31 | | - from ahbicht.content_evaluation.token_logic_provider import SingletonTokenLogicProvider, TokenLogicProvider |
32 | 28 | from ahbicht.expressions.condition_expression_parser import extract_categorized_keys |
33 | | - from ahbicht.models.content_evaluation_result import ContentEvaluationResult |
34 | 29 | from lark.exceptions import VisitError |
35 | 30 | except ImportError as import_error: |
36 | 31 | import_error.msg += "; Did you install fundamend[sqlmodels,ahbicht]?" |
|
39 | 34 |
|
40 | 35 | _logger = logging.getLogger(__name__) |
41 | 36 |
|
42 | | -_content_evaluation_result: ContextVar[Optional[ContentEvaluationResult]] = ContextVar( |
43 | | - "_content_evaluation_result", default=None |
44 | | -) |
45 | | - |
46 | | - |
47 | | -def _get_evaluatable_data() -> EvaluatableData[ContentEvaluationResult]: |
48 | | - """ |
49 | | - returns the _content_evaluation_result context var value wrapped in a EvaluatableData container. |
50 | | - This is the kind of data that the ContentEvaluationResultBased RC/FC Evaluators, HintsProvider and Package Resolver |
51 | | - require. |
52 | | - :return: |
53 | | - """ |
54 | | - cer = _content_evaluation_result.get() |
55 | | - assert cer is not None |
56 | | - return EvaluatableData( |
57 | | - body=cer, |
58 | | - edifact_format=EdifactFormat.UTILMD, # not important, something has to be here |
59 | | - edifact_format_version=EdifactFormatVersion.FV2504, # not important, something has to be here |
60 | | - ) |
61 | | - |
62 | | - |
63 | | -def _setup_weird_ahbicht_dependency_injection() -> None: |
64 | | - def configure(binder: inject.Binder) -> None: |
65 | | - binder.bind( |
66 | | - TokenLogicProvider, |
67 | | - SingletonTokenLogicProvider( |
68 | | - [*create_content_evaluation_result_based_evaluators(EdifactFormat.UTILMD, EdifactFormatVersion.FV2504)] |
69 | | - ), |
70 | | - ) |
71 | | - binder.bind_to_provider(EvaluatableDataProvider, _get_evaluatable_data) |
72 | | - |
73 | | - inject.configure_once(configure) |
74 | | - |
75 | 37 |
|
76 | 38 | def _generate_node_texts(session: Session, expression: str, ahb_pk: uuid.UUID) -> str: |
77 | 39 | categorized_key_extract = asyncio.run(extract_categorized_keys(expression)) |
@@ -120,7 +82,9 @@ def _get_validity_node_texts_and_error_message_cpu_intensive( |
120 | 82 | expression: str, session: Session, anwendungshandbuch_pk: uuid.UUID |
121 | 83 | ) -> tuple[bool, str, str | None]: |
122 | 84 | try: |
123 | | - is_valid, error_message = asyncio.run(is_valid_expression(expression, _content_evaluation_result.set)) |
| 85 | + is_valid, error_message = asyncio.run( |
| 86 | + is_valid_expression(expression, EdifactFormat.UTILMD, EdifactFormatVersion.FV2504) |
| 87 | + ) |
124 | 88 | if is_valid: # we might actually get a meaningful node_texts even for invalid expressions, but I don't like it |
125 | 89 | node_texts = _generate_node_texts(session, expression, anwendungshandbuch_pk) |
126 | 90 | else: |
@@ -157,7 +121,6 @@ def create_and_fill_ahb_expression_table(session: Session, use_cpu_intensive_val |
157 | 121 | outcomes. This leads to only few additional expressions marked as invalid but is very slow. |
158 | 122 | """ |
159 | 123 | rows: list[tuple[EdifactFormatVersion | None, str, str | None, uuid.UUID]] = [] |
160 | | - _setup_weird_ahbicht_dependency_injection() |
161 | 124 | for ahb_status_col in [ |
162 | 125 | AhbHierarchyMaterialized.segmentgroup_ahb_status, |
163 | 126 | AhbHierarchyMaterialized.segment_ahb_status, |
|
0 commit comments