Skip to content

Commit

Permalink
Fix: generator adds new namespace. (#813)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Aug 28, 2024
1 parent cd68b03 commit a24b9f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
23 changes: 18 additions & 5 deletions opensearchpy/_async/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
class PluginsClient(NamespacedClient):
alerting: Any
index_management: Any
knn: Any
ml: Any
notifications: Any
observability: Any
ppl: Any
query: Any
rollups: Any
sql: Any
transforms: Any

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

plugins = [
# "query_workbench",
# "reporting",
# "notebooks",
"alerting",
# "anomaly_detection",
# "trace_analytics",
"index_management",
"knn",
"ml",
"notifications",
"observability",
"ppl",
"query",
"rollups",
"sql",
"transforms",
]
for plugin in plugins:
if not hasattr(client, plugin):
Expand Down
18 changes: 13 additions & 5 deletions utils/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,26 @@ def dump(self) -> None:
"opensearchpy/_async/client/plugins.py", "r+", encoding="utf-8"
) as file:
content = file.read()
file_content = content.replace(
"super(PluginsClient, self).__init__(client)",
f"super(PluginsClient, self).__init__(client)\n self.{self.namespace} = {self.namespace_new}Client(client)", # pylint: disable=line-too-long
content = content.replace(
"super().__init__(client)\n",
f"super().__init__(client)\n\n self.{self.namespace} = {self.namespace_new}Client(client)", # pylint: disable=line-too-long
1,
)
new_file_content = file_content.replace(
content = content.replace(
"from .client import Client",
f"from ..plugins.{self.namespace} import {self.namespace_new}Client\nfrom .client import Client", # pylint: disable=line-too-long
1,
)
content = content.replace(
"class PluginsClient(NamespacedClient):\n",
f"class PluginsClient(NamespacedClient): \n {self.namespace}: Any\n", # pylint: disable=line-too-long
1,
)
content = content.replace(
"plugins = [", f'plugins = [\n "{self.namespace}",\n'
)
file.seek(0)
file.write(new_file_content)
file.write(content)
file.truncate()

else:
Expand Down

0 comments on commit a24b9f3

Please sign in to comment.