Skip to content

Commit 1801ada

Browse files
authored
Added pylint, enforce naming. (opensearch-project#590)
* 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>
1 parent cfd585b commit 1801ada

File tree

89 files changed

+1794
-1674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1794
-1674
lines changed

.ci/make.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ if [[ "$CMD" == "assemble" ]]; then
131131
docker run \
132132
--rm -v $repo/.ci/output:/code/opensearch-py/dist \
133133
$product \
134-
/bin/bash -c "python /code/opensearch-py/utils/build-dists.py $VERSION"
134+
/bin/bash -c "python /code/opensearch-py/utils/build_dists.py $VERSION"
135135

136136
# Verify that there are dists in .ci/output
137137
if compgen -G ".ci/output/*" > /dev/null; then

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
33

44
## [Unreleased]
55
### Added
6+
- Added pylint, enforcing `line-too-long` and `invalid-name` ([#590](https://github.com/opensearch-project/opensearch-py/pull/590))
67
### Changed
78
### Deprecated
89
### Removed

DEVELOPER_GUIDE.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ Note that integration tests require docker to be installed and running, and down
9999

100100
## Linter
101101

102-
Run the linter and test suite to ensure your changes do not break existing code. The following will auto-format your changes.
102+
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.
103+
104+
Run the linters to ensure your changes do not break existing conventions.
105+
106+
```
107+
$ nox -rs lint
108+
```
109+
110+
Use a formatter to auto-correct some common problems.
103111

104112
```
105113
$ nox -rs format

benchmarks/bench_async.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616

1717
from opensearchpy import AsyncHttpConnection, AsyncOpenSearch
1818

19-
host = "localhost"
20-
port = 9200
21-
auth = ("admin", "admin")
22-
index_name = "test-index-async"
23-
item_count = 100
2419

25-
26-
async def index_records(client: Any, item_count: int) -> None:
20+
async def index_records(client: Any, index_name: str, item_count: int) -> None:
2721
await asyncio.gather(
2822
*[
2923
client.index(
@@ -41,6 +35,11 @@ async def index_records(client: Any, item_count: int) -> None:
4135

4236

4337
async def test_async(client_count: int = 1, item_count: int = 1) -> None:
38+
host = "localhost"
39+
port = 9200
40+
auth = ("admin", "admin")
41+
index_name = "test-index-async"
42+
4443
clients = []
4544
for i in range(client_count):
4645
clients.append(
@@ -61,7 +60,10 @@ async def test_async(client_count: int = 1, item_count: int = 1) -> None:
6160
await clients[0].indices.create(index_name)
6261

6362
await asyncio.gather(
64-
*[index_records(clients[i], item_count) for i in range(client_count)]
63+
*[
64+
index_records(clients[i], index_name, item_count)
65+
for i in range(client_count)
66+
]
6567
)
6668

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

8183

84+
ITEM_COUNT = 100
85+
86+
8287
def test_1() -> None:
83-
test(1, 32 * item_count)
88+
test(1, 32 * ITEM_COUNT)
8489

8590

8691
def test_2() -> None:
87-
test(2, 16 * item_count)
92+
test(2, 16 * ITEM_COUNT)
8893

8994

9095
def test_4() -> None:
91-
test(4, 8 * item_count)
96+
test(4, 8 * ITEM_COUNT)
9297

9398

9499
def test_8() -> None:
95-
test(8, 4 * item_count)
100+
test(8, 4 * ITEM_COUNT)
96101

97102

98103
def test_16() -> None:
99-
test(16, 2 * item_count)
104+
test(16, 2 * ITEM_COUNT)
100105

101106

102107
def test_32() -> None:
103-
test(32, item_count)
108+
test(32, ITEM_COUNT)
104109

105110

106111
__benchmarks__ = [(test_1, test_8, "1 client vs. more clients (async)")]

benchmarks/bench_info_sync.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@
2020

2121
from opensearchpy import OpenSearch
2222

23-
host = "localhost"
24-
port = 9200
25-
auth = ("admin", "admin")
26-
request_count = 250
27-
28-
29-
root = logging.getLogger()
30-
# root.setLevel(logging.DEBUG)
31-
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
32-
33-
handler = logging.StreamHandler(sys.stdout)
34-
handler.setLevel(logging.DEBUG)
35-
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
36-
handler.setFormatter(formatter)
37-
root.addHandler(handler)
38-
3923

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

4933

5034
def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) -> None:
35+
host = "localhost"
36+
port = 9200
37+
auth = ("admin", "admin")
38+
39+
root = logging.getLogger()
40+
# root.setLevel(logging.DEBUG)
41+
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
42+
43+
handler = logging.StreamHandler(sys.stdout)
44+
handler.setLevel(logging.DEBUG)
45+
formatter = logging.Formatter(
46+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
47+
)
48+
handler.setFormatter(formatter)
49+
root.addHandler(handler)
50+
5151
clients = []
5252
for i in range(client_count):
5353
clients.append(
@@ -76,24 +76,27 @@ def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) -
7676
print(f"latency={latency}")
7777

7878

79+
REQUEST_COUNT = 250
80+
81+
7982
def test_1() -> None:
80-
test(1, 32 * request_count, 1)
83+
test(1, 32 * REQUEST_COUNT, 1)
8184

8285

8386
def test_2() -> None:
84-
test(2, 16 * request_count, 2)
87+
test(2, 16 * REQUEST_COUNT, 2)
8588

8689

8790
def test_4() -> None:
88-
test(4, 8 * request_count, 3)
91+
test(4, 8 * REQUEST_COUNT, 3)
8992

9093

9194
def test_8() -> None:
92-
test(8, 4 * request_count, 8)
95+
test(8, 4 * REQUEST_COUNT, 8)
9396

9497

9598
def test_32() -> None:
96-
test(32, request_count, 32)
99+
test(32, REQUEST_COUNT, 32)
97100

98101

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

benchmarks/bench_sync.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,8 @@
2121

2222
from opensearchpy import OpenSearch, Urllib3HttpConnection
2323

24-
host = "localhost"
25-
port = 9200
26-
auth = ("admin", "admin")
27-
index_name = "test-index-sync"
28-
item_count = 1000
2924

30-
root = logging.getLogger()
31-
# root.setLevel(logging.DEBUG)
32-
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
33-
34-
handler = logging.StreamHandler(sys.stdout)
35-
handler.setLevel(logging.DEBUG)
36-
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
37-
handler.setFormatter(formatter)
38-
root.addHandler(handler)
39-
40-
41-
def index_records(client: Any, item_count: int) -> Any:
25+
def index_records(client: Any, index_name: str, item_count: int) -> Any:
4226
tt = 0
4327
for n in range(10):
4428
data: Any = []
@@ -65,6 +49,23 @@ def index_records(client: Any, item_count: int) -> Any:
6549

6650

6751
def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> None:
52+
host = "localhost"
53+
port = 9200
54+
auth = ("admin", "admin")
55+
index_name = "test-index-sync"
56+
57+
root = logging.getLogger()
58+
# root.setLevel(logging.DEBUG)
59+
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
60+
61+
handler = logging.StreamHandler(sys.stdout)
62+
handler.setLevel(logging.DEBUG)
63+
formatter = logging.Formatter(
64+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
65+
)
66+
handler.setFormatter(formatter)
67+
root.addHandler(handler)
68+
6869
clients = []
6970
for i in range(client_count):
7071
clients.append(
@@ -96,7 +97,8 @@ def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> N
9697
threads = []
9798
for thread_id in range(thread_count):
9899
thread = ThreadWithReturnValue(
99-
target=index_records, args=[clients[thread_id % len(clients)], item_count]
100+
target=index_records,
101+
args=[clients[thread_id % len(clients)], index_name, item_count],
100102
)
101103
threads.append(thread)
102104
thread.start()
@@ -113,24 +115,27 @@ def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> N
113115
print(f"{count}, latency={latency}")
114116

115117

118+
ITEM_COUNT = 1000
119+
120+
116121
def test_1() -> None:
117-
test(1, 32 * item_count, 1)
122+
test(1, 32 * ITEM_COUNT, 1)
118123

119124

120125
def test_2() -> None:
121-
test(2, 16 * item_count, 2)
126+
test(2, 16 * ITEM_COUNT, 2)
122127

123128

124129
def test_4() -> None:
125-
test(4, 8 * item_count, 3)
130+
test(4, 8 * ITEM_COUNT, 3)
126131

127132

128133
def test_8() -> None:
129-
test(8, 4 * item_count, 8)
134+
test(8, 4 * ITEM_COUNT, 8)
130135

131136

132137
def test_32() -> None:
133-
test(32, item_count, 32)
138+
test(32, ITEM_COUNT, 32)
134139

135140

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

0 commit comments

Comments
 (0)