mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-15 19:14:01 +08:00
refactor: reorganize backend module boundaries
This commit is contained in:
@@ -112,24 +112,24 @@ def _prepend_sys_path(path: Path) -> None:
|
||||
|
||||
|
||||
def ensure_sites_stub() -> None:
|
||||
"""为 ``app.infrastructure.sites`` 补最小垫片(仅在缺失时)。
|
||||
"""为 ``app.application.site.sites`` 补最小垫片(仅在缺失时)。
|
||||
|
||||
``app.infrastructure.sites`` 由独立仓库动态拉取,CI / 全新环境无该模块,而众多 ``app.chain.*`` /
|
||||
``app.application.site.sites`` 由独立仓库动态拉取,CI / 全新环境无该模块,而众多 ``app.chain.*`` /
|
||||
``app.modules.*`` 在 import 期依赖它。统一补一个最小垫片,省去各测试文件各自打桩;若真实模块
|
||||
已存在(本地已拉取)则用真实模块、不覆盖,不影响真实行为。须在隔离 CONFIG_DIR 之后调用,
|
||||
以免试探性 ``import app.infrastructure.sites`` 触发的连库落到真实库。
|
||||
以免试探性 ``import app.application.site.sites`` 触发的连库落到真实库。
|
||||
"""
|
||||
if "app.infrastructure.sites" in sys.modules:
|
||||
if "app.application.site.sites" in sys.modules:
|
||||
return
|
||||
try:
|
||||
import app.infrastructure.sites # noqa: F401 本地已拉取时用真实模块
|
||||
import app.application.site.sites # noqa: F401 本地已拉取时用真实模块
|
||||
except (ModuleNotFoundError, ImportError):
|
||||
from importlib.util import spec_from_loader
|
||||
from types import ModuleType
|
||||
stub = ModuleType("app.infrastructure.sites")
|
||||
stub = ModuleType("app.application.site.sites")
|
||||
stub.SitesHelper = _SitesHelperStub
|
||||
stub.__spec__ = spec_from_loader("app.infrastructure.sites", None)
|
||||
sys.modules["app.infrastructure.sites"] = stub
|
||||
stub.__spec__ = spec_from_loader("app.application.site.sites", None)
|
||||
sys.modules["app.application.site.sites"] = stub
|
||||
|
||||
|
||||
def ensure_optional_stub(name: str, **attrs) -> None:
|
||||
@@ -162,7 +162,7 @@ def prepare_backend() -> None:
|
||||
"""隔离 CONFIG_DIR、补 sites 垫片并建表(后端须已在 ``sys.path`` 上)。
|
||||
|
||||
主程序中后端即当前包;插件仓由其 ``tests/_bootstrap.py`` shim 在 import 本模块前
|
||||
先把后端目录注入 ``sys.path``。顺序固定:先隔离 CONFIG_DIR,再补 ``app.infrastructure.sites`` 垫片,
|
||||
先把后端目录注入 ``sys.path``。顺序固定:先隔离 CONFIG_DIR,再补 ``app.application.site.sites`` 垫片,
|
||||
最后建表——隔离出的临时库为空,运行期查 ``systemconfig`` 等表会报 no such table,故建表;
|
||||
``init_db`` 仅 import models + create_all,无 alembic/网络、幂等、毫秒级。
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user