diff --git a/doc/changelog.d/2368.added.md b/doc/changelog.d/2368.added.md new file mode 100644 index 0000000000..8f532c65f4 --- /dev/null +++ b/doc/changelog.d/2368.added.md @@ -0,0 +1 @@ +Properly handling v0 and v1 initialization diff --git a/src/ansys/geometry/core/_grpc/_version.py b/src/ansys/geometry/core/_grpc/_version.py index 0d905f5e44..49d3dc9dcc 100644 --- a/src/ansys/geometry/core/_grpc/_version.py +++ b/src/ansys/geometry/core/_grpc/_version.py @@ -23,28 +23,34 @@ from enum import Enum, unique -from google.protobuf.empty_pb2 import Empty import grpc # ATTEMPT v0 IMPORT try: - import ansys.api.dbu.v0.admin_pb2_grpc as dbu_v0_admin_pb2_grpc + from ansys.api.dbu.v0.admin_pb2_grpc import AdminStub as V0HealthStub + from google.protobuf.empty_pb2 import Empty as V0HealthRequest except ImportError: - dbu_v0_admin_pb2_grpc = None + V0HealthStub = None + V0HealthRequest = None + # ATTEMPT v1 IMPORT try: - import ansys.api.dbu.v1.admin_pb2_grpc as dbu_v1_admin_pb2_grpc + from ansys.api.discovery.v1.commands.communication_pb2 import HealthRequest as V1HealthRequest + from ansys.api.discovery.v1.commands.communication_pb2_grpc import ( + CommunicationStub as V1HealthStub, + ) except ImportError: - dbu_v1_admin_pb2_grpc = None + V1HealthStub = None + V1HealthRequest = None @unique class GeometryApiProtos(Enum): """Enumeration of the supported versions of the gRPC API protocol.""" - V0 = 0, dbu_v0_admin_pb2_grpc - V1 = 1, dbu_v1_admin_pb2_grpc + V0 = 0, V0HealthStub, V0HealthRequest + V1 = 1, V1HealthStub, V1HealthRequest @staticmethod def get_latest_version() -> "GeometryApiProtos": @@ -85,13 +91,14 @@ def verify_supported(self, channel: grpc.Channel) -> bool: ----- This method checks if the server supports the gRPC API protocol version. """ - pb2_grpc = self.value[1] - if pb2_grpc is None: + StubClass = self.value[1] # noqa: N806 + RequestClass = self.value[2] # noqa: N806 + if StubClass is None: return False try: - admin_stub = pb2_grpc.AdminStub(channel) - admin_stub.Health(Empty()) + admin_stub = StubClass(channel) + admin_stub.Health(RequestClass()) return True except grpc.RpcError: return False @@ -126,9 +133,17 @@ def set_proto_version( # If no version specified... Attempt to use all of them, starting # with the latest version if version is None: - version = GeometryApiProtos.get_latest_version() - while not version.verify_supported(channel): - version = GeometryApiProtos.from_int_value(version.value[0] - 1) + # TODO: Once blitz is over, we will enable this... + # https://github.com/ansys/pyansys-geometry/issues/2366 + # + # ---> REPLACE THIS BLOCK <--- + # version = GeometryApiProtos.get_latest_version() + # while not version.verify_supported(channel): + # version = GeometryApiProtos.from_int_value(version.value[0] - 1) + # ---> REPLACE THIS BLOCK <--- + # ---> DELETE THIS BLOCK <--- + version = GeometryApiProtos.V0 + # ---> DELETE THIS BLOCK <--- # Return the version return version diff --git a/src/ansys/geometry/core/connection/client.py b/src/ansys/geometry/core/connection/client.py index 40047242f9..aad71cf2c2 100644 --- a/src/ansys/geometry/core/connection/client.py +++ b/src/ansys/geometry/core/connection/client.py @@ -176,8 +176,9 @@ class GrpcClient: Logging level to apply to the client. logging_file : str or Path, default: None File to output the log to, if requested. - proto_version: str or None, default: None - Version of the gRPC protocol to use. If ``None``, the latest version is used. + proto_version : str | None, default: None + Protocol version to use for communication with the server. If None, v0 is used. + Available versions are "v0", "v1", etc. """ @check_input_types diff --git a/src/ansys/geometry/core/modeler.py b/src/ansys/geometry/core/modeler.py index c72bf352cb..2dd77a1436 100644 --- a/src/ansys/geometry/core/modeler.py +++ b/src/ansys/geometry/core/modeler.py @@ -83,6 +83,9 @@ class Modeler: Logging level to apply to the client. logging_file : str, Path, default: None File to output the log to, if requested. + proto_version : str | None, default: None + Protocol version to use for communication with the server. If None, v0 is used. + Available versions are "v0", "v1", etc. """ def __init__( @@ -96,6 +99,7 @@ def __init__( timeout: Real = 120, logging_level: int = logging.INFO, logging_file: Path | str | None = None, + proto_version: str | None = None, ): """Initialize the ``Modeler`` class.""" from ansys.geometry.core.designer.geometry_commands import GeometryCommands @@ -110,6 +114,7 @@ def __init__( timeout=timeout, logging_level=logging_level, logging_file=logging_file, + proto_version=proto_version, ) # Single design for the Modeler