LumAPI 1.1.2__tar.gz → 1.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ # LumAPI/__init__.py
2
+
3
+ # 显式导入所有需要对外暴露的类和函数
4
+ from .lumapi import (
5
+ lumapi, lumerical, LumFuncBase,
6
+ FDTD, MODE, DEVICE, INTERCONNECT,
7
+ savemat, loadmat,
8
+ create_cmap, set_colorbar_range,
9
+ Estimate_focal, Kirchhoff,
10
+ RayleighSommerfeld_Scalar, RayleighSommerfeld_Vector, AngularSpectrum_Vector
11
+ )
12
+
13
+ # 定义 import * 时对外暴露的接口白名单(这是静态检查器识别 import * 的关键)
14
+ __all__ = [
15
+ 'lumapi', 'lumerical', 'LumFuncBase',
16
+ 'FDTD', 'MODE', 'DEVICE', 'INTERCONNECT',
17
+ 'savemat', 'loadmat',
18
+ 'create_cmap', 'set_colorbar_range',
19
+ 'Estimate_focal', 'Kirchhoff',
20
+ 'RayleighSommerfeld_Scalar', 'RayleighSommerfeld_Vector', 'AngularSpectrum_Vector'
21
+ ]
@@ -1002,7 +1002,12 @@ def detect_version(lumerical_root):
1002
1002
 
1003
1003
  def get_lumapi_path(lumerical_root, version):
1004
1004
  """从Lumerical根路径和版本获取lumapi.py路径"""
1005
- return os.path.join(lumerical_root, version, "api", "python", "lumapi.py")
1005
+ base = os.path.join(lumerical_root, version)
1006
+ p1 = os.path.join(base, "Lumerical", "api", "python", "lumapi.py")
1007
+ if os.path.exists(p1): return p1
1008
+ p2 = os.path.join(base, "api", "python", "lumapi.py")
1009
+ if os.path.exists(p2): return p2
1010
+ return None
1006
1011
 
1007
1012
  def validate_path(lumerical_root: str, version: str = None) -> object:
1008
1013
  """验证Lumerical路径有效性并返回lumapi对象
@@ -1031,7 +1036,7 @@ def validate_path(lumerical_root: str, version: str = None) -> object:
1031
1036
  # 获取lumapi.py的完整路径
1032
1037
  lumapi_path = get_lumapi_path(lumerical_root, version)
1033
1038
 
1034
- if not os.path.exists(lumapi_path):
1039
+ if not lumapi_path:
1035
1040
  print(f"错误:在指定路径未找到 lumapi.py 文件(查找路径:{lumapi_path})")
1036
1041
  return None
1037
1042
 
@@ -1081,6 +1086,10 @@ class lumerical:
1081
1086
  except Exception:
1082
1087
  self.lumapi = None
1083
1088
 
1089
+ def __bool__(self):
1090
+ """判断配置是否成功,允许直接使用 if lumapi: 来判断"""
1091
+ return self.lumapi is not None
1092
+
1084
1093
  def _check_config_and_prompt(self):
1085
1094
  """核心逻辑:检查配置状态,若无效则引导用户使用 LumAPI 命令"""
1086
1095
  if self.lumapi is None: