Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: generator adds new namespace. #813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading