diff --git a/src/ansys/lumerical/core/autodiscovery.py b/src/ansys/lumerical/core/autodiscovery.py index c7d411d..41ecf03 100644 --- a/src/ansys/lumerical/core/autodiscovery.py +++ b/src/ansys/lumerical/core/autodiscovery.py @@ -22,6 +22,7 @@ """Autodiscover the Lumerical installation directory.""" +import os from pathlib import Path import platform import re @@ -46,6 +47,7 @@ def locate_lumerical_install(): Notes ----- + - Checks the LUMERICAL_HOME environment variable first. If set and valid, uses it. - On Windows, the function searches under "C:\Program Files\Lumerical\" and "C:\Program Files\Ansys Inc\Lumerical". - On Linux, the function searches under "/opt/lumerical/" and "~/Ansys/ansys_inc/Lumerical". @@ -57,6 +59,13 @@ def locate_lumerical_install(): >>> import ansys.lumerical.core as lumapi >>> # use lumapi ... + Example 1a: Set the environment variable before importing the module. + + >>> import os + >>> os.environ["LUMERICAL_HOME"] = r"C:\Program Files\Lumerical\v252\" + >>> import ansys.lumerical.core as lumapi + >>> # use lumapi ... + Example 2: Provide a custom installation path before importing the module. >>> import ansys.api.lumerical.lumapi @@ -73,6 +82,11 @@ def locate_lumerical_install(): """ lumerical_install_dir = None + # Check for environment variable first + env_install_dir = os.environ.get("LUMERICAL_HOME") + if env_install_dir and Path(env_install_dir).exists(): + return env_install_dir + if platform.system() == "Windows": try: import winreg # Import winreg here to avoid errors on non-Windows platforms