From 0fdbf7ca12a0face3e77fa9f8af0fd0cfd982328 Mon Sep 17 00:00:00 2001 From: Matteo Bini <91963243+b-matteo@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:01:36 +0100 Subject: [PATCH] Feat/launcher hidden mode (#861) --- .../geometry/core/connection/launcher.py | 6 ++++ .../core/connection/product_instance.py | 30 +++++++++++++++++++ tests/integration/test_launcher_product.py | 2 ++ 3 files changed, 38 insertions(+) diff --git a/src/ansys/geometry/core/connection/launcher.py b/src/ansys/geometry/core/connection/launcher.py index 1e2c67ba69..ba19a88ae9 100644 --- a/src/ansys/geometry/core/connection/launcher.py +++ b/src/ansys/geometry/core/connection/launcher.py @@ -370,6 +370,7 @@ def launch_modeler_with_discovery( timeout: int = 150, manifest_path: str = None, logs_folder: str = None, + hidden: bool = False, ): """ Start Ansys Discovery locally using the ``ProductInstance`` class. @@ -420,6 +421,7 @@ def launch_modeler_with_discovery( version. logs_folder : sets the backend's logs folder path. If nothing is defined, the backend will use its default path. + hidden : starts the product hiding its UI. Default is ``False``. Raises ------ @@ -465,6 +467,7 @@ def launch_modeler_with_discovery( timeout=timeout, manifest_path=manifest_path, logs_folder=logs_folder, + hidden=hidden, ) @@ -477,6 +480,7 @@ def launch_modeler_with_spaceclaim( timeout: int = 150, manifest_path: str = None, logs_folder: str = None, + hidden: bool = False, ): """ Start Ansys SpaceClaim locally using the ``ProductInstance`` class. @@ -524,6 +528,7 @@ def launch_modeler_with_spaceclaim( version. logs_folder : sets the backend's logs folder path. If nothing is defined, the backend will use its default path. + hidden : starts the product hiding its UI. Default is ``False``. Raises ------ @@ -569,6 +574,7 @@ def launch_modeler_with_spaceclaim( timeout=timeout, manifest_path=manifest_path, logs_folder=logs_folder, + hidden=hidden, ) diff --git a/src/ansys/geometry/core/connection/product_instance.py b/src/ansys/geometry/core/connection/product_instance.py index a447cc652f..4c8aeaf808 100644 --- a/src/ansys/geometry/core/connection/product_instance.py +++ b/src/ansys/geometry/core/connection/product_instance.py @@ -102,6 +102,27 @@ To be used only with Ansys Discovery and Ansys SpaceClaim. """ +BACKEND_SPACECLAIM_HIDDEN = "/Headless=True" +""" +The argument to hide SpaceClaim's UI on the backend. + +To be used only with Ansys SpaceClaim. +""" + +BACKEND_DISCOVERY_HIDDEN = "--hidden" +""" +The argument to hide Discovery's UI on the backend. + +To be used only with Ansys Discovery. +""" + +BACKEND_SPLASH_OFF = "/Splash=False" +""" +The argument to specify the backend's addin manifest file's path. + +To be used only with Ansys Discovery and Ansys SpaceClaim. +""" + class ProductInstance: """ @@ -143,6 +164,7 @@ def prepare_and_start_backend( timeout: int = 150, manifest_path: str = None, logs_folder: str = None, + hidden: bool = False, ) -> "Modeler": """ Start the requested service locally using the ``ProductInstance`` class. @@ -187,6 +209,7 @@ def prepare_and_start_backend( version. Only applicable for Ansys Discovery and Ansys SpaceClaim. logs_folder : sets the backend's logs folder path. If nothing is defined, the backend will use its default path. + hidden : starts the product hiding its UI. Default is ``False``. Raises ------ @@ -223,6 +246,10 @@ def prepare_and_start_backend( if backend_type == BackendType.DISCOVERY: args.append(os.path.join(installations[product_version], DISCOVERY_FOLDER, DISCOVERY_EXE)) + if hidden is True: + args.append(BACKEND_DISCOVERY_HIDDEN) + + # Here begins the spaceclaim arguments. args.append(BACKEND_SPACECLAIM_OPTIONS) args.append( BACKEND_ADDIN_MANIFEST_ARGUMENT @@ -231,6 +258,9 @@ def prepare_and_start_backend( env_copy[BACKEND_API_VERSION_VARIABLE] = str(api_version) elif backend_type == BackendType.SPACECLAIM: args.append(os.path.join(installations[product_version], SPACECLAIM_FOLDER, SPACECLAIM_EXE)) + if hidden is True: + args.append(BACKEND_SPACECLAIM_HIDDEN) + args.append(BACKEND_SPLASH_OFF) args.append( BACKEND_ADDIN_MANIFEST_ARGUMENT + _manifest_path_provider(product_version, installations, manifest_path) diff --git a/tests/integration/test_launcher_product.py b/tests/integration/test_launcher_product.py index 1e4838cb85..f485d400a4 100644 --- a/tests/integration/test_launcher_product.py +++ b/tests/integration/test_launcher_product.py @@ -91,6 +91,7 @@ def test_product_launch_with_parameters(): log_level=random.randint(0, 3), api_version=apiVersions[random.randint(0, len(apiVersions) - 1)].value, timeout=180, + hidden=True, ) modeler_spaceclaim = launch_modeler_with_spaceclaim( @@ -99,6 +100,7 @@ def test_product_launch_with_parameters(): log_level=random.randint(0, 3), api_version=apiVersions[random.randint(0, len(apiVersions) - 1)].value, timeout=180, + hidden=True, ) assert modeler_geo_service != None