Skip to content

Commit a24b9f3

Browse files
authored
Fix: generator adds new namespace. (#813)
Signed-off-by: dblock <[email protected]>
1 parent cd68b03 commit a24b9f3

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

opensearchpy/_async/client/plugins.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
class PluginsClient(NamespacedClient):
2929
alerting: Any
3030
index_management: Any
31+
knn: Any
32+
ml: Any
33+
notifications: Any
34+
observability: Any
35+
ppl: Any
36+
query: Any
37+
rollups: Any
38+
sql: Any
39+
transforms: Any
3140

3241
def __init__(self, client: Client) -> None:
3342
super().__init__(client)
@@ -50,13 +59,17 @@ def _dynamic_lookup(self, client: Any) -> None:
5059
# Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742
5160

5261
plugins = [
53-
# "query_workbench",
54-
# "reporting",
55-
# "notebooks",
5662
"alerting",
57-
# "anomaly_detection",
58-
# "trace_analytics",
5963
"index_management",
64+
"knn",
65+
"ml",
66+
"notifications",
67+
"observability",
68+
"ppl",
69+
"query",
70+
"rollups",
71+
"sql",
72+
"transforms",
6073
]
6174
for plugin in plugins:
6275
if not hasattr(client, plugin):

utils/generate_api.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,26 @@ def dump(self) -> None:
178178
"opensearchpy/_async/client/plugins.py", "r+", encoding="utf-8"
179179
) as file:
180180
content = file.read()
181-
file_content = content.replace(
182-
"super(PluginsClient, self).__init__(client)",
183-
f"super(PluginsClient, self).__init__(client)\n self.{self.namespace} = {self.namespace_new}Client(client)", # pylint: disable=line-too-long
181+
content = content.replace(
182+
"super().__init__(client)\n",
183+
f"super().__init__(client)\n\n self.{self.namespace} = {self.namespace_new}Client(client)", # pylint: disable=line-too-long
184184
1,
185185
)
186-
new_file_content = file_content.replace(
186+
content = content.replace(
187187
"from .client import Client",
188188
f"from ..plugins.{self.namespace} import {self.namespace_new}Client\nfrom .client import Client", # pylint: disable=line-too-long
189189
1,
190190
)
191+
content = content.replace(
192+
"class PluginsClient(NamespacedClient):\n",
193+
f"class PluginsClient(NamespacedClient): \n {self.namespace}: Any\n", # pylint: disable=line-too-long
194+
1,
195+
)
196+
content = content.replace(
197+
"plugins = [", f'plugins = [\n "{self.namespace}",\n'
198+
)
191199
file.seek(0)
192-
file.write(new_file_content)
200+
file.write(content)
193201
file.truncate()
194202

195203
else:

0 commit comments

Comments
 (0)