Skip to content

Commit b48eb08

Browse files
danzh2010danzh1989
andauthored
mobile: relax AsyncClient Python API to take different engine builders (#45078)
Commit Message: the Python class now takes a custom Protocol `EngineBuilderLike`. Additional Description: also remove google's private PyPI mirror url override Risk Level: low Testing: existing tests passs Docs Changes: N/A Release Notes: N/A Platform Specific Features: N/A Signed-off-by: Dan Zhang <danzh@google.com> Co-authored-by: Dan Zhang <danzh@google.com>
1 parent fc93002 commit b48eb08

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

mobile/MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ local_path_override(
2424
)
2525

2626
pip.parse(
27-
experimental_index_url = "https://us-python.pkg.dev/artifact-foundry-prod/python-3p-trusted/simple/",
2827
hub_name = "pypi",
2928
python_version = PYTHON_VERSION,
3029
requirements_lock = "//:requirements.txt",

mobile/library/python/envoy_mobile/async_client/client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""High level asyncio client built on top of the Envoy Mobile bindings."""
22

33
import asyncio
4-
from typing import Any, Dict, List, Optional, Union
4+
from typing import Any, Callable, Dict, List, Optional, Protocol, Union
55

66
from .. import envoy_engine
7-
from ..envoy_engine import EngineBuilder
87

98
from .executor import AsyncioExecutor, Executor
109
from .response import ClientResponseError, Response
@@ -13,6 +12,16 @@
1312
)
1413

1514

15+
class EngineBuilderLike(Protocol):
16+
def set_on_engine_running(self, closure: Callable[[], None]) -> "EngineBuilderLike":
17+
"""Set callback to be invoked when engine is running."""
18+
...
19+
20+
def build(self) -> Any:
21+
"""Build and return the engine instance."""
22+
...
23+
24+
1625
class AsyncClient:
1726
"""A very small HTTP client that speaks the subset of envoy_requests
1827
that we care about.
@@ -25,11 +34,11 @@ class AsyncClient:
2534
Use as an async context manager: ``async with AsyncClient(engine_builder) as client:``
2635
"""
2736

28-
def __init__(self, engine_builder: EngineBuilder) -> None:
37+
def __init__(self, engine_builder: EngineBuilderLike) -> None:
2938
"""Construct a new AsyncClient.
3039
3140
Args:
32-
engine_builder: A pre-configured EngineBuilder to finalize and build.
41+
engine_builder: A pre-configured EngineBuilder (or compatible builder object) to finalize and build.
3342
"""
3443
self._engine_builder = engine_builder
3544
self._engine = None

0 commit comments

Comments
 (0)