From 42a869124789082caacdbed1c4f670d53955ae29 Mon Sep 17 00:00:00 2001 From: "d.zakharchuk" Date: Tue, 23 Jan 2024 14:43:34 +0200 Subject: [PATCH] add dummy clients --- README.md | 2 +- examples/http/aiohttp_client.py | 4 +- examples/http/httpx_client.py | 4 +- examples/http/requests_client.py | 2 + featureflags_client/http/managers/dummy.py | 73 ++++++++++++++++++++++ pdm.lock | 28 ++++----- pyproject.toml | 4 +- 7 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 featureflags_client/http/managers/dummy.py diff --git a/README.md b/README.md index b6a4115..42fed52 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Installation To install package: -- ``pdm add evo-featureflags-protobuf`` +- ``pdm add evo-featureflags-client`` To release package: diff --git a/examples/http/aiohttp_client.py b/examples/http/aiohttp_client.py index 6f57f8e..f5b5d86 100644 --- a/examples/http/aiohttp_client.py +++ b/examples/http/aiohttp_client.py @@ -16,11 +16,13 @@ async def on_start(app): project=config.FF_PROJECT, variables=[flags.REQUEST_QUERY], defaults=flags.Defaults, + request_timeout=5, + refresh_interval=10, ) app["ff_client"] = FeatureFlagsClient(app["ff_manager"]) try: - await app["ff_client"].preload_async(timeout=5) + await app["ff_client"].preload_async() except Exception: log.exception( "Unable to preload feature flags, application will " diff --git a/examples/http/httpx_client.py b/examples/http/httpx_client.py index 5df7c33..7782ace 100644 --- a/examples/http/httpx_client.py +++ b/examples/http/httpx_client.py @@ -16,11 +16,13 @@ async def on_start(app): project=config.FF_PROJECT, variables=[flags.REQUEST_QUERY], defaults=flags.Defaults, + request_timeout=5, + refresh_interval=10, ) app["ff_client"] = FeatureFlagsClient(app["ff_manager"]) try: - await app["ff_client"].preload_async(timeout=5) + await app["ff_client"].preload_async() except Exception: log.exception( "Unable to preload feature flags, application will " diff --git a/examples/http/requests_client.py b/examples/http/requests_client.py index eb3e625..b15a914 100644 --- a/examples/http/requests_client.py +++ b/examples/http/requests_client.py @@ -19,6 +19,8 @@ def get_ff_client(): project=config.FF_PROJECT, variables=[flags.REQUEST_QUERY], defaults=flags.Defaults, + request_timeout=5, + refresh_interval=10, ) ff_client = g._ff_client = FeatureFlagsClient(manager) return ff_client diff --git a/featureflags_client/http/managers/dummy.py b/featureflags_client/http/managers/dummy.py new file mode 100644 index 0000000..b3ceefc --- /dev/null +++ b/featureflags_client/http/managers/dummy.py @@ -0,0 +1,73 @@ +import logging +from typing import Any, Callable, Dict, Optional + +from featureflags_client.http.constants import Endpoints +from featureflags_client.http.managers.base import ( + AsyncBaseManager, + BaseManager, +) + +log = logging.getLogger(__name__) + + +class DummyManager(BaseManager): + """Dummy feature flags manager. + + It can be helpful when you want to use flags with their default values. + """ + + def get(self, name: str) -> Optional[Callable[[Dict], bool]]: + """ + So that `featureflags.http.flags.Flags` will use default values. + """ + return None + + def sync(self) -> None: + pass + + def preload(self) -> None: + pass + + def _post( + self, + url: Endpoints, + payload: Dict[str, Any], + timeout: int, + ) -> Dict[str, Any]: + pass + + +class AsyncDummyManager(AsyncBaseManager): + """Dummy feature flags manager for asyncio apps. + + It can be helpful when you want to use flags with their default values. + """ + + def get(self, name: str) -> Optional[Callable[[Dict], bool]]: + """ + So that `featureflags.http.flags.Flags` will use default values. + """ + return None + + async def _post( # type: ignore + self, + url: Endpoints, + payload: Dict[str, Any], + timeout: int, + ) -> Dict[str, Any]: + pass + + async def close(self) -> None: + pass + + async def sync(self) -> None: # type: ignore + pass + + async def preload(self) -> None: # type: ignore + pass + + def start(self) -> None: + pass + + async def wait_closed(self) -> None: + pass diff --git a/pdm.lock b/pdm.lock index 69bb036..a16dcb9 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev", "docs", "examples", "lint", "test", "aiohttp", "requests", "ptpython"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:c7bbb6cf01030ad7838b479d4786a3836b5c8e5e1c146cfcd53743604cbc0a0b" +content_hash = "sha256:fdd56826b863fc02ec84def7e83ab9e064b2027f7900ff5006ccac624d65532f" [[package]] name = "aiofiles" @@ -1041,22 +1041,20 @@ files = [ [[package]] name = "protobuf" -version = "3.20.3" -requires_python = ">=3.7" -summary = "Protocol Buffers" +version = "4.25.2" +requires_python = ">=3.8" +summary = "" groups = ["examples", "test"] files = [ - {file = "protobuf-3.20.3-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:f4bd856d702e5b0d96a00ec6b307b0f51c1982c2bf9c0052cf9019e9a544ba99"}, - {file = "protobuf-3.20.3-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:9aae4406ea63d825636cc11ffb34ad3379335803216ee3a856787bcf5ccc751e"}, - {file = "protobuf-3.20.3-cp310-cp310-win32.whl", hash = "sha256:28545383d61f55b57cf4df63eebd9827754fd2dc25f80c5253f9184235db242c"}, - {file = "protobuf-3.20.3-cp310-cp310-win_amd64.whl", hash = "sha256:67a3598f0a2dcbc58d02dd1928544e7d88f764b47d4a286202913f0b2801c2e7"}, - {file = "protobuf-3.20.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:398a9e0c3eaceb34ec1aee71894ca3299605fa8e761544934378bbc6c97de23b"}, - {file = "protobuf-3.20.3-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:bf01b5720be110540be4286e791db73f84a2b721072a3711efff6c324cdf074b"}, - {file = "protobuf-3.20.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:daa564862dd0d39c00f8086f88700fdbe8bc717e993a21e90711acfed02f2402"}, - {file = "protobuf-3.20.3-cp39-cp39-win32.whl", hash = "sha256:819559cafa1a373b7096a482b504ae8a857c89593cf3a25af743ac9ecbd23480"}, - {file = "protobuf-3.20.3-cp39-cp39-win_amd64.whl", hash = "sha256:03038ac1cfbc41aa21f6afcbcd357281d7521b4157926f30ebecc8d4ea59dcb7"}, - {file = "protobuf-3.20.3-py2.py3-none-any.whl", hash = "sha256:a7ca6d488aa8ff7f329d4c545b2dbad8ac31464f1d8b1c87ad1346717731e4db"}, - {file = "protobuf-3.20.3.tar.gz", hash = "sha256:2e3427429c9cffebf259491be0af70189607f365c2f41c7c3764af6f337105f2"}, + {file = "protobuf-4.25.2-cp310-abi3-win32.whl", hash = "sha256:b50c949608682b12efb0b2717f53256f03636af5f60ac0c1d900df6213910fd6"}, + {file = "protobuf-4.25.2-cp310-abi3-win_amd64.whl", hash = "sha256:8f62574857ee1de9f770baf04dde4165e30b15ad97ba03ceac65f760ff018ac9"}, + {file = "protobuf-4.25.2-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:2db9f8fa64fbdcdc93767d3cf81e0f2aef176284071507e3ede160811502fd3d"}, + {file = "protobuf-4.25.2-cp37-abi3-manylinux2014_aarch64.whl", hash = "sha256:10894a2885b7175d3984f2be8d9850712c57d5e7587a2410720af8be56cdaf62"}, + {file = "protobuf-4.25.2-cp37-abi3-manylinux2014_x86_64.whl", hash = "sha256:fc381d1dd0516343f1440019cedf08a7405f791cd49eef4ae1ea06520bc1c020"}, + {file = "protobuf-4.25.2-cp39-cp39-win32.whl", hash = "sha256:5e5c933b4c30a988b52e0b7c02641760a5ba046edc5e43d3b94a74c9fc57c1b3"}, + {file = "protobuf-4.25.2-cp39-cp39-win_amd64.whl", hash = "sha256:d66a769b8d687df9024f2985d5137a337f957a0916cf5464d1513eee96a63ff0"}, + {file = "protobuf-4.25.2-py3-none-any.whl", hash = "sha256:a8b7a98d4ce823303145bf3c1a8bdb0f2f4642a414b196f04ad9853ed0c8f830"}, + {file = "protobuf-4.25.2.tar.gz", hash = "sha256:fe599e175cb347efc8ee524bcd4b902d11f7262c0e569ececcb89995c15f0a5e"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 4872a0e..41c2b31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ test = [ "faker==18.13", "tox-pdm==0.7.0", "grpclib==0.4.6", - "protobuf<4.0.0", + "protobuf>=4.24.4", "grpcio==1.59.0", "hiku==0.7.1", ] @@ -74,7 +74,7 @@ examples = [ "flask>=2.2.5", "sanic>=23.3.0", "grpclib>=0.4.6", - "protobuf<4.0.0", + "protobuf>=4.24.4", "grpcio==1.59.0", "httpx>=0.24.1", "requests>=2.31.0",