Skip to content

Commit 7c55bf9

Browse files
committed
V1 version of service to run script files
In creating the v1 version of the original dbuapplication file the following changes were made - File dbuapplication has been renamed to commands_script (it only invokes runscriptfile stub) - Service GRPCDbuApplicationService has been renamed GRPCCommandsScriptService - internal method has been renamed from run_script to run_script_file
1 parent 8b628a2 commit 7c55bf9

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .base.components import GRPCComponentsService
3232
from .base.coordinate_systems import GRPCCoordinateSystemService
3333
from .base.curves import GRPCCurvesService
34-
from .base.dbuapplication import GRPCDbuApplicationService
34+
from .base.commands_script import GRPCCommandsScriptService
3535
from .base.designs import GRPCDesignsService
3636
from .base.driving_dimensions import GRPCDrivingDimensionsService
3737
from .base.edges import GRPCEdgesService
@@ -94,7 +94,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
9494
self._components = None
9595
self._coordinate_systems = None
9696
self._curves = None
97-
self._dbu_application = None
97+
self._commands_script = None
9898
self._designs = None
9999
self._driving_dimensions = None
100100
self._edges = None
@@ -345,30 +345,30 @@ def designs(self) -> GRPCDesignsService:
345345
return self._designs
346346

347347
@property
348-
def dbu_application(self) -> GRPCDbuApplicationService:
348+
def commands_script(self) -> GRPCCommandsScriptService:
349349
"""
350350
Get the DBU application service for the specified version.
351351
352352
Returns
353353
-------
354-
GRPCDbuApplicationService
355-
The DBU application service for the specified version.
354+
GRPCCommandsScriptService
355+
The commands script application service for the specified version.
356356
"""
357-
if not self._dbu_application:
357+
if not self._commands_script:
358358
# Import the appropriate DBU application service based on the version
359-
from .v0.dbuapplication import GRPCDbuApplicationServiceV0
360-
from .v1.dbuapplication import GRPCDbuApplicationServiceV1
359+
from .v0.commands_script import GRPCCommandsScriptServiceV0
360+
from .v1.commands_script import GRPCCommandsScriptServiceV1
361361

362362
if self.version == GeometryApiProtos.V0:
363-
self._dbu_application = GRPCDbuApplicationServiceV0(self.channel)
363+
self._commands_script = GRPCCommandsScriptServiceV0(self.channel)
364364
elif self.version == GeometryApiProtos.V1: # pragma: no cover
365365
# V1 is not implemented yet
366-
self._dbu_application = GRPCDbuApplicationServiceV1(self.channel)
366+
self._commands_script = GRPCCommandsScriptServiceV1(self.channel)
367367
else: # pragma: no cover
368368
# This should never happen as the version is set in the constructor
369369
raise ValueError(f"Unsupported version: {self.version}")
370370

371-
return self._dbu_application
371+
return self._commands_script
372372

373373
@property
374374
def driving_dimensions(self) -> GRPCDrivingDimensionsService:

src/ansys/geometry/core/_grpc/_services/base/dbuapplication.py renamed to src/ansys/geometry/core/_grpc/_services/base/commands_script.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22-
"""Module containing the DBU Application service implementation (abstraction layer)."""
22+
"""Module containing the CommandsScript service implementation (abstraction layer)."""
2323

2424
from abc import ABC, abstractmethod
2525

2626
import grpc
2727

2828

29-
class GRPCDbuApplicationService(ABC): # pragma: no cover
30-
"""DBU Application service for gRPC communication with the Geometry server.
29+
class GRPCCommandsScriptService(ABC): # pragma: no cover
30+
"""Commands Script service for gRPC communication with the Geometry server.
3131
3232
Parameters
3333
----------
@@ -36,10 +36,10 @@ class GRPCDbuApplicationService(ABC): # pragma: no cover
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the GRPCDbuApplicationService class."""
39+
"""Initialize the GRPCCommandsScriptService class."""
4040
pass
4141

4242
@abstractmethod
43-
def run_script(self, **kwargs) -> dict:
44-
"""Run a Scripting API script."""
43+
def run_script_file(self, **kwargs) -> dict:
44+
"""Run a Scripting API script file."""
4545
pass

src/ansys/geometry/core/_grpc/_services/v0/dbuapplication.py renamed to src/ansys/geometry/core/_grpc/_services/v0/commands_script.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
from ansys.geometry.core.errors import protect_grpc
2727

28-
from ..base.dbuapplication import GRPCDbuApplicationService
28+
from ..base.commands_script import GRPCCommandsScriptService
2929

3030

31-
class GRPCDbuApplicationServiceV0(GRPCDbuApplicationService):
31+
class GRPCCommandsScriptServiceV0(GRPCCommandsScriptService):
3232
"""DBU Application service for gRPC communication with the Geometry server.
3333
3434
This class provides methods to interact with the Geometry server's
@@ -48,7 +48,7 @@ def __init__(self, channel: grpc.Channel): # noqa: D102
4848
self.stub = DbuApplicationStub(channel)
4949

5050
@protect_grpc
51-
def run_script(self, **kwargs) -> dict: # noqa: D102
51+
def run_script_file(self, **kwargs) -> dict: # noqa: D102
5252
from ansys.api.dbu.v0.dbuapplication_pb2 import RunScriptFileRequest
5353

5454
# Create the request - assumes all inputs are valid and of the proper type

src/ansys/geometry/core/_grpc/_services/v1/dbuapplication.py renamed to src/ansys/geometry/core/_grpc/_services/v1/commands_script.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22-
"""Module containing the DBU Application service implementation for v1."""
22+
"""Module containing the Commands Script service implementation for v1."""
2323

2424
import grpc
2525

2626
from ansys.geometry.core.errors import protect_grpc
2727

28-
from ..base.dbuapplication import GRPCDbuApplicationService
28+
from ..base.commands_script import GRPCCommandsScriptService
2929

3030

31-
class GRPCDbuApplicationServiceV1(GRPCDbuApplicationService): # pragma: no cover
32-
"""DBU Application service for gRPC communication with the Geometry server.
31+
class GRPCCommandsScriptServiceV1(GRPCCommandsScriptService): # pragma: no cover
32+
"""Commands Script service for gRPC communication with the Geometry server.
3333
3434
This class provides methods to interact with the Geometry server's
35-
DBU Application service. It is specifically designed for the v1 version
35+
Commands Script service. It is specifically designed for the v1 version
3636
of the Geometry API.
3737
3838
Parameters
@@ -43,10 +43,27 @@ class GRPCDbuApplicationServiceV1(GRPCDbuApplicationService): # pragma: no cove
4343

4444
@protect_grpc
4545
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.dbu.v1.dbuapplication_pb2_grpc import DbuApplicationStub
46+
from ansys.api.discovery.v1.commands.script_pb2 import ScriptStub
4747

48-
self.stub = DbuApplicationStub(channel)
48+
self.stub = ScriptStub(channel)
4949

5050
@protect_grpc
51-
def run_script(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
51+
def run_script_file(self, **kwargs) -> dict: # noqa: D102
52+
from aansys.api.discovery.v1.commands.script_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/modeler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def run_discovery_script_file(
538538
serv_path = self._upload_file(file_path)
539539

540540
self.client.log.debug(f"Running Discovery script file at {file_path}...")
541-
response = self.client.services.dbu_application.run_script(
541+
response = self.client.services.commands_script.run_script_file(
542542
script_path=serv_path,
543543
script_args=script_args,
544544
api_version=api_version.value if api_version is not None else None,

0 commit comments

Comments
 (0)