Skip to content
Open
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions src/ansys/lumerical/core/autodiscovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"""Autodiscover the Lumerical installation directory."""

import os
from pathlib import Path
import platform
import re
Expand All @@ -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".
Expand All @@ -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
Expand All @@ -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
Expand Down