Skip to content

Commit

Permalink
Merge .pyi type stubs inline (#563)
Browse files Browse the repository at this point in the history
* Merged types into .py code.

Signed-off-by: dblock <dblock@amazon.com>

* Fix: nox -rs generate.

Signed-off-by: dblock <dblock@amazon.com>

* Updated CHANGELOG.

Signed-off-by: dblock <dblock@amazon.com>

* Use lowest common python version for lint.

Signed-off-by: dblock <dblock@amazon.com>

* Fix: don't typeshed.

Signed-off-by: dblock <dblock@amazon.com>

* Removed unneeded comment.

Signed-off-by: dblock <dblock@amazon.com>

* Simplify OPENSEARCH_URL.

Signed-off-by: dblock <dblock@amazon.com>

* Fix: positional ignore_status used as chunk_size.

Signed-off-by: dblock <dblock@amazon.com>

* Fix: parse version string.

Signed-off-by: dblock <dblock@amazon.com>

* Remove future annotations for Python 3.6.

Signed-off-by: dblock <dblock@amazon.com>

* Fix: types in documentation.

Signed-off-by: dblock <dblock@amazon.com>

* Improve CHANGELOG text.

Signed-off-by: dblock <dblock@amazon.com>

* Re-added missing separator.

Signed-off-by: dblock <dblock@amazon.com>

* Remove duplicate licenses.

Signed-off-by: dblock <dblock@amazon.com>

* Get rid of Optional[Any].

Signed-off-by: dblock <dblock@amazon.com>

* Fix docs with AsyncOpenSearch.

Signed-off-by: dblock <dblock@amazon.com>

* Fix: undo comment.

Signed-off-by: dblock <dblock@amazon.com>

---------

Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock authored Nov 6, 2023
1 parent 0d8a23d commit dcb79cc
Show file tree
Hide file tree
Showing 268 changed files with 6,001 additions and 16,161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Generate `nodes` client from API specs ([#514](https://github.com/opensearch-project/opensearch-py/pull/514))
- Generate `cat` client from API specs ([#529](https://github.com/opensearch-project/opensearch-py/pull/529))
- Use API generator for all APIs ([#551](https://github.com/opensearch-project/opensearch-py/pull/551))
- Merge `.pyi` type stubs inline ([#563](https://github.com/opensearch-project/opensearch-py/pull/563))
### Deprecated
- Deprecated point-in-time APIs (list_all_point_in_time, create_point_in_time, delete_point_in_time) and Security Client APIs (health_check and update_audit_config) ([#502](https://github.com/opensearch-project/opensearch-py/pull/502))
### Removed
Expand Down
4 changes: 3 additions & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ If you want to auto-start one, the following will start a new instance and run t
If your OpenSearch docker instance is running, you can execute the test suite directly.

```
$ nox -rs test
$ nox -rs test-3.9
```

Substitute `3.9` with your Python version above, or use `nox -rs test` to run with multiple.

To run tests against different versions of OpenSearch, use `run-tests [with/without security] [version]`:

```
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include LICENSE
include MANIFEST.in
include README.md
include setup.py
recursive-include opensearch* py.typed *.pyi
recursive-include opensearch* py.typed

prune test_opensearch
recursive-exclude * __pycache__
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/bench_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
item_count = 100


async def index_records(client, item_count):
async def index_records(client, item_count) -> None:
await asyncio.gather(
*[
client.index(
Expand Down Expand Up @@ -71,34 +71,34 @@ async def test_async(client_count=1, item_count=1):
await asyncio.gather(*[client.close() for client in clients])


def test(item_count=1, client_count=1):
def test(item_count: int = 1, client_count: int = 1) -> None:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(test_async(item_count, client_count))
loop.close()


def test_1():
def test_1() -> None:
test(1, 32 * item_count)


def test_2():
def test_2() -> None:
test(2, 16 * item_count)


def test_4():
def test_4() -> None:
test(4, 8 * item_count)


def test_8():
def test_8() -> None:
test(8, 4 * item_count)


def test_16():
def test_16() -> None:
test(16, 2 * item_count)


def test_32():
def test_32() -> None:
test(32, item_count)


Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bench_info_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ def test(thread_count=1, request_count=1, client_count=1):
print(f"latency={latency}")


def test_1():
def test_1() -> None:
test(1, 32 * request_count, 1)


def test_2():
def test_2() -> None:
test(2, 16 * request_count, 2)


def test_4():
def test_4() -> None:
test(4, 8 * request_count, 3)


def test_8():
def test_8() -> None:
test(8, 4 * request_count, 8)


def test_32():
def test_32() -> None:
test(32, request_count, 32)


Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bench_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ def test(thread_count=1, item_count=1, client_count=1):
print(f"{count}, latency={latency}")


def test_1():
def test_1() -> None:
test(1, 32 * item_count, 1)


def test_2():
def test_2() -> None:
test(2, 16 * item_count, 2)


def test_4():
def test_4() -> None:
test(4, 8 * item_count, 3)


def test_8():
def test_8() -> None:
test(8, 4 * item_count, 8)


def test_32():
def test_32() -> None:
test(32, item_count, 32)


Expand Down
23 changes: 16 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"])
def test(session):
def test(session) -> None:
session.install(".")
session.install("-r", "dev-requirements.txt")

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


@nox.session()
def format(session):
def format(session) -> None:
session.install("black", "isort")

session.run("isort", "--profile=black", *SOURCE_FILES)
Expand All @@ -59,9 +59,18 @@ def format(session):
lint(session)


@nox.session()
def lint(session):
session.install("flake8", "black", "mypy", "isort", "types-requests", "types-six")
@nox.session(python=["3.7"])
def lint(session) -> None:
session.install(
"flake8",
"black",
"mypy",
"isort",
"types-requests",
"types-six",
"types-simplejson",
"types-python-dateutil",
)

session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
session.run("black", "--target-version=py33", "--check", *SOURCE_FILES)
Expand All @@ -85,7 +94,7 @@ def lint(session):


@nox.session()
def docs(session):
def docs(session) -> None:
session.install(".")
session.install(
"-rdev-requirements.txt", "sphinx-rtd-theme", "sphinx-autodoc-typehints"
Expand All @@ -94,7 +103,7 @@ def docs(session):


@nox.session()
def generate(session):
def generate(session) -> None:
session.install("-rdev-requirements.txt")
session.run("python", "utils/generate-api.py")
format(session)
16 changes: 6 additions & 10 deletions opensearchpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@

import logging
import re
import sys
import warnings

from ._version import __versionstr__

_major, _minor, _patch = [
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups()
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups() # type: ignore
]

VERSION = __version__ = (_major, _minor, _patch)

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 Down Expand Up @@ -247,14 +251,6 @@
"normalizer",
"token_filter",
"tokenizer",
]

from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .connection import AsyncHttpConnection

__all__ += [
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
Expand Down
132 changes: 0 additions & 132 deletions opensearchpy/__init__.pyi

This file was deleted.

Loading

0 comments on commit dcb79cc

Please sign in to comment.