Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
712u3 committed Nov 15, 2023
1 parent 2cdc0c4 commit a9e41f3
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions frontik/dependency_manager/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
make_stub_dependency,
)
from frontik.preprocessors import (
DependencyGroupMarker,
Preprocessor,
get_all_preprocessors_functions,
get_simple_preprocessors_functions,
make_full_name,
)

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
Expand All @@ -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
Expand Down

0 comments on commit a9e41f3

Please sign in to comment.