Fix: generator adds new namespace. (#813)
Signed-off-by: dblock <[email protected]>
This commit is contained in:
@@ -28,6 +28,15 @@ from .utils import NamespacedClient
|
|||||||
class PluginsClient(NamespacedClient):
|
class PluginsClient(NamespacedClient):
|
||||||
alerting: Any
|
alerting: Any
|
||||||
index_management: 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:
|
def __init__(self, client: Client) -> None:
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
@@ -50,13 +59,17 @@ class PluginsClient(NamespacedClient):
|
|||||||
# Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742
|
# Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742
|
||||||
|
|
||||||
plugins = [
|
plugins = [
|
||||||
# "query_workbench",
|
|
||||||
# "reporting",
|
|
||||||
# "notebooks",
|
|
||||||
"alerting",
|
"alerting",
|
||||||
# "anomaly_detection",
|
|
||||||
# "trace_analytics",
|
|
||||||
"index_management",
|
"index_management",
|
||||||
|
"knn",
|
||||||
|
"ml",
|
||||||
|
"notifications",
|
||||||
|
"observability",
|
||||||
|
"ppl",
|
||||||
|
"query",
|
||||||
|
"rollups",
|
||||||
|
"sql",
|
||||||
|
"transforms",
|
||||||
]
|
]
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
if not hasattr(client, plugin):
|
if not hasattr(client, plugin):
|
||||||
|
|||||||
+13
-5
@@ -178,18 +178,26 @@ class Module:
|
|||||||
"opensearchpy/_async/client/plugins.py", "r+", encoding="utf-8"
|
"opensearchpy/_async/client/plugins.py", "r+", encoding="utf-8"
|
||||||
) as file:
|
) as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
file_content = content.replace(
|
content = content.replace(
|
||||||
"super(PluginsClient, self).__init__(client)",
|
"super().__init__(client)\n",
|
||||||
f"super(PluginsClient, self).__init__(client)\n self.{self.namespace} = {self.namespace_new}Client(client)", # pylint: disable=line-too-long
|
f"super().__init__(client)\n\n self.{self.namespace} = {self.namespace_new}Client(client)", # pylint: disable=line-too-long
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
new_file_content = file_content.replace(
|
content = content.replace(
|
||||||
"from .client import Client",
|
"from .client import Client",
|
||||||
f"from ..plugins.{self.namespace} import {self.namespace_new}Client\nfrom .client import Client", # pylint: disable=line-too-long
|
f"from ..plugins.{self.namespace} import {self.namespace_new}Client\nfrom .client import Client", # pylint: disable=line-too-long
|
||||||
1,
|
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.seek(0)
|
||||||
file.write(new_file_content)
|
file.write(content)
|
||||||
file.truncate()
|
file.truncate()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user