Skip to content

Commit 29e9a0b

Browse files
germa89akaszynski
andauthored
Making PIM package lazy (#1151)
* Making pim lazy * taking advantage of short circuit in logical operations * removing decorator. * Apply suggestions from code review Co-authored-by: Alex Kaszynski <[email protected]>
1 parent 263222d commit 29e9a0b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ansys/mapdl/core/launcher.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
import time
1212
import warnings
1313

14-
import ansys.platform.instancemanagement as pypim
14+
try:
15+
import ansys.platform.instancemanagement as pypim
16+
17+
_HAS_PIM = True
18+
except ModuleNotFoundError: # pragma: no cover
19+
_HAS_PIM = False
20+
1521
import appdirs
1622

1723
from ansys.mapdl import core as pymapdl
@@ -547,6 +553,11 @@ def launch_remote_mapdl(
547553
ansys.mapdl.core.mapdl._MapdlCore
548554
An instance of Mapdl.
549555
"""
556+
if not _HAS_PIM: # pragma: no cover
557+
raise ModuleNotFoundError(
558+
"The package 'ansys-platform-instancemanagement' is required to use this function."
559+
)
560+
550561
pim = pypim.connect()
551562
instance = pim.create_instance(product_name="mapdl", product_version=version)
552563
instance.wait_for_ready()
@@ -1249,7 +1260,7 @@ def launch_mapdl(
12491260

12501261
# Start MAPDL with PyPIM if the environment is configured for it
12511262
# and the user did not pass a directive on how to launch it.
1252-
if pypim.is_configured() and exec_file is None:
1263+
if _HAS_PIM and exec_file is None and pypim.is_configured():
12531264
LOG.info("Starting MAPDL remotely. The startup configuration will be ignored.")
12541265
return launch_remote_mapdl(cleanup_on_exit=cleanup_on_exit)
12551266

0 commit comments

Comments
 (0)