Skip to content

Commit 435a565

Browse files
feat: DbuApplication stub relocation (#1882)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent 305c074 commit 435a565

File tree

11 files changed

+259
-27
lines changed

11 files changed

+259
-27
lines changed

doc/changelog.d/1882.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DbuApplication stub relocation

src/ansys/geometry/core/_grpc/_services/_service.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import grpc
2424

2525
from .._version import GeometryApiProtos, set_proto_version
26+
from .base.admin import GRPCAdminService
2627
from .base.bodies import GRPCBodyService
28+
from .base.dbuapplication import GRPCDbuApplicationService
2729

2830

2931
class _GRPCServices:
@@ -66,6 +68,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
6668
# Lazy load all the services
6769
self._admin = None
6870
self._bodies = None
71+
self._dbu_application = None
6972

7073
@property
7174
def bodies(self) -> GRPCBodyService:
@@ -84,15 +87,17 @@ def bodies(self) -> GRPCBodyService:
8487

8588
if self.version == GeometryApiProtos.V0:
8689
self._bodies = GRPCBodyServiceV0(self.channel)
87-
elif self.version == GeometryApiProtos.V1:
90+
elif self.version == GeometryApiProtos.V1: # pragma: no cover
91+
# V1 is not implemented yet
8892
self._bodies = GRPCBodyServiceV1(self.channel)
89-
else:
93+
else: # pragma: no cover
94+
# This should never happen as the version is set in the constructor
9095
raise ValueError(f"Unsupported version: {self.version}")
9196

9297
return self._bodies
9398

9499
@property
95-
def admin(self):
100+
def admin(self) -> GRPCAdminService:
96101
"""
97102
Get the admin service for the specified version.
98103
@@ -108,9 +113,37 @@ def admin(self):
108113

109114
if self.version == GeometryApiProtos.V0:
110115
self._admin = GRPCAdminServiceV0(self.channel)
111-
elif self.version == GeometryApiProtos.V1:
116+
elif self.version == GeometryApiProtos.V1: # pragma: no cover
117+
# V1 is not implemented yet
112118
self._admin = GRPCAdminServiceV1(self.channel)
113-
else:
119+
else: # pragma: no cover
120+
# This should never happen as the version is set in the constructor
114121
raise ValueError(f"Unsupported version: {self.version}")
115122

116123
return self._admin
124+
125+
@property
126+
def dbu_application(self) -> GRPCDbuApplicationService:
127+
"""
128+
Get the DBU application service for the specified version.
129+
130+
Returns
131+
-------
132+
DbuApplicationServiceBase
133+
The DBU application service for the specified version.
134+
"""
135+
if not self._dbu_application:
136+
# Import the appropriate DBU application service based on the version
137+
from .v0.dbuapplication import GRPCDbuApplicationServiceV0
138+
from .v1.dbuapplication import GRPCDbuApplicationServiceV1
139+
140+
if self.version == GeometryApiProtos.V0:
141+
self._dbu_application = GRPCDbuApplicationServiceV0(self.channel)
142+
elif self.version == GeometryApiProtos.V1: # pragma: no cover
143+
# V1 is not implemented yet
144+
self._dbu_application = GRPCDbuApplicationServiceV1(self.channel)
145+
else: # pragma: no cover
146+
# This should never happen as the version is set in the constructor
147+
raise ValueError(f"Unsupported version: {self.version}")
148+
149+
return self._dbu_application
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Module containing the DBU Application service implementation (abstraction layer)."""
23+
24+
from abc import ABC, abstractmethod
25+
26+
import grpc
27+
28+
29+
class GRPCDbuApplicationService(ABC):
30+
"""DBU Application service for gRPC communication with the Geometry server.
31+
32+
Parameters
33+
----------
34+
channel : grpc.Channel
35+
The gRPC channel to the server.
36+
"""
37+
38+
def __init__(self, channel: grpc.Channel):
39+
"""Initialize the GRPCDbuApplicationService class."""
40+
pass # pragma: no cover
41+
42+
@abstractmethod
43+
def run_script(self, **kwargs) -> dict:
44+
"""Run a Scripting API script."""
45+
pass # pragma: no cover

src/ansys/geometry/core/_grpc/_services/v0/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class GRPCAdminServiceV0(GRPCAdminService):
4545
The gRPC channel to the server.
4646
"""
4747

48-
def __init__(self, channel: grpc.Channel):
49-
"""Initialize the AdminServiceBase class."""
48+
@protect_grpc
49+
def __init__(self, channel: grpc.Channel): # noqa: D102
5050
from ansys.api.dbu.v0.admin_pb2_grpc import AdminStub
5151

5252
self.stub = AdminStub(channel)

src/ansys/geometry/core/_grpc/_services/v0/bodies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class GRPCBodyServiceV0(GRPCBodyService):
5959
"""
6060

6161
@protect_grpc
62-
def __init__(self, channel: grpc.Channel):
63-
"""Initialize the BodyService with the gRPC stub."""
62+
def __init__(self, channel: grpc.Channel): # noqa: D102
6463
from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub
6564

6665
self.stub = BodiesStub(channel)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Module containing the DBU Application service implementation for v0."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.dbuapplication import GRPCDbuApplicationService
29+
30+
31+
class GRPCDbuApplicationServiceV0(GRPCDbuApplicationService):
32+
"""DBU Application service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
DBU Application service. It is specifically designed for the v0 version
36+
of the Geometry API.
37+
38+
Parameters
39+
----------
40+
channel : grpc.Channel
41+
The gRPC channel to the server.
42+
"""
43+
44+
@protect_grpc
45+
def __init__(self, channel: grpc.Channel): # noqa: D102
46+
from ansys.api.dbu.v0.dbuapplication_pb2_grpc import DbuApplicationStub
47+
48+
self.stub = DbuApplicationStub(channel)
49+
50+
@protect_grpc
51+
def run_script(self, **kwargs) -> dict: # noqa: D102
52+
from ansys.api.dbu.v0.dbuapplication_pb2 import RunScriptFileRequest
53+
54+
# Create the request - assumes all inputs are valid and of the proper type
55+
request = RunScriptFileRequest(
56+
script_path=kwargs["script_path"],
57+
script_args=kwargs["script_args"],
58+
api_version=kwargs["api_version"],
59+
)
60+
61+
# Call the gRPC service
62+
response = self.stub.RunScriptFile(request)
63+
64+
# Return the response - formatted as a dictionary
65+
return {
66+
"success": response.success,
67+
"message": response.message,
68+
"values": None if not response.values else dict(response.values),
69+
}

src/ansys/geometry/core/_grpc/_services/v1/admin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import grpc
2525

26+
from ansys.geometry.core.errors import protect_grpc
27+
2628
from ..base.admin import GRPCAdminService
2729

2830

@@ -39,14 +41,16 @@ class GRPCAdminServiceV1(GRPCAdminService): # pragma: no cover
3941
The gRPC channel to the server.
4042
"""
4143

42-
def __init__(self, channel: grpc.Channel):
43-
"""Initialize the AdminServiceBase class."""
44+
@protect_grpc
45+
def __init__(self, channel: grpc.Channel): # noqa: D102
4446
from ansys.api.dbu.v1.admin_pb2_grpc import AdminStub
4547

4648
self.stub = AdminStub(channel)
4749

50+
@protect_grpc
4851
def get_backend(self, **kwargs) -> dict: # noqa: D102
4952
raise NotImplementedError
5053

54+
@protect_grpc
5155
def get_logs(self, **kwargs) -> dict: # noqa: D102
5256
raise NotImplementedError

src/ansys/geometry/core/_grpc/_services/v1/bodies.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,101 +48,134 @@ def __init__(self, channel: grpc.Channel):
4848

4949
self.stub = BodiesStub(channel)
5050

51+
@protect_grpc
5152
def create_sphere_body(self, **kwargs) -> dict: # noqa: D102
5253
raise NotImplementedError
5354

55+
@protect_grpc
5456
def create_extruded_body(self, **kwargs) -> dict: # noqa: D102
5557
raise NotImplementedError
5658

59+
@protect_grpc
5760
def create_sweeping_profile_body(self, **kwargs) -> dict: # noqa: D102
5861
raise NotImplementedError
5962

63+
@protect_grpc
6064
def create_sweeping_chain(self, **kwargs) -> dict: # noqa: D102
6165
raise NotImplementedError
6266

67+
@protect_grpc
6368
def create_extruded_body_from_face_profile(self, **kwargs) -> dict: # noqa: D102
6469
raise NotImplementedError
6570

71+
@protect_grpc
6672
def create_extruded_body_from_loft_profiles(self, **kwargs) -> dict: # noqa: D102
6773
raise NotImplementedError
6874

75+
@protect_grpc
6976
def create_planar_body(self, **kwargs) -> dict: # noqa: D102
7077
raise NotImplementedError
7178

79+
@protect_grpc
7280
def create_body_from_face(self, **kwargs) -> dict: # noqa: D102
7381
raise NotImplementedError
7482

83+
@protect_grpc
7584
def create_surface_body(self, **kwargs) -> dict: # noqa: D102
7685
raise NotImplementedError
7786

87+
@protect_grpc
7888
def create_surface_body_from_trimmed_curves(self, **kwargs) -> dict: # noqa: D102
7989
raise NotImplementedError
8090

91+
@protect_grpc
8192
def translate(self, **kwargs) -> dict: # noqa: D102
8293
raise NotImplementedError
8394

95+
@protect_grpc
8496
def delete(self, **kwargs) -> dict: # noqa: D102
8597
raise NotImplementedError
8698

99+
@protect_grpc
87100
def is_suppressed(self, **kwargs) -> dict: # noqa: D102
88101
raise NotImplementedError
89102

103+
@protect_grpc
90104
def get_color(self, **kwargs) -> dict: # noqa: D102
91105
raise NotImplementedError
92106

107+
@protect_grpc
93108
def get_faces(self, **kwargs) -> dict: # noqa: D102
94109
raise NotImplementedError
95110

111+
@protect_grpc
96112
def get_edges(self, **kwargs) -> dict: # noqa: D102
97113
raise NotImplementedError
98114

115+
@protect_grpc
99116
def get_volume(self, **kwargs) -> dict: # noqa: D102
100117
raise NotImplementedError
101118

119+
@protect_grpc
102120
def get_bounding_box(self, **kwargs) -> dict: # noqa: D102
103121
raise NotImplementedError
104122

123+
@protect_grpc
105124
def set_assigned_material(self, **kwargs) -> dict: # noqa: D102
106125
raise NotImplementedError
107126

127+
@protect_grpc
108128
def get_assigned_material(self, **kwargs) -> dict: # noqa: D102
109129
raise NotImplementedError
110130

131+
@protect_grpc
111132
def set_name(self, **kwargs) -> dict: # noqa: D102
112133
raise NotImplementedError
113134

135+
@protect_grpc
114136
def set_fill_style(self, **kwargs) -> dict: # noqa: D102
115137
raise NotImplementedError
116138

139+
@protect_grpc
117140
def set_suppressed(self, **kwargs) -> dict: # noqa: D102
118141
raise NotImplementedError
119142

143+
@protect_grpc
120144
def set_color(self, **kwargs) -> dict: # noqa: D102
121145
raise NotImplementedError
122146

147+
@protect_grpc
123148
def rotate(self, **kwargs) -> dict: # noqa: D102
124149
raise NotImplementedError
125150

151+
@protect_grpc
126152
def scale(self, **kwargs) -> dict: # noqa: D102
127153
raise NotImplementedError
128154

155+
@protect_grpc
129156
def mirror(self, **kwargs) -> dict: # noqa: D102
130157
raise NotImplementedError
131158

159+
@protect_grpc
132160
def map(self, **kwargs) -> dict: # noqa: D102
133161
raise NotImplementedError
134162

163+
@protect_grpc
135164
def get_collision(self, **kwargs) -> dict: # noqa: D102
136165
raise NotImplementedError
137166

167+
@protect_grpc
138168
def copy(self, **kwargs) -> dict: # noqa: D102
139169
raise NotImplementedError
140170

171+
@protect_grpc
141172
def get_tesellation(self, **kwargs) -> dict: # noqa: D102
142173
raise NotImplementedError
143174

175+
@protect_grpc
144176
def get_tesellation_with_options(self, **kwargs) -> dict: # noqa: D102
145177
raise NotImplementedError
146178

179+
@protect_grpc
147180
def boolean(self, **kwargs) -> dict: # noqa: D102
148181
raise NotImplementedError

0 commit comments

Comments
 (0)