Skip to content

Commit 9d62787

Browse files
jonahrbpyansys-ci-botRobPasMue
authored
feat: launch core service from envar (#1716)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent a28172c commit 9d62787

File tree

3 files changed

+73
-24
lines changed

3 files changed

+73
-24
lines changed

doc/changelog.d/1716.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
launch core service from envar

doc/source/getting_started/local/index.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ either Discovery, SpaceClaim, or the Geometry service.
3535
3636
modeler = launch_modeler_with_geometry_service()
3737
38+
When launching via Geometry Service, if you have a custom local install, you can define the path of this install
39+
in the ANSYS_GEOMETRY_SERVICE_ROOT environment variable. In that case, the launcher uses this location by default.
40+
41+
.. tab-set::
42+
43+
.. tab-item:: Powershell
44+
45+
.. code-block:: pwsh
46+
47+
$env:ANSYS_GEOMETRY_SERVICE_ROOT="C:\Program Files\ANSYS Inc\v252\GeometryService"
48+
# or
49+
$env:ANSYS_GEOMETRY_SERVICE_ROOT="C:\myCustomPath\CoreGeometryService"
50+
51+
.. tab-item:: Windows CMD
52+
53+
.. code-block:: bash
54+
55+
SET ANSYS_GEOMETRY_SERVICE_ROOT="C:\Program Files\ANSYS Inc\v252\GeometryService"
56+
# or
57+
SET ANSYS_GEOMETRY_SERVICE_ROOT="C:\myCustomPath\CoreGeometryService"
58+
59+
.. tab-item:: Linux
60+
61+
.. code-block:: bash
62+
63+
export ANSYS_GEOMETRY_SERVICE_ROOT=/my_path/to/core_geometry_service
64+
3865
3966
For more information on the arguments accepted by the launcher methods, see
4067
their API documentation:

src/ansys/geometry/core/connection/product_instance.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
To be used only with Ansys Discovery and Ansys SpaceClaim.
143143
"""
144144

145+
ANSYS_GEOMETRY_SERVICE_ROOT = "ANSYS_GEOMETRY_SERVICE_ROOT"
146+
"""Local Geometry Service install location. This is for GeometryService and CoreGeometryService."""
147+
145148

146149
class ProductInstance:
147150
"""``ProductInstance`` class.
@@ -283,25 +286,35 @@ def prepare_and_start_backend(
283286

284287
port = _check_port_or_get_one(port)
285288
installations = get_available_ansys_installations()
286-
if product_version is not None:
287-
try:
288-
_check_version_is_available(product_version, installations)
289-
except SystemError as serr:
290-
# The user requested a version as a Student version...
291-
# Let's negate it and try again... if this works, we override the
292-
# product_version variable.
293-
try:
294-
_check_version_is_available(-product_version, installations)
295-
except SystemError:
296-
# The student version is not installed either... raise the original error.
297-
raise serr
298-
299-
product_version = -product_version
289+
if os.getenv(ANSYS_GEOMETRY_SERVICE_ROOT) is not None and backend_type in (
290+
BackendType.WINDOWS_SERVICE,
291+
BackendType.LINUX_SERVICE,
292+
BackendType.CORE_WINDOWS,
293+
BackendType.CORE_LINUX,
294+
):
295+
# If the user has set the ANSYS_GEOMETRY_SERVICE_ROOT environment variable,
296+
# we will use it as the root folder for the Geometry Service.
297+
pass
300298
else:
301-
product_version = get_latest_ansys_installation()[0]
299+
if product_version is not None:
300+
try:
301+
_check_version_is_available(product_version, installations)
302+
except SystemError as serr:
303+
# The user requested a version as a Student version...
304+
# Let's negate it and try again... if this works, we override the
305+
# product_version variable.
306+
try:
307+
_check_version_is_available(-product_version, installations)
308+
except SystemError:
309+
# The student version is not installed either... raise the original error.
310+
raise serr
311+
312+
product_version = -product_version
313+
else:
314+
product_version = get_latest_ansys_installation()[0]
302315

303-
# Verify that the minimum version is installed.
304-
_check_minimal_versions(product_version, specific_minimum_version)
316+
# Verify that the minimum version is installed.
317+
_check_minimal_versions(product_version, specific_minimum_version)
305318

306319
if server_logs_folder is not None:
307320
# Verify that the user has write permissions to the folder and that it exists.
@@ -357,17 +370,27 @@ def prepare_and_start_backend(
357370
)
358371

359372
elif backend_type == BackendType.WINDOWS_SERVICE:
373+
root_service_folder = os.getenv(ANSYS_GEOMETRY_SERVICE_ROOT)
374+
if root_service_folder is None:
375+
root_service_folder = Path(
376+
installations[product_version], WINDOWS_GEOMETRY_SERVICE_FOLDER
377+
)
378+
else:
379+
root_service_folder = Path(root_service_folder)
360380
args.append(
361381
Path(
362-
installations[product_version],
363-
WINDOWS_GEOMETRY_SERVICE_FOLDER,
382+
root_service_folder,
364383
GEOMETRY_SERVICE_EXE,
365384
)
366385
)
367386
# This should be modified to Windows Core Service in the future
368387
elif BackendType.is_core_service(backend_type):
369388
# Define several Ansys Geometry Core Service folders needed
370-
root_service_folder = Path(installations[product_version], CORE_GEOMETRY_SERVICE_FOLDER)
389+
root_service_folder = os.getenv(ANSYS_GEOMETRY_SERVICE_ROOT)
390+
if root_service_folder is None:
391+
root_service_folder = Path(installations[product_version], CORE_GEOMETRY_SERVICE_FOLDER)
392+
else:
393+
root_service_folder = Path(root_service_folder)
371394
native_folder = root_service_folder / "Native"
372395
cad_integration_folder = root_service_folder / "CADIntegration"
373396
schema_folder = root_service_folder / "Schema"
@@ -395,8 +418,7 @@ def prepare_and_start_backend(
395418
# For Windows, we need to use the exe file to launch the Core Geometry Service
396419
args.append(
397420
Path(
398-
installations[product_version],
399-
CORE_GEOMETRY_SERVICE_FOLDER,
421+
root_service_folder,
400422
CORE_GEOMETRY_SERVICE_EXE,
401423
)
402424
)
@@ -431,8 +453,7 @@ def prepare_and_start_backend(
431453
args.append("dotnet")
432454
args.append(
433455
Path(
434-
installations[product_version],
435-
CORE_GEOMETRY_SERVICE_FOLDER,
456+
root_service_folder,
436457
CORE_GEOMETRY_SERVICE_EXE.replace(".exe", ".dll"),
437458
)
438459
)

0 commit comments

Comments
 (0)