-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support Trio with httpx #3089
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
base: main
Are you sure you want to change the base?
Support Trio with httpx #3089
Changes from all commits
056daa8
ed3a069
879cb27
bb552bc
7c85a53
1094d2d
176968a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,11 +41,17 @@ keywords = [ | |
] | ||
dynamic = ["version"] | ||
dependencies = [ | ||
"elastic-transport>=9.1.0,<10", | ||
# TODO revert before merging/releasing | ||
"elastic-transport @ git+https://github.com/pquentin/elastic-transport-python.git@trio-support", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a comment here just to remind you that need this to be edited. (not sure if your |
||
"python-dateutil", | ||
"typing-extensions", | ||
"sniffio", | ||
] | ||
|
||
# TODO revert before merging/releasing | ||
[tool.hatch.metadata] | ||
allow-direct-references = true | ||
|
||
[project.optional-dependencies] | ||
async = ["aiohttp>=3,<4"] | ||
requests = ["requests>=2.4.0, !=2.32.2, <3.0.0"] | ||
|
@@ -56,6 +62,7 @@ vectorstore_mmr = ["numpy>=1", "simsimd>=3"] | |
dev = [ | ||
"requests>=2, <3", | ||
"aiohttp", | ||
"httpx", | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-mock", | ||
|
@@ -78,6 +85,8 @@ dev = [ | |
"mapbox-vector-tile", | ||
"jinja2", | ||
"tqdm", | ||
"trio", | ||
"anyio", | ||
"mypy", | ||
"pyright", | ||
"types-python-dateutil", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,27 +16,27 @@ | |
# under the License. | ||
|
||
import pytest | ||
import pytest_asyncio | ||
import sniffio | ||
|
||
import elasticsearch | ||
|
||
from ...utils import CA_CERTS, wipe_cluster | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
@pytest_asyncio.fixture(scope="function") | ||
@pytest.fixture(scope="function") | ||
async def async_client_factory(elasticsearch_url): | ||
|
||
if not hasattr(elasticsearch, "AsyncElasticsearch"): | ||
pytest.skip("test requires 'AsyncElasticsearch' and aiohttp to be installed") | ||
|
||
print("async!", elasticsearch_url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug print? |
||
kwargs = {} | ||
if sniffio.current_async_library() == "trio": | ||
kwargs["node_class"] = "httpxasync" | ||
# Unfortunately the asyncio client needs to be rebuilt every | ||
# test execution due to how pytest-asyncio manages | ||
# event loops (one per test!) | ||
client = None | ||
try: | ||
client = elasticsearch.AsyncElasticsearch(elasticsearch_url, ca_certs=CA_CERTS) | ||
client = elasticsearch.AsyncElasticsearch( | ||
elasticsearch_url, ca_certs=CA_CERTS, **kwargs | ||
) | ||
yield client | ||
finally: | ||
if client: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
import warnings | ||
|
||
import pytest | ||
import pytest_asyncio | ||
|
||
from elasticsearch import ElasticsearchWarning, RequestError | ||
|
||
|
@@ -39,6 +38,8 @@ | |
) | ||
from ...utils import parse_version | ||
|
||
# We're not using `pytest.mark.anyio` here because it would run the test suite twice, | ||
# which does not work as it does not fully clean up after itself. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably something that we'll want to address at some point. |
||
pytestmark = pytest.mark.asyncio | ||
|
||
XPACK_FEATURES = None | ||
|
@@ -240,7 +241,7 @@ async def _feature_enabled(self, name): | |
return name in XPACK_FEATURES | ||
|
||
|
||
@pytest_asyncio.fixture(scope="function") | ||
@pytest.fixture(scope="function") | ||
def async_runner(async_client_factory): | ||
return AsyncYamlRunner(async_client_factory) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to ask the transport what the current library is, since it stores it? Not super important, but it feels unnecessary to constantly run the detection logic in sniffio.