Skip to content

Commit

Permalink
Added pylint, enforce naming. (#590)
Browse files Browse the repository at this point in the history
* Added pylint.

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

* Enforce pylint:invalid-name.

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

* Updated the generated code header to prevent broken links.

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

* Swapped order of messages.

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

---------

Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock authored Nov 21, 2023
1 parent cfd585b commit 1801ada
Show file tree
Hide file tree
Showing 89 changed files with 1,794 additions and 1,674 deletions.
2 changes: 1 addition & 1 deletion .ci/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ if [[ "$CMD" == "assemble" ]]; then
docker run \
--rm -v $repo/.ci/output:/code/opensearch-py/dist \
$product \
/bin/bash -c "python /code/opensearch-py/utils/build-dists.py $VERSION"
/bin/bash -c "python /code/opensearch-py/utils/build_dists.py $VERSION"

# Verify that there are dists in .ci/output
if compgen -G ".ci/output/*" > /dev/null; then
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
### Added
- Added pylint, enforcing `line-too-long` and `invalid-name` ([#590](https://github.com/opensearch-project/opensearch-py/pull/590))
### Changed
### Deprecated
### Removed
Expand Down
10 changes: 9 additions & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ Note that integration tests require docker to be installed and running, and down

## Linter

Run the linter and test suite to ensure your changes do not break existing code. The following will auto-format your changes.
This library uses a combination of [pylint](https://github.com/pylint-dev/pylint), [black](https://github.com/psf/black), and [isort](https://github.com/PyCQA/isort) to enforce some consistency in code formatting or naming conventions.

Run the linters to ensure your changes do not break existing conventions.

```
$ nox -rs lint
```

Use a formatter to auto-correct some common problems.

```
$ nox -rs format
Expand Down
33 changes: 19 additions & 14 deletions benchmarks/bench_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@

from opensearchpy import AsyncHttpConnection, AsyncOpenSearch

host = "localhost"
port = 9200
auth = ("admin", "admin")
index_name = "test-index-async"
item_count = 100


async def index_records(client: Any, item_count: int) -> None:
async def index_records(client: Any, index_name: str, item_count: int) -> None:
await asyncio.gather(
*[
client.index(
Expand All @@ -41,6 +35,11 @@ async def index_records(client: Any, item_count: int) -> None:


async def test_async(client_count: int = 1, item_count: int = 1) -> None:
host = "localhost"
port = 9200
auth = ("admin", "admin")
index_name = "test-index-async"

clients = []
for i in range(client_count):
clients.append(
Expand All @@ -61,7 +60,10 @@ async def test_async(client_count: int = 1, item_count: int = 1) -> None:
await clients[0].indices.create(index_name)

await asyncio.gather(
*[index_records(clients[i], item_count) for i in range(client_count)]
*[
index_records(clients[i], index_name, item_count)
for i in range(client_count)
]
)

await clients[0].indices.refresh(index=index_name)
Expand All @@ -79,28 +81,31 @@ def test(item_count: int = 1, client_count: int = 1) -> None:
loop.close()


ITEM_COUNT = 100


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


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


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


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


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


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


__benchmarks__ = [(test_1, test_8, "1 client vs. more clients (async)")]
45 changes: 24 additions & 21 deletions benchmarks/bench_info_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@

from opensearchpy import OpenSearch

host = "localhost"
port = 9200
auth = ("admin", "admin")
request_count = 250


root = logging.getLogger()
# root.setLevel(logging.DEBUG)
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
root.addHandler(handler)


def get_info(client: Any, request_count: int) -> float:
tt: float = 0
Expand All @@ -48,6 +32,22 @@ def get_info(client: Any, request_count: int) -> float:


def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) -> None:
host = "localhost"
port = 9200
auth = ("admin", "admin")

root = logging.getLogger()
# root.setLevel(logging.DEBUG)
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
root.addHandler(handler)

clients = []
for i in range(client_count):
clients.append(
Expand Down Expand Up @@ -76,24 +76,27 @@ def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) -
print(f"latency={latency}")


REQUEST_COUNT = 250


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


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


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


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


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


__benchmarks__ = [(test_1, test_32, "1 thread vs. 32 threads (sync)")]
51 changes: 28 additions & 23 deletions benchmarks/bench_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,8 @@

from opensearchpy import OpenSearch, Urllib3HttpConnection

host = "localhost"
port = 9200
auth = ("admin", "admin")
index_name = "test-index-sync"
item_count = 1000

root = logging.getLogger()
# root.setLevel(logging.DEBUG)
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
root.addHandler(handler)


def index_records(client: Any, item_count: int) -> Any:
def index_records(client: Any, index_name: str, item_count: int) -> Any:
tt = 0
for n in range(10):
data: Any = []
Expand All @@ -65,6 +49,23 @@ def index_records(client: Any, item_count: int) -> Any:


def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> None:
host = "localhost"
port = 9200
auth = ("admin", "admin")
index_name = "test-index-sync"

root = logging.getLogger()
# root.setLevel(logging.DEBUG)
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
root.addHandler(handler)

clients = []
for i in range(client_count):
clients.append(
Expand Down Expand Up @@ -96,7 +97,8 @@ def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> N
threads = []
for thread_id in range(thread_count):
thread = ThreadWithReturnValue(
target=index_records, args=[clients[thread_id % len(clients)], item_count]
target=index_records,
args=[clients[thread_id % len(clients)], index_name, item_count],
)
threads.append(thread)
thread.start()
Expand All @@ -113,24 +115,27 @@ def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> N
print(f"{count}, latency={latency}")


ITEM_COUNT = 1000


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


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


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


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


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


__benchmarks__ = [(test_1, test_32, "1 thread vs. 32 threads (sync)")]
Loading

0 comments on commit 1801ada

Please sign in to comment.