mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 16:07:01 +08:00
refactor backend module architecture
This commit is contained in:
+31
-5
@@ -1,8 +1,34 @@
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def _prepare_direct_execution_import_path() -> None:
|
||||
"""
|
||||
修正直接执行 ``app/main.py`` 时的模块搜索路径。
|
||||
|
||||
PyCharm 的脚本启动方式会把 ``app`` 目录放到 ``sys.path[0]``,导致第三方
|
||||
库的 ``import platform`` 错误命中 ``app/platform``。直接执行时只保留项目
|
||||
根目录作为应用导入入口,模块方式启动则不做任何调整。
|
||||
"""
|
||||
if __package__:
|
||||
return
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
project_root = os.path.dirname(script_dir)
|
||||
sys.path[:] = [
|
||||
entry
|
||||
for entry in sys.path
|
||||
if os.path.realpath(entry or os.curdir) != script_dir
|
||||
]
|
||||
if project_root in sys.path:
|
||||
sys.path.remove(project_root)
|
||||
sys.path.insert(0, project_root)
|
||||
|
||||
|
||||
_prepare_direct_execution_import_path()
|
||||
|
||||
import multiprocessing
|
||||
import setproctitle
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
@@ -10,8 +36,8 @@ import uvicorn as uvicorn
|
||||
from PIL import Image
|
||||
from uvicorn import Config
|
||||
|
||||
from app.utils.stdio import configure_rotating_stdio
|
||||
from app.utils.system import SystemUtils
|
||||
from app.infrastructure.stdio import configure_rotating_stdio
|
||||
from app.infrastructure.system import SystemUtils
|
||||
|
||||
# 禁用输出
|
||||
stdio_log_file = os.getenv("MOVIEPILOT_STDIO_LOG_FILE")
|
||||
@@ -30,7 +56,7 @@ elif SystemUtils.is_frozen():
|
||||
sys.stderr = open(os.devnull, 'w')
|
||||
|
||||
from app.factory import app
|
||||
from app.core.config import global_vars, settings
|
||||
from app.platform.config import global_vars, settings
|
||||
from app.db.init import init_db, update_db
|
||||
|
||||
# 设置进程名
|
||||
|
||||
Reference in New Issue
Block a user