api.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. r"""观澜 · 算法 —— **对外公开面**(P0 阶段:接口先立,实现仍在既有路径)。
  3. 用户令 2026-09-22:按模块重构源代码目录,**每模块只许经 `api.py` 被别的模块调用**。
  4. 本文件当前把公开名**惰性转发**到既有实现(src/windscada/{taxonomy,audit}.py、src/windscada/perf/*、src/windscada/subsys/*、src/windcms/{report_std,tcm,knowledge,cross_review,audit_rules,pipeline}.py),因此:
  5. * 调用的行为与重构前完全一致(零行为变化);
  6. * 后续阶段(见 `docs/重构方案_模块化_v0.1.md`)把实现搬到本模块目录后,**只改这里的目标映射**,
  7. 调用方一行都不用动;
  8. * 惰性转发(PEP 562)保证 import 本文件不会连带 import 重依赖。
  9. """
  10. from __future__ import annotations
  11. import importlib
  12. # 公开名 → 现有实现(P0 转发目标;P1 起改为本模块内的实现模块)
  13. _TARGETS: dict[str, str] = {
  14. 'taxonomy': 'src.windscada.taxonomy',
  15. 'audit': 'src.windscada.audit',
  16. 'curves': 'src.windscada.perf.curves',
  17. 'control': 'src.windscada.perf.control',
  18. 'reliability': 'src.windscada.perf.reliability',
  19. 'faults': 'src.windscada.perf.faults',
  20. 'availability': 'src.windscada.perf.availability',
  21. 'trend': 'src.windscada.perf.trend',
  22. 'curtail': 'src.windscada.perf.curtail',
  23. 'powercurve': 'src.windscada.perf.powercurve',
  24. 'fusion': 'src.windscada.subsys.fusion',
  25. 'pitch': 'src.windscada.subsys.pitch',
  26. 'yaw': 'src.windscada.subsys.yaw',
  27. 'hydraulic': 'src.windscada.subsys.hydraulic',
  28. 'temp_nbm': 'src.windscada.subsys.temp_nbm',
  29. 'structure': 'src.windscada.subsys.structure',
  30. 'thermal_chain': 'src.windscada.subsys.thermal_chain',
  31. 'workorder': 'src.windscada.subsys.workorder',
  32. 'cms_report': 'src.windcms.report_std',
  33. 'cms_tcm': 'src.windcms.tcm',
  34. 'cms_knowledge': 'src.windcms.knowledge',
  35. 'cms_review': 'src.windcms.cross_review',
  36. 'cms_rules': 'src.windcms.audit_rules',
  37. 'cms_pipeline': 'src.windcms.pipeline',
  38. }
  39. __all__ = list(_TARGETS)
  40. def __getattr__(name: str):
  41. target = _TARGETS.get(name)
  42. if target is None:
  43. raise AttributeError(
  44. f'{__name__} 未公开 {name!r};公开面见 __all__ —— 模块间调用只许走 api.py'
  45. )
  46. mod = importlib.import_module(target)
  47. globals()[name] = mod
  48. return mod