diff --git a/frontik/dependency_manager/graph_builder.py b/frontik/dependency_manager/graph_builder.py index 3959ef6a8..65fa889ef 100644 --- a/frontik/dependency_manager/graph_builder.py +++ b/frontik/dependency_manager/graph_builder.py @@ -13,6 +13,7 @@ make_stub_dependency, ) from frontik.preprocessors import ( + DependencyGroupMarker, Preprocessor, get_all_preprocessors_functions, get_simple_preprocessors_functions, @@ -20,12 +21,12 @@ ) if TYPE_CHECKING: - from collections.abc import Callable, Iterable + from collections.abc import Callable, Generator, Iterable from frontik.handler import PageHandler -def build_sub_graph(handler: PageHandler, functions_to_run: list) -> DependencyGraph: +def build_sub_graph(handler: PageHandler, dependencies_to_run: list) -> DependencyGraph: """ building sub_graph duplicated dependencies will be taken from main graph @@ -37,16 +38,32 @@ def build_sub_graph(handler: PageHandler, functions_to_run: list) -> DependencyG sub_graph.known_deps = main_graph.known_deps # collect dependencies which defined explicitly - _register_side_dependencies(sub_graph, root_dep, functions_to_run, deep_scan=False) + shallow_dependencies = _get_shallow_functions(dependencies_to_run) + _register_side_dependencies(sub_graph, root_dep, shallow_dependencies, deep_scan=False) # collect all dependencies with deep_scan - _register_side_dependencies(sub_graph, root_dep, functions_to_run, deep_scan=True) + all_dependencies = _get_all_functions(dependencies_to_run) + _register_side_dependencies(sub_graph, root_dep, all_dependencies, deep_scan=True) _set_priority_links(handler.__class__._priority_dependency_names, sub_graph) sub_graph.build_topological_sorter() return sub_graph +def _get_shallow_functions(dependencies_to_run: list) -> Generator: + for dependency_item in dependencies_to_run: + if not isinstance(dependency_item, DependencyGroupMarker): + yield dependency_item + + +def _get_all_functions(dependencies_to_run: list) -> Generator: + for dependency_item in dependencies_to_run: + if isinstance(dependency_item, DependencyGroupMarker): + yield from dependency_item.deps + else: + yield dependency_item + + def get_dependency_graph(page_method_func: Callable, handler_cls: type) -> DependencyGraph: """ build meta_graph or make deepcopy as main_graph if meta_graph existed