Skip to content

Commit

Permalink
Fix: sync opensearchpy without iohttp.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 16, 2023
1 parent 4874437 commit 0d08f08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
7 changes: 6 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]) # type: ignore
def test(session: Any) -> None:
session.install(".")
# ensure client can be imported without aiohttp
session.run("python", "-c", "import opensearchpy\nprint(opensearchpy.OpenSearch())")
# ensure client can be imported with aiohttp
session.install(".[async]")
session.run("python", "-c", "import opensearchpy\nprint(opensearchpy.AsyncOpenSearch())")

session.install("-r", "dev-requirements.txt")

session.run("python", "setup.py", "test")


@nox.session(python=["3.7"]) # type: ignore
def format(session: Any) -> None:
session.install("black", "isort")
Expand Down
36 changes: 19 additions & 17 deletions opensearchpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@
logger = logging.getLogger("opensearch")
logger.addHandler(logging.NullHandler())

from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .client import OpenSearch
from .connection import (
AsyncHttpConnection,
Connection,
RequestsHttpConnection,
Urllib3HttpConnection,
Expand All @@ -76,12 +72,7 @@
UnknownDslObject,
ValidationException,
)
from .helpers import (
AWSV4SignerAsyncAuth,
AWSV4SignerAuth,
RequestsAWSV4SignerAuth,
Urllib3AWSV4SignerAuth,
)
from .helpers import AWSV4SignerAuth, RequestsAWSV4SignerAuth, Urllib3AWSV4SignerAuth
from .helpers.aggs import A
from .helpers.analysis import analyzer, char_filter, normalizer, token_filter, tokenizer
from .helpers.document import Document, InnerDoc, MetaField
Expand Down Expand Up @@ -159,7 +150,6 @@
"JSONSerializer",
"Connection",
"RequestsHttpConnection",
"AsyncHttpConnection",
"Urllib3HttpConnection",
"ImproperlyConfigured",
"OpenSearchException",
Expand All @@ -178,7 +168,6 @@
"AWSV4SignerAuth",
"Urllib3AWSV4SignerAuth",
"RequestsAWSV4SignerAuth",
"AWSV4SignerAsyncAuth",
"A",
"AttrDict",
"AttrList",
Expand Down Expand Up @@ -251,10 +240,23 @@
"normalizer",
"token_filter",
"tokenizer",
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
"AsyncOpenSearch",
"AsyncHttpConnection",
"__versionstr__",
]

try:
from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .connection import AsyncHttpConnection
from .helpers import AWSV4SignerAsyncAuth

__all__ += [
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
"AsyncOpenSearch",
"AsyncHttpConnection",
"AWSV4SignerAsyncAuth",
]
except (ImportError, SyntaxError):
pass
11 changes: 9 additions & 2 deletions opensearchpy/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


from .base import Connection
from .http_async import AsyncHttpConnection
from .http_requests import RequestsHttpConnection
from .http_urllib3 import Urllib3HttpConnection, create_ssl_context

Expand All @@ -36,5 +35,13 @@
"RequestsHttpConnection",
"Urllib3HttpConnection",
"create_ssl_context",
"AsyncHttpConnection",
]

try:
from .http_async import AsyncHttpConnection

__all__ += [
"AsyncHttpConnection",
]
except (ImportError, SyntaxError):
pass

0 comments on commit 0d08f08

Please sign in to comment.