Skip to content

feat: grpc common layer architecture, bodies stub and admin stub implementation #1867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
262e764
feat: creating proto version setter
RobPasMue Mar 12, 2025
cdce481
wip: bodies service layer
RobPasMue Mar 13, 2025
4bc0302
wip: full implementation for sphere body
RobPasMue Mar 17, 2025
4094238
wip: general conversions
RobPasMue Mar 17, 2025
ecebabb
fix: import issue
RobPasMue Mar 17, 2025
4a04842
feat: define all abstract bodies methods used
RobPasMue Mar 17, 2025
2b72e7a
feat: raise error if abstractmethod is called
RobPasMue Mar 18, 2025
a477c49
feat: relocate protect_grpc calls
RobPasMue Mar 18, 2025
6f9642a
Revert "feat: raise error if abstractmethod is called"
RobPasMue Mar 18, 2025
d5dfa9f
fix: instantiate all abstract methods on v0 implementation
RobPasMue Mar 18, 2025
91e1aeb
wip: implement delete and translate
RobPasMue Mar 18, 2025
4bd0707
wip: continuing to implement bodies stub methods
RobPasMue Mar 25, 2025
a026a62
chore: adding changelog file 1867.added.md [dependabot-skip]
pyansys-ci-bot Mar 25, 2025
b7676fd
wip: adding new methods
RobPasMue Mar 25, 2025
47fab9a
wip: adding tesellation endpoints
RobPasMue Mar 25, 2025
926563e
wip: cleanup the Body object completely
RobPasMue Mar 26, 2025
33f0d4f
wip: expanding components implementations
RobPasMue Mar 26, 2025
e19a94c
wip: full removal of bodies stub
RobPasMue Mar 27, 2025
135c249
fix: cleanup unused functions
RobPasMue Mar 27, 2025
8e053f3
docs: exclude _grpc folder from docs
RobPasMue Mar 31, 2025
b5bfd1f
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Mar 31, 2025
1520a6b
Merge branch 'main' into feat/grpc-common-layer
RobPasMue Mar 31, 2025
0950238
fix: pragma statements
RobPasMue Mar 31, 2025
a72e2d0
Merge branch 'feat/grpc-common-layer' of https://github.com/ansys/pya…
RobPasMue Mar 31, 2025
8a53ea1
ci: do not consider typechecking in coverage
RobPasMue Mar 31, 2025
ccde5f5
fix: pragma statements in abstract class
RobPasMue Mar 31, 2025
1ea5a0a
Merge branch 'main' into feat/grpc-common-layer
RobPasMue Apr 1, 2025
b34585e
Merge branch 'main' into feat/grpc-common-layer
RobPasMue Apr 2, 2025
fedb803
fix: missing v1 unimplemented model
RobPasMue Apr 2, 2025
434a0a9
feat: adding admin stub
RobPasMue Apr 2, 2025
527586f
chore: adding changelog file 1867.added.md [dependabot-skip]
pyansys-ci-bot Apr 2, 2025
a4ecb7c
fix: typo
RobPasMue Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/1867.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grpc common layer architecture, bodies stub and admin stub implementation
1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def intersphinx_pyansys_geometry(switcher_version: str):
"design.grid",
"config.cache",
"design.fa-build",
"toc.not_included", # Caused by the autoapi extension and the "_grpc" folder
]

# Examples gallery customization
Expand Down
116 changes: 116 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import grpc

from .._version import GeometryApiProtos, set_proto_version
from .base.bodies import GRPCBodyService


class _GRPCServices:
"""
Placeholder for the gRPC services (i.e. stubs).

Notes
-----
This class provides a unified interface to access the different
gRPC services available in the Geometry API. It allows for easy
switching between different versions of the API by using the
`version` parameter in the constructor. The services are lazy-loaded
to avoid unnecessary imports and to improve performance.

Parameters
----------
channel : grpc.Channel
The gRPC channel to the server.
version : GeometryApiProtos | str | None
The version of the gRPC API protocol to use. If None, the latest
version is used.
"""

def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | None = None):
"""
Initialize the GRPCServices class.

Parameters
----------
channel : grpc.Channel
The gRPC channel to the server.
version : GeometryApiProtos | str | None
The version of the gRPC API protocol to use. If None, the latest
version is used.
"""
# Set the proto version to be used
self.version = set_proto_version(channel, version)
self.channel = channel

# Lazy load all the services
self._admin = None
self._bodies = None

@property
def bodies(self) -> GRPCBodyService:
"""
Get the body service for the specified version.

Returns
-------
BodyServiceBase
The body service for the specified version.
"""
if not self._bodies:
# Import the appropriate body service based on the version
from .v0.bodies import GRPCBodyServiceV0
from .v1.bodies import GRPCBodyServiceV1

if self.version == GeometryApiProtos.V0:
self._bodies = GRPCBodyServiceV0(self.channel)
elif self.version == GeometryApiProtos.V1:
self._bodies = GRPCBodyServiceV1(self.channel)
else:
raise ValueError(f"Unsupported version: {self.version}")

return self._bodies

@property
def admin(self):
"""
Get the admin service for the specified version.

Returns
-------
AdminServiceBase
The admin service for the specified version.
"""
if not self._admin:
# Import the appropriate admin service based on the version
from .v0.admin import GRPCAdminServiceV0
from .v1.admin import GRPCAdminServiceV1

if self.version == GeometryApiProtos.V0:
self._admin = GRPCAdminServiceV0(self.channel)
elif self.version == GeometryApiProtos.V1:
self._admin = GRPCAdminServiceV1(self.channel)
else:
raise ValueError(f"Unsupported version: {self.version}")

return self._admin
50 changes: 50 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/base/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module containing the admin service implementation (abstraction layer)."""

from abc import ABC, abstractmethod

import grpc


class GRPCAdminService(ABC):
"""Admin service for gRPC communication with the Geometry server.

Parameters
----------
channel : grpc.Channel
The gRPC channel to the server.
"""

def __init__(self, channel: grpc.Channel):
"""Initialize the AdminServiceBase class."""
pass # pragma: no cover

@abstractmethod
def get_backend(self, **kwargs) -> dict:
"""Get server information."""
pass # pragma: no cover

@abstractmethod
def get_logs(self, **kwargs) -> dict:
"""Get server logs."""
pass # pragma: no cover
205 changes: 205 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/base/bodies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module containing the bodies service implementation (abstraction layer)."""

from abc import ABC, abstractmethod

import grpc


class GRPCBodyService(ABC):
"""Body service for gRPC communication with the Geometry server.

Parameters
----------
channel : grpc.Channel
The gRPC channel to the server.
"""

def __init__(self, channel: grpc.Channel):
"""Initialize the BodyServiceBase class."""
pass # pragma: no cover

@abstractmethod
def create_sphere_body(self, **kwargs) -> dict:
"""Create a sphere body."""
pass # pragma: no cover

@abstractmethod
def create_extruded_body(self, **kwargs) -> dict:
"""Create an extruded body."""
pass # pragma: no cover

@abstractmethod
def create_sweeping_profile_body(self, **kwargs) -> dict:
"""Create a sweeping profile body."""
pass # pragma: no cover

@abstractmethod
def create_sweeping_chain(self, **kwargs) -> dict:
"""Create a sweeping chain."""
pass # pragma: no cover

@abstractmethod
def create_extruded_body_from_face_profile(self, **kwargs) -> dict:
"""Create an extruded body from a face profile."""
pass # pragma: no cover

@abstractmethod
def create_extruded_body_from_loft_profiles(self, **kwargs) -> dict:
"""Create an extruded body from loft profiles."""
pass # pragma: no cover

@abstractmethod
def create_planar_body(self, **kwargs) -> dict:
"""Create a planar body."""
pass # pragma: no cover

@abstractmethod
def create_body_from_face(self, **kwargs) -> dict:
"""Create a body from a face."""
pass # pragma: no cover

@abstractmethod
def create_surface_body(self, **kwargs) -> dict:
"""Create a surface body."""
pass # pragma: no cover

@abstractmethod
def create_surface_body_from_trimmed_curves(self, **kwargs) -> dict:
"""Create a surface body from trimmed curves."""
pass # pragma: no cover

@abstractmethod
def translate(self, **kwargs) -> dict:
"""Translate a body."""
pass # pragma: no cover

@abstractmethod
def delete(self, **kwargs) -> dict:
"""Delete a body."""
pass # pragma: no cover

@abstractmethod
def is_suppressed(self, **kwargs) -> dict:
"""Check if a body is suppressed."""
pass # pragma: no cover

@abstractmethod
def get_color(self, **kwargs) -> dict:
"""Get the color of a body."""
pass # pragma: no cover

@abstractmethod
def get_faces(self, **kwargs) -> dict:
"""Get the faces of a body."""
pass # pragma: no cover

@abstractmethod
def get_edges(self, **kwargs) -> dict:
"""Get the edges of a body."""
pass # pragma: no cover

@abstractmethod
def get_volume(self, **kwargs) -> dict:
"""Get the volume of a body."""
pass # pragma: no cover

@abstractmethod
def get_bounding_box(self, **kwargs) -> dict:
"""Get the bounding box of a body."""
pass # pragma: no cover

@abstractmethod
def set_assigned_material(self, **kwargs) -> dict:
"""Set the assigned material of a body."""
pass # pragma: no cover

@abstractmethod
def get_assigned_material(self, **kwargs) -> dict:
"""Get the assigned material of a body."""
pass # pragma: no cover

@abstractmethod
def set_name(self, **kwargs) -> dict:
"""Set the name of a body."""
pass # pragma: no cover

@abstractmethod
def set_fill_style(self, **kwargs) -> dict:
"""Set the fill style of a body."""
pass # pragma: no cover

@abstractmethod
def set_suppressed(self, **kwargs) -> dict:
"""Set the suppressed state of a body."""
pass # pragma: no cover

@abstractmethod
def set_color(self, **kwargs) -> dict:
"""Set the color of a body."""
pass # pragma: no cover

@abstractmethod
def rotate(self, **kwargs) -> dict:
"""Rotate a body."""
pass # pragma: no cover

@abstractmethod
def scale(self, **kwargs) -> dict:
"""Scale a body."""
pass # pragma: no cover

@abstractmethod
def mirror(self, **kwargs) -> dict:
"""Mirror a body."""
pass # pragma: no cover

@abstractmethod
def map(self, **kwargs) -> dict:
"""Map a body."""
pass # pragma: no cover

@abstractmethod
def get_collision(self, **kwargs) -> dict:
"""Get the collision of a body."""
pass # pragma: no cover

@abstractmethod
def copy(self, **kwargs) -> dict:
"""Copy a body."""
pass # pragma: no cover

@abstractmethod
def get_tesellation(self, **kwargs) -> dict:
"""Get the tessellation of a body."""
pass # pragma: no cover

@abstractmethod
def get_tesellation_with_options(self, **kwargs) -> dict:
"""Get the tessellation of a body with options."""
pass # pragma: no cover

@abstractmethod
def boolean(self, **kwargs) -> dict:
"""Boolean operation."""
pass # pragma: no cover
Loading
Loading