api.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. r"""观澜 · 后端 —— **对外公开面**(P0 阶段:接口先立,实现仍在既有路径)。
  3. 用户令 2026-09-22:按模块重构源代码目录,**每模块只许经 `api.py` 被别的模块调用**。
  4. 本文件当前把公开名**惰性转发**到既有实现(guanlan.py、scripts/{windscada_serve,guanlan_gateway,guanlan_ops,_ops_*}.py、src/windscada/{config,terms,i18n,lang,report_export}.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. 'config': 'src.windscada.config',
  15. 'terms': 'src.windscada.terms',
  16. 'i18n': 'src.windscada.i18n',
  17. 'lang': 'src.windscada.lang',
  18. 'report_export': 'src.windscada.report_export',
  19. 'deid': 'src.windscada.deid',
  20. 'cms_serve': 'src.windcms.serve',
  21. 'cms_orchestrator': 'src.windcms.orchestrator',
  22. }
  23. __all__ = list(_TARGETS)
  24. def __getattr__(name: str):
  25. target = _TARGETS.get(name)
  26. if target is None:
  27. raise AttributeError(
  28. f'{__name__} 未公开 {name!r};公开面见 __all__ —— 模块间调用只许走 api.py'
  29. )
  30. mod = importlib.import_module(target)
  31. globals()[name] = mod
  32. return mod