[7.x] Remove yarl from [async] extra
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
This commit is contained in:
committed by
GitHub
parent
9b8cee0199
commit
0cdeeb654a
@@ -31,6 +31,14 @@
|
||||
|
||||
import aiohttp
|
||||
import aiohttp.client_exceptions as aiohttp_exceptions
|
||||
import yarl
|
||||
|
||||
|
||||
# We do this because we don't explicitly require 'yarl'
|
||||
# within our [async] extra any more.
|
||||
# See AIOHttpConnection.request() for more information why.
|
||||
try:
|
||||
import yarl
|
||||
except ImportError:
|
||||
yarl = False
|
||||
|
||||
__all__ = ["aiohttp", "aiohttp_exceptions", "yarl"]
|
||||
|
||||
@@ -231,15 +231,30 @@ class AIOHttpConnection(AsyncConnection):
|
||||
method = "GET"
|
||||
is_head = True
|
||||
|
||||
# Provide correct URL object to avoid string parsing in low-level code
|
||||
url = yarl.URL.build(
|
||||
scheme=self.scheme,
|
||||
host=self.hostname,
|
||||
port=self.port,
|
||||
path=url_path,
|
||||
query_string=query_string,
|
||||
encoded=True,
|
||||
)
|
||||
# Top-tier tip-toeing happening here. Basically
|
||||
# because Pip's old resolver is bad and wipes out
|
||||
# strict pins in favor of non-strict pins of extras
|
||||
# our [async] extra overrides aiohttp's pin of
|
||||
# yarl. yarl released breaking changes, aiohttp pinned
|
||||
# defensively afterwards, but our users don't get
|
||||
# that nice pin that aiohttp set. :( So to play around
|
||||
# this super-defensively we try to import yarl, if we can't
|
||||
# then we pass a string into ClientSession.request() instead.
|
||||
if yarl:
|
||||
# Provide correct URL object to avoid string parsing in low-level code
|
||||
url = yarl.URL.build(
|
||||
scheme=self.scheme,
|
||||
host=self.hostname,
|
||||
port=self.port,
|
||||
path=url_path,
|
||||
query_string=query_string,
|
||||
encoded=True,
|
||||
)
|
||||
else:
|
||||
url = self.url_prefix + url
|
||||
if query_string:
|
||||
url = "%s?%s" % (url, query_string)
|
||||
url = self.host + url
|
||||
|
||||
timeout = aiohttp.ClientTimeout(
|
||||
total=timeout if timeout is not None else self.timeout
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ def lint(session):
|
||||
|
||||
# Make sure we don't require aiohttp to be installed for users to
|
||||
# receive type hint information from mypy.
|
||||
session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp", "yarl")
|
||||
session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp")
|
||||
session.run("mypy", "--strict", "elasticsearch/")
|
||||
session.run("mypy", "--strict", "test_elasticsearch/test_types/sync_types.py")
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ packages = [
|
||||
]
|
||||
|
||||
install_requires = [
|
||||
"urllib3>=1.21.1",
|
||||
"urllib3>=1.21.1, <2",
|
||||
"certifi",
|
||||
]
|
||||
tests_require = [
|
||||
@@ -49,7 +49,7 @@ tests_require = [
|
||||
"pytest",
|
||||
"pytest-cov",
|
||||
]
|
||||
async_require = ["aiohttp>=3,<4", "yarl"]
|
||||
async_require = ["aiohttp>=3,<4"]
|
||||
|
||||
docs_require = ["sphinx<1.7", "sphinx_rtd_theme"]
|
||||
generate_require = ["black", "jinja2"]
|
||||
|
||||
@@ -41,3 +41,16 @@ class TestBulk:
|
||||
|
||||
assert response["errors"] is False
|
||||
assert len(response["items"]) == 1
|
||||
|
||||
|
||||
class TestYarlMissing:
|
||||
async def test_aiohttp_connection_works_without_yarl(
|
||||
self, async_client, monkeypatch
|
||||
):
|
||||
# This is a defensive test case for if aiohttp suddenly stops using yarl.
|
||||
from elasticsearch._async import http_aiohttp
|
||||
|
||||
monkeypatch.setattr(http_aiohttp, "yarl", False)
|
||||
|
||||
resp = await async_client.info(pretty=True)
|
||||
assert isinstance(resp, dict)
|
||||
|
||||
Reference in New Issue
Block a user