Fix: generator adds new namespace. (#813)

Signed-off-by: dblock <[email protected]>
This commit is contained in:
Daniel (dB.) Doubrovkine
2024-08-28 10:07:50 -07:00
committed by GitHub
parent cd68b03157
commit a24b9f3f3c
2 changed files with 31 additions and 10 deletions
+18 -5
View File
@@ -28,6 +28,15 @@ from .utils import NamespacedClient
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)
@@ -50,13 +59,17 @@ class PluginsClient(NamespacedClient):
# 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):
+13 -5
View File
@@ -178,18 +178,26 @@ class Module:
"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: