Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter connectors whitelist before load call to avoid unnecessary connectors imports #77

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/dl_api_lib/dl_api_lib/app/data_api/resources/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class PingReadyView(BaseView):
async def is_pg_ready(self) -> bool:
compeng: CompEngPgService = CompEngPgService.get_app_instance(self.request.app)
processor = compeng.get_data_processor(
service_registry=self.dl_request.services_registry, reporting_enabled=False,
service_registry=self.dl_request.services_registry,
reporting_enabled=False,
)

try:
Expand Down
4 changes: 1 addition & 3 deletions lib/dl_api_lib/dl_api_lib/app_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class ApiConnectorEntrypointManager(EntrypointClassManager[ApiConnector]):


def register_all_connectors(connector_ep_names: Optional[Collection[str]] = None) -> None:
connectors = ApiConnectorEntrypointManager().get_all_ep_classes()
connectors = ApiConnectorEntrypointManager().get_all_ep_classes(connector_ep_names)
for ep_name, connector_cls in sorted(connectors.items()):
if connector_ep_names is not None and ep_name not in connector_ep_names:
continue
CONN_REG_BI_API.register_connector(connector_cls)
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
from dl_core_testing.testcases.service_base import DbServiceFixtureTextClass
from dl_testing.regulated_test import (
Feature,
for_features,
RegulatedTestCase,
for_features,
)


class DefaultBasicExtAggregationTestSuite(RegulatedTestCase, DataApiTestBase, DatasetTestBase, DbServiceFixtureTextClass):
class DefaultBasicExtAggregationTestSuite(
RegulatedTestCase, DataApiTestBase, DatasetTestBase, DbServiceFixtureTextClass
):
def test_lod_fixed_single_dim_in_two_dim_query(self, control_api, data_api, saved_dataset):
ds = add_formulas_to_dataset(
api_v1=control_api,
Expand Down Expand Up @@ -264,7 +266,9 @@ def get_data(order_by: list[ResultField]) -> list:
assert ordered_data_rows == data_rows


class DefaultBasicLookupFunctionTestSuite(RegulatedTestCase, DataApiTestBase, DatasetTestBase, DbServiceFixtureTextClass):
class DefaultBasicLookupFunctionTestSuite(
RegulatedTestCase, DataApiTestBase, DatasetTestBase, DbServiceFixtureTextClass
):
def test_ago_any_db(self, request, saved_connection_id, control_api, data_api, db):
db_table = make_table(db=db)
request.addfinalizer(functools.partial(db.drop_table, db_table.table))
Expand Down Expand Up @@ -460,7 +464,9 @@ def test_month_ago_for_shorter_month(self, request, db, saved_connection_id, con
assert len(data_rows) == 1


class DefaultBasicWindowFunctionTestSuite(RegulatedTestCase, DataApiTestBase, DatasetTestBase, DbServiceFixtureTextClass):
class DefaultBasicWindowFunctionTestSuite(
RegulatedTestCase, DataApiTestBase, DatasetTestBase, DbServiceFixtureTextClass
):
feature_window_functions = Feature("window_functions")

@for_features(feature_window_functions)
Expand Down
10 changes: 7 additions & 3 deletions lib/dl_core/dl_core/connectors/registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Type
from typing import (
Collection,
Optional,
Type,
)

import attr

Expand All @@ -15,9 +19,9 @@ class CoreConnectorEntrypointManager(EntrypointClassManager[CoreConnector]):
entrypoint_group_name = attr.ib(init=False, default=_CONNECTOR_EP_GROUP)


def get_all_connectors() -> dict[str, Type[CoreConnector]]:
def get_all_connectors(ep_filter: Optional[Collection[str]] = None) -> dict[str, Type[CoreConnector]]:
ep_mgr = CoreConnectorEntrypointManager()
return ep_mgr.get_all_ep_classes()
return ep_mgr.get_all_ep_classes(ep_filter)


def get_connector_cls(name: str) -> Type[CoreConnector]:
Expand Down
4 changes: 1 addition & 3 deletions lib/dl_core/dl_core/core_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ def load_all_connectors() -> None:


def register_all_connectors(connector_ep_names: Optional[Collection[str]] = None) -> None:
for ep_name, connector_cls in sorted(get_all_connectors().items()):
if connector_ep_names is not None and ep_name not in connector_ep_names:
continue
for ep_name, connector_cls in sorted(get_all_connectors(connector_ep_names).items()):
_register_connector(connector_cls)
Empty file.
19 changes: 12 additions & 7 deletions lib/dl_formula/dl_formula/formula_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@
Type,
)

import attr

import dl_formula as package
from dl_formula.connectors.base.connector import FormulaConnector
from dl_formula.connectors.registration import CONN_REG_FORMULA
from dl_utils.entrypoints import EntrypointClassManager


_CONNECTOR_EP_GROUP = f"{package.__name__}.connectors"


def _get_all_ep_connectors() -> dict[str, Type[FormulaConnector]]:
entrypoints = list(metadata.entry_points().select(group=_CONNECTOR_EP_GROUP)) # type: ignore
return {ep.name: ep.load() for ep in entrypoints}
@attr.s
class FormulaConnectorEntrypointManager(EntrypointClassManager[FormulaConnector]):
entrypoint_group_name = attr.ib(init=False, default=_CONNECTOR_EP_GROUP)


def _get_all_ep_connectors(ep_filter: Optional[Collection[str]] = None) -> dict[str, Type[FormulaConnector]]:
ep_mgr = FormulaConnectorEntrypointManager()
return ep_mgr.get_all_ep_classes(ep_filter)


def load_all_connectors() -> None:
_get_all_ep_connectors()


def register_all_connectors(connector_ep_names: Optional[Collection[str]] = None) -> None:
connectors = _get_all_ep_connectors()
for ep_name, connector_cls in sorted(connectors.items()):
if connector_ep_names is not None and ep_name not in connector_ep_names:
continue
for ep_name, connector_cls in sorted(_get_all_ep_connectors(connector_ep_names).items()):
CONN_REG_FORMULA.register_connector(connector_cls)
1 change: 1 addition & 0 deletions lib/dl_formula/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jinja2 = ">=3.1.2"
python = ">=3.10, <3.12"
pytz = ">=2022.7.1"
sqlalchemy = ">=1.4.46, <2.0"
datalens-utils = {path = "../dl_utils"}
dynamic-enum = {path = "../dynamic_enum"}

[tool.poetry.group]
Expand Down
6 changes: 5 additions & 1 deletion lib/dl_utils/dl_utils/entrypoints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import abc
from importlib import metadata
from typing import (
Collection,
Generic,
Optional,
Type,
TypeVar,
)
Expand All @@ -20,8 +22,10 @@ class EntrypointClassManager(abc.ABC, Generic[_EP_CLS_TV]):

entrypoint_group_name: str = attr.ib(kw_only=True)

def get_all_ep_classes(self) -> dict[str, Type[_EP_CLS_TV]]:
def get_all_ep_classes(self, ep_filter: Optional[Collection[str]] = None) -> dict[str, Type[_EP_CLS_TV]]:
entrypoints = list(metadata.entry_points().select(group=self.entrypoint_group_name)) # type: ignore
if ep_filter is not None:
entrypoints = [ep for ep in entrypoints if ep.name in ep_filter]
return {ep.name: ep.load() for ep in entrypoints}

def get_ep_class(self, name: str) -> Type[_EP_CLS_TV]:
Expand Down
1 change: 0 additions & 1 deletion lib/dl_utils/dl_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Generator,
Iterable,
List,
NoReturn,
Optional,
Tuple,
Type,
Expand Down
11 changes: 1 addition & 10 deletions metapkg/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions terrarium/bi_ci/bi_ci/execute_mypy_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from pathlib import Path
import subprocess
import sys
from typing import (
Iterable,
)
from typing import Iterable

import clize
import tomlkit
Expand Down
Loading