-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.spec
More file actions
115 lines (102 loc) · 3.06 KB
/
Copy pathbuild.spec
File metadata and controls
115 lines (102 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- mode: python ; coding: utf-8 -*-
from pathlib import Path
import os
import sys
from PyInstaller.utils.hooks import copy_metadata
block_cipher = None
# 获取项目根目录
BASE_DIR = Path(os.getcwd())
BACKEND_DIR = BASE_DIR / "src" / "backend"
# 定义静态文件路径
STATIC_DIR = BASE_DIR / "dist" # 前端构建产物目录
# 检查前端构建是否完成
if not STATIC_DIR.exists():
print("Error: Frontend build directory 'dist' not found. Please run 'pnpm build' first.")
sys.exit(1)
# 数据文件:包含前端静态资源和后端可能需要的配置
datas = [
(str(STATIC_DIR), "static"), # 将 dist 映射到 _internal/static
(str(BASE_DIR / "openapi.json"), "."),
]
# 修复: 显式复制 tortoise-orm 的元数据,解决 importlib.metadata.PackageNotFoundError
datas += copy_metadata("tortoise-orm")
# 核心修复: 包含 migrations 目录下的所有文件
# 确保 migrations 目录存在且不为空
migrations_path = BASE_DIR / "migrations"
if migrations_path.exists():
# 直接添加目录元组 (source_dir, dest_dir_name)
# PyInstaller 会递归复制整个目录
datas.append((str(migrations_path), "migrations"))
else:
print(f"Warning: Migrations directory not found at {migrations_path}")
# 隐藏导入:Tortoise ORM 和其他动态加载的库可能需要
hiddenimports = [
"tortoise.backends.sqlite",
"uvicorn.logging",
"uvicorn.loops",
"uvicorn.loops.auto",
"uvicorn.protocols",
"uvicorn.protocols.http",
"uvicorn.protocols.http.auto",
"uvicorn.protocols.websockets",
"uvicorn.protocols.websockets.auto",
"uvicorn.lifespan",
"uvicorn.lifespan.on",
"src.features.user.backend.models",
"src.features.dashboard.backend.models",
"src.features.monitor.backend.models",
# 手动添加 tortoise 模块依赖
"tortoise.backends.asyncpg",
"tortoise.backends.mysql",
"tortoise.contrib.pydantic",
# importlib.metadata 兼容性
"importlib_metadata",
# aerich 迁移工具
"aerich.models",
"aerich.ddl.sqlite",
"aerich.ddl.mysql",
"aerich.ddl.postgres",
]
a = Analysis(
[str(BACKEND_DIR / "desktop_launcher.py")], # 使用新的桌面启动器作为入口
pathex=[str(BASE_DIR)],
binaries=[],
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='NekroVStack',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True, # 保留控制台以便查看日志,发布时可改为 False
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='NekroVStack',
)