Skip to content

feat: Feat/add local launcher #454

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 51 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c043605
add speos rpc launcher for local execution
StefanThoene Feb 12, 2025
dfeb48a
add speos rpc launcher for local execution
StefanThoene Feb 12, 2025
d0c90b3
add speos rpc launcher for local execution
StefanThoene Feb 12, 2025
056186f
add speos rpc launcher for local execution
StefanThoene Feb 12, 2025
0a0fccf
add speos rpc launcher for local execution
StefanThoene Feb 12, 2025
e90c237
move to ansys tools path pacjage
StefanThoene Feb 13, 2025
e9ea54f
remove Path from requirments and switch to inbuild pathlib
StefanThoene Feb 14, 2025
1a98126
adjust docstring
StefanThoene Feb 18, 2025
03e78ef
adjust docstring
StefanThoene Feb 18, 2025
6f79019
adjust docstring
StefanThoene Feb 18, 2025
ede5986
Merge branch 'main' into feat/add-local-launcher
StefanThoene Feb 25, 2025
15a48c4
merge main
StefanThoene Mar 24, 2025
b5faf6a
remove try kill instance
StefanThoene Mar 25, 2025
b744de7
remove try kill instance
StefanThoene Mar 26, 2025
24b90d7
adjust close and test
StefanThoene Mar 26, 2025
2eae017
add psutil to test req
StefanThoene Mar 26, 2025
781eb7f
add psutil to test req
StefanThoene Mar 26, 2025
a7b5268
fix Path(None) issue on test
StefanThoene Mar 26, 2025
4a00b41
fix Path(None) issue on test
StefanThoene Mar 26, 2025
6602d2e
Merge branch 'main' into feat/add-local-launcher
StefanThoene Mar 26, 2025
af1097e
adjust test to only test on windows
StefanThoene Mar 26, 2025
ed28bae
adjust test to only test on windows
StefanThoene Mar 26, 2025
9a03cd5
adjust test to only test on windows
StefanThoene Mar 27, 2025
94c6c6f
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 8, 2025
aa03f05
improve code coverage
StefanThoene Apr 8, 2025
d5ce90d
fix test issue
StefanThoene Apr 8, 2025
1703727
avoid error
StefanThoene Apr 8, 2025
99d3c1a
avoid error
StefanThoene Apr 8, 2025
a59737a
improve test
StefanThoene Apr 8, 2025
b60b24b
chore: adding changelog file 454.added.md [dependabot-skip]
pyansys-ci-bot Apr 8, 2025
21a908e
improve test
StefanThoene Apr 8, 2025
67a1c5c
fix unit test for Speos launcher
StefanThoene Apr 8, 2025
bb1a02d
improve unit test
StefanThoene Apr 8, 2025
2e756b7
improve unit test
StefanThoene Apr 8, 2025
b98662b
improve unit test
StefanThoene Apr 8, 2025
4529c22
fix issue with close
StefanThoene Apr 8, 2025
05f08e5
fix issue with close
StefanThoene Apr 8, 2025
9c97efc
improve coverage by created function for closed connection error
StefanThoene Apr 8, 2025
de17dbc
move install not found error to general methods for reuse
StefanThoene Apr 8, 2025
d81ac41
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 8, 2025
2273299
adjust code based on code review
StefanThoene Apr 11, 2025
14dc7b3
adjust code based on code review
StefanThoene Apr 11, 2025
2b40e04
fix circular import and side effects
StefanThoene Apr 11, 2025
d1fe2c6
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 11, 2025
89fdaf3
implment adjustment based on code review
StefanThoene Apr 14, 2025
045ff8e
Apply suggestions from code review
StefanThoene Apr 14, 2025
aeadbef
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 14, 2025
c5583ef
Update src/ansys/speos/core/kernel/client.py
StefanThoene Apr 14, 2025
82afa35
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 14, 2025
6938d3d
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 14, 2025
2a4c0f8
Merge branch 'main' into feat/add-local-launcher
StefanThoene Apr 14, 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/454.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feat/add local launcher
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies=[
"grpcio>=1.50.0,<1.71",
"grpcio-health-checking>=1.45.0,<1.68",
"ansys-api-speos==0.14.2",
"ansys-tools-path>=0.3.1",
"numpy>=1.20.3,<3",
"comtypes>=1.4,<1.5",
]
Expand All @@ -41,6 +42,7 @@ graphics = [
"ansys-tools-visualization-interface>=0.8.3",
]
tests = [
"psutil==6.1.1",
"pytest==8.3.5",
"pyvista>=0.40.0,<0.45",
"ansys-tools-visualization-interface>=0.8.3",
Expand Down
36 changes: 36 additions & 0 deletions src/ansys/speos/core/generic/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2021 - 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.

"""Collection of all constants used in pySpeos."""

import os

DEFAULT_HOST = "localhost"
"""Default host used by Speos RPC server and client """
DEFAULT_PORT = "50098"
"""Default port used by Speos RPC server and client """
LATEST_VERSION = "251"
"""Latest supported Speos version of the current PySpeos Package"""
MAX_MESSAGE_LENGTH = int(os.environ.get("SPEOS_MAX_MESSAGE_LENGTH", 256 * 1024**2))
"""Maximum message length value accepted by the Speos RPC server,
By default, value stored in environment variable SPEOS_MAX_MESSAGE_LENGTH or 268 435 456.
"""
71 changes: 71 additions & 0 deletions src/ansys/speos/core/generic/general_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
"""

from functools import wraps
import os
from pathlib import Path
from typing import Optional, Union
import warnings

from ansys.speos.core.generic.constants import LATEST_VERSION
from ansys.tools.path import get_available_ansys_installations

__GRAPHICS_AVAILABLE = None
GRAPHICS_ERROR = (
"Preview unsupported without 'ansys-tools-visualization_interface' installed. "
Expand Down Expand Up @@ -108,3 +114,68 @@ def wrapper(*args, **kwargs):
return method(*args, **kwargs)

return wrapper


def error_no_install(install_loc: Union[Path, str], version: Union[int, str]):
"""Raise error that installation was not found at a location.

Parameters
----------
install_loc : Union[Path, str]
Installation Path
version : Union[int, str]
Version
"""
if not install_loc:
install_loc_msg = ""
else:
install_loc_msg = f"at {Path(install_loc).parent}"
raise FileNotFoundError(
f"Ansys Speos RPC server installation not found{install_loc_msg}. "
f"Please define AWP_ROOT{version} environment variable"
)


def retrieve_speos_install_dir(
speos_rpc_loc: Optional[Union[Path, str]], version: str = LATEST_VERSION
):
"""Retrieve Speos install location based on Path or Environment.

Parameters
----------
speos_rpc_loc : Optional[str, Path]
location of Speos rpc executable
version : str
The Speos server version to run, in the 3 digits format, such as "242".
If unspecified, the version will be chosen as
``ansys.speos.core.kernel.client.LATEST_VERSION``.

"""
if not speos_rpc_loc:
speos_rpc_loc = ""
if not speos_rpc_loc or not Path(speos_rpc_loc).exists():
if not Path(speos_rpc_loc).exists():
warnings.warn(
"Provided executable location not found, looking for local installation",
UserWarning,
)
versions = get_available_ansys_installations()
ansys_loc = versions.get(int(version), False)
if not ansys_loc:
ansys_loc = os.environ.get("AWP_ROOT{}".format(version), False)
if not ansys_loc:
error_no_install(speos_rpc_loc, int(version))

speos_rpc_loc = Path(ansys_loc) / "Optical Products" / "SPEOS_RPC"
elif Path(speos_rpc_loc).is_file():
if "SpeosRPC_Server" not in Path(speos_rpc_loc).name:
error_no_install(speos_rpc_loc, int(version))
else:
speos_rpc_loc = Path(speos_rpc_loc).parent
if os.name == "nt":
speos_exec = speos_rpc_loc / "SpeosRPC_Server.exe"
else:
speos_exec = speos_rpc_loc / "SpeosRPC_Server.x"
if not speos_exec.is_file():
error_no_install(speos_rpc_loc, int(version))
return speos_rpc_loc
Loading