unifypy 2.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unifypy/__init__.py +7 -0
- unifypy/__main__.py +21 -0
- unifypy/cli/__init__.py +10 -0
- unifypy/cli/argument_parser.py +209 -0
- unifypy/core/__init__.py +8 -0
- unifypy/core/config.py +491 -0
- unifypy/core/context.py +36 -0
- unifypy/core/engine.py +93 -0
- unifypy/core/environment.py +509 -0
- unifypy/core/event_bus.py +37 -0
- unifypy/core/events.py +16 -0
- unifypy/core/platforms.py +58 -0
- unifypy/core/plugin.py +65 -0
- unifypy/core/validators/__init__.py +10 -0
- unifypy/core/validators/tool_validator.py +144 -0
- unifypy/platforms/__init__.py +10 -0
- unifypy/platforms/base.py +127 -0
- unifypy/platforms/linux/__init__.py +10 -0
- unifypy/platforms/linux/deb_packager.py +289 -0
- unifypy/platforms/linux/rpm_packager.py +332 -0
- unifypy/platforms/macos/__init__.py +10 -0
- unifypy/platforms/macos/dmg_packager.py +477 -0
- unifypy/platforms/macos/post_processor.py +272 -0
- unifypy/platforms/registry.py +108 -0
- unifypy/platforms/windows/__init__.py +9 -0
- unifypy/platforms/windows/inno_setup.py +715 -0
- unifypy/plugins/__init__.py +3 -0
- unifypy/plugins/auto_rollback_plugin.py +156 -0
- unifypy/plugins/cleanup_plugin.py +22 -0
- unifypy/plugins/config_plugin.py +42 -0
- unifypy/plugins/dry_run_plugin.py +22 -0
- unifypy/plugins/environment_plugin.py +61 -0
- unifypy/plugins/external_plugins_loader.py +42 -0
- unifypy/plugins/packaging_plugin.py +125 -0
- unifypy/plugins/prepare_plugin.py +89 -0
- unifypy/plugins/progress_plugin.py +32 -0
- unifypy/plugins/pyinstaller_plugin.py +95 -0
- unifypy/plugins/rollback_plugin.py +62 -0
- unifypy/plugins/summary_plugin.py +36 -0
- unifypy/plugins/windows_language_plugin.py +85 -0
- unifypy/pyinstaller/__init__.py +7 -0
- unifypy/pyinstaller/config_builder.py +908 -0
- unifypy/templates/ChineseSimplified.isl.template +403 -0
- unifypy/templates/setup.iss.template +51 -0
- unifypy/tools/create-dmg/.this-is-the-create-dmg-repo +3 -0
- unifypy/tools/create-dmg/LICENSE +22 -0
- unifypy/tools/create-dmg/Makefile +33 -0
- unifypy/tools/create-dmg/README.md +126 -0
- unifypy/tools/create-dmg/builder/create-dmg.builder +26 -0
- unifypy/tools/create-dmg/create-dmg +621 -0
- unifypy/tools/create-dmg/doc-project/Developer Notes.md +35 -0
- unifypy/tools/create-dmg/doc-project/Release Checklist.md +10 -0
- unifypy/tools/create-dmg/examples/01-main-example/installer_background.png +0 -0
- unifypy/tools/create-dmg/examples/01-main-example/sample +30 -0
- unifypy/tools/create-dmg/examples/01-main-example/source_folder/Application.app +0 -0
- unifypy/tools/create-dmg/support/eula-resources-template.xml +105 -0
- unifypy/tools/create-dmg/support/template.applescript +74 -0
- unifypy/tools/create-dmg/tests/007-space-in-dir-name/my files/hello.txt +1 -0
- unifypy/tools/create-dmg/tests/007-space-in-dir-name/run-test +5 -0
- unifypy/utils/__init__.py +10 -0
- unifypy/utils/cache_manager.py +957 -0
- unifypy/utils/command_runner.py +195 -0
- unifypy/utils/entitlements_generator.py +450 -0
- unifypy/utils/file_ops.py +333 -0
- unifypy/utils/icon_converter.py +144 -0
- unifypy/utils/info_plist_updater.py +247 -0
- unifypy/utils/macos_codesign.py +225 -0
- unifypy/utils/parallel_builder.py +355 -0
- unifypy/utils/progress.py +371 -0
- unifypy/utils/progress_callback_factory.py +56 -0
- unifypy/utils/rollback.py +484 -0
- unifypy/utils/tool_manager.py +701 -0
- unifypy-2.0.2.dist-info/METADATA +609 -0
- unifypy-2.0.2.dist-info/RECORD +78 -0
- unifypy-2.0.2.dist-info/WHEEL +5 -0
- unifypy-2.0.2.dist-info/entry_points.txt +2 -0
- unifypy-2.0.2.dist-info/licenses/LICENSE +21 -0
- unifypy-2.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
环境管理器 处理构建环境的准备和清理.
|
|
5
|
+
支持现代化的规范化架构映射系统 (2024 标准)
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import platform
|
|
9
|
+
import subprocess
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Dict, Optional
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class EnvironmentManager:
|
|
16
|
+
"""
|
|
17
|
+
环境管理器 - 支持规范化架构映射和现代分发标准.
|
|
18
|
+
|
|
19
|
+
内部架构键规范:
|
|
20
|
+
- win-x64, win-arm64
|
|
21
|
+
- mac-arm64, mac-x64
|
|
22
|
+
- linux-x64-glibc, linux-arm64-glibc
|
|
23
|
+
- linux-x64-musl, linux-arm64-musl
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, project_dir: str):
|
|
27
|
+
"""初始化环境管理器.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
project_dir: 项目目录
|
|
31
|
+
"""
|
|
32
|
+
self.project_dir = Path(project_dir).resolve()
|
|
33
|
+
self.current_platform = self._detect_platform()
|
|
34
|
+
self.current_arch = self._detect_raw_architecture()
|
|
35
|
+
self.normalized_arch = self._normalize_architecture()
|
|
36
|
+
self.c_runtime = self._detect_c_runtime() if self.current_platform == "linux" else None
|
|
37
|
+
self.internal_key = self._generate_internal_key()
|
|
38
|
+
|
|
39
|
+
def _detect_platform(self) -> str:
|
|
40
|
+
"""
|
|
41
|
+
检测当前平台.
|
|
42
|
+
"""
|
|
43
|
+
system = platform.system().lower()
|
|
44
|
+
if system == "darwin":
|
|
45
|
+
return "mac"
|
|
46
|
+
elif system == "windows":
|
|
47
|
+
return "win"
|
|
48
|
+
elif system == "linux":
|
|
49
|
+
return "linux"
|
|
50
|
+
else:
|
|
51
|
+
return system
|
|
52
|
+
|
|
53
|
+
def _detect_raw_architecture(self) -> str:
|
|
54
|
+
"""
|
|
55
|
+
检测原始架构标识.
|
|
56
|
+
"""
|
|
57
|
+
return platform.machine().lower()
|
|
58
|
+
|
|
59
|
+
def _normalize_architecture(self) -> str:
|
|
60
|
+
"""
|
|
61
|
+
将各种系统返回的机型字符串规范化为内部架构键.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
str: 规范化的架构标识 (x64, arm64)
|
|
65
|
+
"""
|
|
66
|
+
machine = self.current_arch
|
|
67
|
+
|
|
68
|
+
# AMD64|x86_64 → x64
|
|
69
|
+
if machine in ["x86_64", "amd64"]:
|
|
70
|
+
return "x64"
|
|
71
|
+
|
|
72
|
+
# ARM64|aarch64|arm64 → arm64
|
|
73
|
+
elif machine in ["aarch64", "arm64", "armv8", "armv8l"]:
|
|
74
|
+
return "arm64"
|
|
75
|
+
|
|
76
|
+
# 不再支持 32 位架构
|
|
77
|
+
elif machine in ["i386", "i686", "i586", "armv7", "armv7l", "armhf", "arm"]:
|
|
78
|
+
raise ValueError(f"不支持的 32 位架构: {machine}。UnifyPy 2.0 仅支持 64 位架构。")
|
|
79
|
+
|
|
80
|
+
else:
|
|
81
|
+
raise ValueError(f"不支持的架构: {machine}")
|
|
82
|
+
|
|
83
|
+
def _detect_c_runtime(self) -> Optional[str]:
|
|
84
|
+
"""
|
|
85
|
+
检测 Linux C 运行时 (glibc/musl).
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
str: 'glibc' 或 'musl'
|
|
89
|
+
"""
|
|
90
|
+
if self.current_platform != "linux":
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
# 检测 ldd --version 是否包含 musl
|
|
95
|
+
result = subprocess.run(
|
|
96
|
+
["ldd", "--version"],
|
|
97
|
+
capture_output=True,
|
|
98
|
+
text=True,
|
|
99
|
+
timeout=5
|
|
100
|
+
)
|
|
101
|
+
output = result.stderr.lower() + result.stdout.lower()
|
|
102
|
+
|
|
103
|
+
if "musl" in output:
|
|
104
|
+
return "musl"
|
|
105
|
+
else:
|
|
106
|
+
return "glibc" # 默认为 glibc (manylinux)
|
|
107
|
+
|
|
108
|
+
except (subprocess.TimeoutExpired, subprocess.CalledProcessError, FileNotFoundError):
|
|
109
|
+
# 备用检测方法:检查 /lib/libc.musl* 文件
|
|
110
|
+
try:
|
|
111
|
+
musl_files = list(Path("/lib").glob("libc.musl*"))
|
|
112
|
+
if musl_files:
|
|
113
|
+
return "musl"
|
|
114
|
+
except:
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
# 默认假设为 glibc
|
|
118
|
+
return "glibc"
|
|
119
|
+
|
|
120
|
+
def _is_rosetta(self) -> bool:
|
|
121
|
+
"""
|
|
122
|
+
检测是否在 macOS Rosetta 下运行.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
bool: 是否在 Rosetta 下运行
|
|
126
|
+
"""
|
|
127
|
+
if self.current_platform != "mac":
|
|
128
|
+
return False
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
result = subprocess.run(
|
|
132
|
+
["sysctl", "-in", "sysctl.proc_translated"],
|
|
133
|
+
capture_output=True,
|
|
134
|
+
text=True,
|
|
135
|
+
timeout=5
|
|
136
|
+
)
|
|
137
|
+
return result.stdout.strip() == "1"
|
|
138
|
+
except:
|
|
139
|
+
return False
|
|
140
|
+
|
|
141
|
+
def _generate_internal_key(self) -> str:
|
|
142
|
+
"""
|
|
143
|
+
生成规范化的内部架构键.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
str: 内部架构键 (如 mac-arm64, linux-x64-glibc)
|
|
147
|
+
"""
|
|
148
|
+
base_key = f"{self.current_platform}-{self.normalized_arch}"
|
|
149
|
+
|
|
150
|
+
# Linux 需要添加 C 运行时标识
|
|
151
|
+
if self.current_platform == "linux":
|
|
152
|
+
base_key += f"-{self.c_runtime}"
|
|
153
|
+
|
|
154
|
+
return base_key
|
|
155
|
+
|
|
156
|
+
def get_internal_key(self) -> str:
|
|
157
|
+
"""
|
|
158
|
+
获取当前环境的内部架构键.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
str: 内部架构键
|
|
162
|
+
"""
|
|
163
|
+
return self.internal_key
|
|
164
|
+
|
|
165
|
+
def get_rosetta_info(self) -> Dict[str, Any]:
|
|
166
|
+
"""
|
|
167
|
+
获取 Rosetta 相关信息.
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
Dict: Rosetta 信息
|
|
171
|
+
"""
|
|
172
|
+
if self.current_platform != "mac":
|
|
173
|
+
return {"supported": False, "running": False}
|
|
174
|
+
|
|
175
|
+
is_rosetta = self._is_rosetta()
|
|
176
|
+
return {
|
|
177
|
+
"supported": True,
|
|
178
|
+
"running": is_rosetta,
|
|
179
|
+
"native_arch": "arm64" if self.normalized_arch == "x64" and is_rosetta else self.normalized_arch,
|
|
180
|
+
"recommendation": "建议下载 arm64 版本" if is_rosetta else f"使用 {self.normalized_arch} 版本"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
def get_arch_for_format(self, format_type: str) -> str:
|
|
184
|
+
"""
|
|
185
|
+
根据打包格式获取标准化的架构名称 (仅支持 64 位).
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
format_type: 打包格式 (deb, rpm, dmg, exe, zip)
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
str: 对应格式的架构名称
|
|
192
|
+
"""
|
|
193
|
+
# 只支持 64 位架构
|
|
194
|
+
if self.normalized_arch == "x64":
|
|
195
|
+
if format_type in ["deb"]:
|
|
196
|
+
return "amd64" # Debian/Ubuntu 包名
|
|
197
|
+
elif format_type in ["rpm"]:
|
|
198
|
+
return "x86_64" # RPM 包名
|
|
199
|
+
elif format_type in ["dmg", "exe"]:
|
|
200
|
+
return "x86_64" # 通用标准
|
|
201
|
+
else:
|
|
202
|
+
return "x86_64"
|
|
203
|
+
|
|
204
|
+
elif self.normalized_arch == "arm64":
|
|
205
|
+
if format_type in ["deb"]:
|
|
206
|
+
return "arm64" # Debian/Ubuntu 包名
|
|
207
|
+
elif format_type in ["rpm"]:
|
|
208
|
+
return "aarch64" # RPM 包名
|
|
209
|
+
elif format_type in ["dmg", "exe"]:
|
|
210
|
+
return "aarch64" # 通用标准
|
|
211
|
+
else:
|
|
212
|
+
return "arm64"
|
|
213
|
+
|
|
214
|
+
else:
|
|
215
|
+
raise ValueError(f"不支持的架构: {self.normalized_arch}")
|
|
216
|
+
|
|
217
|
+
def get_package_filename_arch(self, format_type: str) -> str:
|
|
218
|
+
"""
|
|
219
|
+
获取用于包文件名的架构标识.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
format_type: 打包格式
|
|
223
|
+
|
|
224
|
+
Returns:
|
|
225
|
+
str: 用于文件名的架构标识
|
|
226
|
+
"""
|
|
227
|
+
return self.get_arch_for_format(format_type)
|
|
228
|
+
|
|
229
|
+
def get_modern_filename(self, app_name: str, version: str, format_type: str) -> str:
|
|
230
|
+
"""
|
|
231
|
+
生成现代化的文件名 (使用内部架构键).
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
app_name: 应用名称
|
|
235
|
+
version: 版本号
|
|
236
|
+
format_type: 文件格式 (zip, tar.gz, dmg, exe)
|
|
237
|
+
|
|
238
|
+
Returns:
|
|
239
|
+
str: 现代化的文件名
|
|
240
|
+
"""
|
|
241
|
+
# 使用内部架构键作为文件名的一部分
|
|
242
|
+
return f"{app_name}-{version}-{self.internal_key}.{format_type}"
|
|
243
|
+
|
|
244
|
+
def get_legacy_format_filename(self, app_name: str, version: str, format_type: str) -> str:
|
|
245
|
+
"""
|
|
246
|
+
生成传统格式的文件名 (兼容现有系统).
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
app_name: 应用名称
|
|
250
|
+
version: 版本号
|
|
251
|
+
format_type: 打包格式 (deb, rpm)
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
str: 传统格式的文件名
|
|
255
|
+
"""
|
|
256
|
+
arch = self.get_arch_for_format(format_type)
|
|
257
|
+
|
|
258
|
+
if format_type == "deb":
|
|
259
|
+
return f"{app_name}_{version}_{arch}.deb"
|
|
260
|
+
elif format_type == "rpm":
|
|
261
|
+
return f"{app_name}-{version}-1.{arch}.rpm"
|
|
262
|
+
|
|
263
|
+
else:
|
|
264
|
+
return f"{app_name}-{version}-{arch}.{format_type}"
|
|
265
|
+
|
|
266
|
+
def is_supported_architecture(self) -> bool:
|
|
267
|
+
"""
|
|
268
|
+
检查当前架构是否受支持 (仅 64 位).
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
bool: 是否支持当前架构
|
|
272
|
+
"""
|
|
273
|
+
try:
|
|
274
|
+
# 如果可以成功规范化架构,则支持
|
|
275
|
+
self._normalize_architecture()
|
|
276
|
+
return True
|
|
277
|
+
except ValueError:
|
|
278
|
+
return False
|
|
279
|
+
|
|
280
|
+
def get_manylinux_tag(self) -> str:
|
|
281
|
+
"""
|
|
282
|
+
获取 Python manylinux 标签 (2024 标准).
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
str: manylinux 标签
|
|
286
|
+
"""
|
|
287
|
+
if self.current_platform != "linux":
|
|
288
|
+
return ""
|
|
289
|
+
|
|
290
|
+
arch = self.get_arch_for_format("deb") # 使用 DEB 格式的架构名
|
|
291
|
+
|
|
292
|
+
if self.c_runtime == "musl":
|
|
293
|
+
# musllinux 标签 (Alpine 等)
|
|
294
|
+
return f"musllinux_1_2_{arch}"
|
|
295
|
+
else:
|
|
296
|
+
# manylinux 标签 (glibc)
|
|
297
|
+
# 2024 标准推荐使用 manylinux_2_28
|
|
298
|
+
return f"manylinux_2_28_{arch}"
|
|
299
|
+
|
|
300
|
+
def get_rust_target_triple(self) -> str:
|
|
301
|
+
"""
|
|
302
|
+
获取 Rust 目标三元组.
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
str: Rust target triple
|
|
306
|
+
"""
|
|
307
|
+
if self.current_platform == "linux":
|
|
308
|
+
if self.normalized_arch == "x64":
|
|
309
|
+
if self.c_runtime == "musl":
|
|
310
|
+
return "x86_64-unknown-linux-musl"
|
|
311
|
+
else:
|
|
312
|
+
return "x86_64-unknown-linux-gnu"
|
|
313
|
+
elif self.normalized_arch == "arm64":
|
|
314
|
+
if self.c_runtime == "musl":
|
|
315
|
+
return "aarch64-unknown-linux-musl"
|
|
316
|
+
else:
|
|
317
|
+
return "aarch64-unknown-linux-gnu"
|
|
318
|
+
|
|
319
|
+
elif self.current_platform == "mac":
|
|
320
|
+
if self.normalized_arch == "x64":
|
|
321
|
+
return "x86_64-apple-darwin"
|
|
322
|
+
elif self.normalized_arch == "arm64":
|
|
323
|
+
return "aarch64-apple-darwin"
|
|
324
|
+
|
|
325
|
+
elif self.current_platform == "win":
|
|
326
|
+
if self.normalized_arch == "x64":
|
|
327
|
+
return "x86_64-pc-windows-msvc"
|
|
328
|
+
elif self.normalized_arch == "arm64":
|
|
329
|
+
return "aarch64-pc-windows-msvc"
|
|
330
|
+
|
|
331
|
+
raise ValueError(f"不支持的平台/架构组合: {self.current_platform}-{self.normalized_arch}")
|
|
332
|
+
|
|
333
|
+
def get_recommended_targets(self) -> Dict[str, str]:
|
|
334
|
+
"""
|
|
335
|
+
获取推荐的打包目标 (2024 标准).
|
|
336
|
+
|
|
337
|
+
Returns:
|
|
338
|
+
Dict: 推荐的打包目标
|
|
339
|
+
"""
|
|
340
|
+
targets = {
|
|
341
|
+
"primary": self.internal_key,
|
|
342
|
+
"rust_triple": self.get_rust_target_triple(),
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if self.current_platform == "linux":
|
|
346
|
+
targets["manylinux"] = self.get_manylinux_tag()
|
|
347
|
+
|
|
348
|
+
return targets
|
|
349
|
+
|
|
350
|
+
def get_platform_info(self) -> Dict[str, Any]:
|
|
351
|
+
"""获取平台信息 (现代化版本).
|
|
352
|
+
|
|
353
|
+
Returns:
|
|
354
|
+
Dict[str, Any]: 平台信息字典
|
|
355
|
+
"""
|
|
356
|
+
info = {
|
|
357
|
+
"platform": self.current_platform,
|
|
358
|
+
"raw_architecture": self.current_arch,
|
|
359
|
+
"normalized_architecture": self.normalized_arch,
|
|
360
|
+
"internal_key": self.internal_key,
|
|
361
|
+
"system": platform.system(),
|
|
362
|
+
"release": platform.release(),
|
|
363
|
+
"version": platform.version(),
|
|
364
|
+
"machine": platform.machine(),
|
|
365
|
+
"processor": platform.processor(),
|
|
366
|
+
"supported": self.is_supported_architecture(),
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
# Linux 特定信息
|
|
370
|
+
if self.current_platform == "linux":
|
|
371
|
+
info.update({
|
|
372
|
+
"c_runtime": self.c_runtime,
|
|
373
|
+
"manylinux_tag": self.get_manylinux_tag(),
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
# macOS 特定信息
|
|
377
|
+
if self.current_platform == "mac":
|
|
378
|
+
rosetta_info = self.get_rosetta_info()
|
|
379
|
+
info.update({
|
|
380
|
+
"rosetta": rosetta_info,
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
# 添加推荐目标
|
|
384
|
+
info["recommended_targets"] = self.get_recommended_targets()
|
|
385
|
+
|
|
386
|
+
return info
|
|
387
|
+
|
|
388
|
+
def check_prerequisites(self) -> Dict[str, bool]:
|
|
389
|
+
"""检查构建前提条件 (现代化版本).
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
Dict[str, bool]: 检查结果字典
|
|
393
|
+
"""
|
|
394
|
+
results = {}
|
|
395
|
+
|
|
396
|
+
# 检查Python版本 (UnifyPy 2.0 要求 Python 3.8+)
|
|
397
|
+
import sys
|
|
398
|
+
python_version = sys.version_info
|
|
399
|
+
results["python_version"] = python_version >= (3, 8)
|
|
400
|
+
|
|
401
|
+
# 检查架构支持
|
|
402
|
+
results["architecture_supported"] = self.is_supported_architecture()
|
|
403
|
+
|
|
404
|
+
# 检查必要库
|
|
405
|
+
libraries = ["pyinstaller", "rich", "requests"]
|
|
406
|
+
for lib in libraries:
|
|
407
|
+
try:
|
|
408
|
+
__import__(lib)
|
|
409
|
+
results[lib] = True
|
|
410
|
+
except ImportError:
|
|
411
|
+
results[lib] = False
|
|
412
|
+
|
|
413
|
+
return results
|
|
414
|
+
|
|
415
|
+
def get_recommended_settings(self) -> Dict[str, Any]:
|
|
416
|
+
"""获取推荐的平台设置 (现代化版本).
|
|
417
|
+
|
|
418
|
+
Returns:
|
|
419
|
+
Dict[str, Any]: 推荐设置
|
|
420
|
+
"""
|
|
421
|
+
settings = {
|
|
422
|
+
"internal_key": self.internal_key,
|
|
423
|
+
"architecture": self.normalized_arch,
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if self.current_platform == "win":
|
|
427
|
+
settings.update({
|
|
428
|
+
"pyinstaller": {
|
|
429
|
+
"windowed": True,
|
|
430
|
+
"icon": "app.ico",
|
|
431
|
+
"target_architecture": self.normalized_arch
|
|
432
|
+
},
|
|
433
|
+
"installer_type": "inno_setup",
|
|
434
|
+
"recommended_formats": ["exe"],
|
|
435
|
+
})
|
|
436
|
+
elif self.current_platform == "mac":
|
|
437
|
+
settings.update({
|
|
438
|
+
"pyinstaller": {
|
|
439
|
+
"windowed": True,
|
|
440
|
+
"osx_bundle_identifier": "com.example.app",
|
|
441
|
+
"target_architecture": self.normalized_arch
|
|
442
|
+
},
|
|
443
|
+
"installer_type": "dmg",
|
|
444
|
+
"recommended_formats": ["dmg"],
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
# Rosetta 特殊建议
|
|
448
|
+
rosetta_info = self.get_rosetta_info()
|
|
449
|
+
if rosetta_info["running"]:
|
|
450
|
+
settings["rosetta_notice"] = "在 Rosetta 下运行,建议构建 arm64 和 universal2 版本"
|
|
451
|
+
|
|
452
|
+
elif self.current_platform == "linux":
|
|
453
|
+
settings.update({
|
|
454
|
+
"pyinstaller": {
|
|
455
|
+
"strip": True,
|
|
456
|
+
"target_architecture": self.normalized_arch
|
|
457
|
+
},
|
|
458
|
+
"installer_type": "deb", # 默认推荐 DEB
|
|
459
|
+
"recommended_formats": ["deb"],
|
|
460
|
+
"c_runtime": self.c_runtime,
|
|
461
|
+
"manylinux_compatible": self.c_runtime == "glibc",
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
return settings
|
|
465
|
+
|
|
466
|
+
def get_build_recommendations(self) -> Dict[str, Any]:
|
|
467
|
+
"""
|
|
468
|
+
获取 2024 年构建和发布建议.
|
|
469
|
+
|
|
470
|
+
Returns:
|
|
471
|
+
Dict: 构建建议
|
|
472
|
+
"""
|
|
473
|
+
recommendations = {
|
|
474
|
+
"primary_targets": [],
|
|
475
|
+
"optional_targets": [],
|
|
476
|
+
"naming_examples": {},
|
|
477
|
+
"compatibility_notes": []
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
# 主要构建目标 (6 档标准)
|
|
481
|
+
if self.current_platform == "win":
|
|
482
|
+
recommendations["primary_targets"] = ["win-x64", "win-arm64"]
|
|
483
|
+
recommendations["naming_examples"] = {
|
|
484
|
+
"modern": f"myapp-1.2.3-{self.internal_key}.zip",
|
|
485
|
+
"traditional": "myapp-1.2.3.exe"
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
elif self.current_platform == "mac":
|
|
489
|
+
recommendations["primary_targets"] = ["mac-arm64", "mac-x64"]
|
|
490
|
+
recommendations["optional_targets"] = ["mac-universal2"]
|
|
491
|
+
recommendations["naming_examples"] = {
|
|
492
|
+
"modern": f"myapp-1.2.3-{self.internal_key}.dmg",
|
|
493
|
+
"universal": "myapp-1.2.3-mac-universal2.dmg"
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
elif self.current_platform == "linux":
|
|
497
|
+
recommendations["primary_targets"] = [f"linux-{self.normalized_arch}-glibc", f"linux-{self.normalized_arch}-musl"]
|
|
498
|
+
|
|
499
|
+
if self.c_runtime == "glibc":
|
|
500
|
+
recommendations["compatibility_notes"].append("优先 manylinux_2_28,老发行版需求时加 manylinux_2_17")
|
|
501
|
+
else:
|
|
502
|
+
recommendations["compatibility_notes"].append("Alpine 用户使用 musllinux 变体")
|
|
503
|
+
|
|
504
|
+
recommendations["naming_examples"] = {
|
|
505
|
+
"modern": f"myapp-1.2.3-{self.internal_key}.tar.gz",
|
|
506
|
+
"deb": f"myapp_1.2.3_{self.get_arch_for_format('deb')}.deb",
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return recommendations
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
事件总线:支持生命周期事件的订阅与触发,按优先级调用处理器。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Callable, DefaultDict, Dict, List, Tuple
|
|
8
|
+
from collections import defaultdict
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Handler = Callable[[Any], None]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class EventBus:
|
|
15
|
+
"""简单的事件总线,支持优先级和异常隔离。"""
|
|
16
|
+
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self._subscribers: DefaultDict[str, List[Tuple[int, Handler]]] = defaultdict(list)
|
|
19
|
+
|
|
20
|
+
def subscribe(self, event: str, handler: Handler, priority: int = 100) -> None:
|
|
21
|
+
self._subscribers[event].append((priority, handler))
|
|
22
|
+
# 按优先级升序排序(数值越小越先执行)
|
|
23
|
+
self._subscribers[event].sort(key=lambda x: x[0])
|
|
24
|
+
|
|
25
|
+
def emit(self, event: str, context: Any) -> None:
|
|
26
|
+
handlers = self._subscribers.get(event, [])
|
|
27
|
+
for _, handler in handlers:
|
|
28
|
+
try:
|
|
29
|
+
handler(context)
|
|
30
|
+
except Exception as e:
|
|
31
|
+
# 将异常记录到上下文,交由引擎统一处理
|
|
32
|
+
if hasattr(context, "errors") and isinstance(context.errors, list):
|
|
33
|
+
context.errors.append((event, e))
|
|
34
|
+
else:
|
|
35
|
+
# 兜底:直接抛出
|
|
36
|
+
raise
|
|
37
|
+
|
unifypy/core/events.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""生命周期事件常量,避免硬编码字符串。"""
|
|
4
|
+
|
|
5
|
+
ON_START = "on_start"
|
|
6
|
+
ON_EXIT = "on_exit"
|
|
7
|
+
ON_ERROR = "on_error"
|
|
8
|
+
|
|
9
|
+
HANDLE_ROLLBACK_COMMANDS = "handle_rollback_commands"
|
|
10
|
+
LOAD_CONFIG = "load_config"
|
|
11
|
+
ENVIRONMENT_CHECK = "environment_check"
|
|
12
|
+
PREPARE = "prepare"
|
|
13
|
+
BUILD_EXECUTABLE = "build_executable"
|
|
14
|
+
GENERATE_INSTALLERS = "generate_installers"
|
|
15
|
+
ON_SUCCESS = "on_success"
|
|
16
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
平台与架构规范化工具。
|
|
5
|
+
|
|
6
|
+
统一对外平台键:windows / macos / linux
|
|
7
|
+
统一对外架构键:x64 / arm64(仅支持 64 位;不支持 32 位/armv7)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import platform as _platform
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 对外平台名常量
|
|
15
|
+
PLATFORM_WINDOWS = "windows"
|
|
16
|
+
PLATFORM_MACOS = "macos"
|
|
17
|
+
PLATFORM_LINUX = "linux"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def normalize_platform(system: Optional[str] = None) -> str:
|
|
21
|
+
"""将系统平台规范化为 windows/macos/linux。
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
system: 原始平台字符串(可选);默认读取 platform.system().lower()
|
|
25
|
+
"""
|
|
26
|
+
s = (system or _platform.system()).lower()
|
|
27
|
+
if s == "darwin":
|
|
28
|
+
return PLATFORM_MACOS
|
|
29
|
+
if s.startswith("win"):
|
|
30
|
+
return PLATFORM_WINDOWS
|
|
31
|
+
if s == "linux":
|
|
32
|
+
return PLATFORM_LINUX
|
|
33
|
+
# 兜底:按 linux 处理
|
|
34
|
+
return PLATFORM_LINUX
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def normalize_arch(machine: Optional[str] = None) -> str:
|
|
38
|
+
"""将 CPU 架构规范化为 x64/arm64(仅 64 位)。
|
|
39
|
+
|
|
40
|
+
映射:
|
|
41
|
+
- x86_64/amd64 → x64
|
|
42
|
+
- aarch64/arm64/armv8* → arm64
|
|
43
|
+
其他(如 armv7/armhf/i386 等 32 位)均视为不支持并抛出异常。
|
|
44
|
+
"""
|
|
45
|
+
m = (machine or _platform.machine()).lower()
|
|
46
|
+
if m in ("x86_64", "amd64"):
|
|
47
|
+
return "x64"
|
|
48
|
+
if m in ("aarch64", "arm64", "armv8", "armv8l"):
|
|
49
|
+
return "arm64"
|
|
50
|
+
# 只支持 64 位架构
|
|
51
|
+
raise ValueError(f"不支持的架构: {m}(仅支持 x64/arm64)")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def is_supported_arch(arch: Optional[str] = None) -> bool:
|
|
55
|
+
"""是否为推荐支持的架构(x64/arm64)。
|
|
56
|
+
"""
|
|
57
|
+
a = arch.lower() if arch else normalize_arch()
|
|
58
|
+
return a in ("x64", "arm64")
|
unifypy/core/plugin.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
插件基类与插件管理:提供统一的注册机制,将处理器绑定到事件总线。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Type
|
|
8
|
+
|
|
9
|
+
from .event_bus import EventBus
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BasePlugin:
|
|
13
|
+
name: str = "base"
|
|
14
|
+
priority: int = 100
|
|
15
|
+
|
|
16
|
+
def __init__(self, context):
|
|
17
|
+
self.context = context
|
|
18
|
+
|
|
19
|
+
def register(self, bus: EventBus):
|
|
20
|
+
"""子类实现:在此方法中将自身的各事件处理器订阅到总线。"""
|
|
21
|
+
raise NotImplementedError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PluginManager:
|
|
25
|
+
"""插件管理器:加载并注册内置插件(以及后续可扩展的外部插件)。"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, context):
|
|
28
|
+
self.context = context
|
|
29
|
+
|
|
30
|
+
def load_builtin_plugins(self) -> List[BasePlugin]:
|
|
31
|
+
# 延迟导入避免循环依赖
|
|
32
|
+
from unifypy.plugins.progress_plugin import ProgressPlugin
|
|
33
|
+
from unifypy.plugins.dry_run_plugin import DryRunPlugin
|
|
34
|
+
from unifypy.plugins.config_plugin import ConfigPlugin
|
|
35
|
+
from unifypy.plugins.external_plugins_loader import ExternalPluginsLoaderPlugin
|
|
36
|
+
from unifypy.plugins.environment_plugin import EnvironmentPlugin
|
|
37
|
+
from unifypy.plugins.windows_language_plugin import WindowsLanguagePlugin
|
|
38
|
+
from unifypy.plugins.prepare_plugin import PreparePlugin
|
|
39
|
+
from unifypy.plugins.pyinstaller_plugin import PyInstallerPlugin
|
|
40
|
+
from unifypy.plugins.packaging_plugin import PackagingPlugin
|
|
41
|
+
from unifypy.plugins.summary_plugin import SummaryPlugin
|
|
42
|
+
from unifypy.plugins.cleanup_plugin import CleanupPlugin
|
|
43
|
+
from unifypy.plugins.rollback_plugin import RollbackPlugin
|
|
44
|
+
from unifypy.plugins.auto_rollback_plugin import AutoRollbackPlugin
|
|
45
|
+
|
|
46
|
+
plugins: List[BasePlugin] = [
|
|
47
|
+
ProgressPlugin(self.context),
|
|
48
|
+
DryRunPlugin(self.context),
|
|
49
|
+
RollbackPlugin(self.context),
|
|
50
|
+
ExternalPluginsLoaderPlugin(self.context),
|
|
51
|
+
ConfigPlugin(self.context),
|
|
52
|
+
EnvironmentPlugin(self.context),
|
|
53
|
+
WindowsLanguagePlugin(self.context),
|
|
54
|
+
AutoRollbackPlugin(self.context),
|
|
55
|
+
PreparePlugin(self.context),
|
|
56
|
+
PyInstallerPlugin(self.context),
|
|
57
|
+
PackagingPlugin(self.context),
|
|
58
|
+
SummaryPlugin(self.context),
|
|
59
|
+
CleanupPlugin(self.context),
|
|
60
|
+
]
|
|
61
|
+
return plugins
|
|
62
|
+
|
|
63
|
+
def register_plugins(self, bus: EventBus, plugins: List[BasePlugin]):
|
|
64
|
+
for p in plugins:
|
|
65
|
+
p.register(bus)
|