api.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. r"""观澜 · 公共层 —— **对外公开面**(P0 阶段:接口先立,实现仍在既有路径)。
  3. 用户令 2026-09-22:按模块重构源代码目录,**每模块只许经 `api.py` 被别的模块调用**。
  4. 本文件当前把公开名**惰性转发**到既有实现(src/{paths,version,logfile,proc,entry_refs,console,opsjob,derived_manifest,tabfmt}.py),因此:
  5. * 调用的行为与重构前完全一致(零行为变化);
  6. * 后续阶段(见 `docs/重构方案_模块化_v0.1.md`)把实现搬到本模块目录后,**只改这里的目标映射**,
  7. 调用方一行都不用动;
  8. * 惰性转发(PEP 562)保证 import 本文件不会连带 import 重依赖。
  9. """
  10. from __future__ import annotations
  11. import importlib
  12. from app_common.app_common_guanlan._root import install_root # noqa: F401 公开面之一
  13. from app_common.app_common_guanlan._alias import alias_prefix # noqa: F401 旧前缀别名(过渡期)
  14. # 公开名 → 实现(P1 起实现就在本模块目录内;P2 起其他模块的构建器经本公开面取安装根)
  15. _TARGETS: dict[str, str] = {
  16. 'paths': 'app_common.app_common_guanlan.paths',
  17. 'version': 'app_common.app_common_guanlan.version',
  18. 'logfile': 'app_common.app_common_guanlan.logfile',
  19. 'proc': 'app_common.app_common_guanlan.proc',
  20. 'entry_refs': 'app_common.app_common_guanlan.entry_refs',
  21. 'console': 'app_common.app_common_guanlan.console',
  22. 'opsjob': 'app_common.app_common_guanlan.opsjob',
  23. 'derived_manifest': 'app_common.app_common_guanlan.derived_manifest',
  24. 'tabfmt': 'app_common.app_common_guanlan.tabfmt',
  25. }
  26. __all__ = list(_TARGETS) + ['install_root', 'alias_prefix']
  27. def __getattr__(name: str):
  28. target = _TARGETS.get(name)
  29. if target is None:
  30. raise AttributeError(
  31. f'{__name__} 未公开 {name!r};公开面见 __all__ —— 模块间调用只许走 api.py'
  32. )
  33. mod = importlib.import_module(target)
  34. globals()[name] = mod
  35. return mod