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.
Files changed (78) hide show
  1. unifypy/__init__.py +7 -0
  2. unifypy/__main__.py +21 -0
  3. unifypy/cli/__init__.py +10 -0
  4. unifypy/cli/argument_parser.py +209 -0
  5. unifypy/core/__init__.py +8 -0
  6. unifypy/core/config.py +491 -0
  7. unifypy/core/context.py +36 -0
  8. unifypy/core/engine.py +93 -0
  9. unifypy/core/environment.py +509 -0
  10. unifypy/core/event_bus.py +37 -0
  11. unifypy/core/events.py +16 -0
  12. unifypy/core/platforms.py +58 -0
  13. unifypy/core/plugin.py +65 -0
  14. unifypy/core/validators/__init__.py +10 -0
  15. unifypy/core/validators/tool_validator.py +144 -0
  16. unifypy/platforms/__init__.py +10 -0
  17. unifypy/platforms/base.py +127 -0
  18. unifypy/platforms/linux/__init__.py +10 -0
  19. unifypy/platforms/linux/deb_packager.py +289 -0
  20. unifypy/platforms/linux/rpm_packager.py +332 -0
  21. unifypy/platforms/macos/__init__.py +10 -0
  22. unifypy/platforms/macos/dmg_packager.py +477 -0
  23. unifypy/platforms/macos/post_processor.py +272 -0
  24. unifypy/platforms/registry.py +108 -0
  25. unifypy/platforms/windows/__init__.py +9 -0
  26. unifypy/platforms/windows/inno_setup.py +715 -0
  27. unifypy/plugins/__init__.py +3 -0
  28. unifypy/plugins/auto_rollback_plugin.py +156 -0
  29. unifypy/plugins/cleanup_plugin.py +22 -0
  30. unifypy/plugins/config_plugin.py +42 -0
  31. unifypy/plugins/dry_run_plugin.py +22 -0
  32. unifypy/plugins/environment_plugin.py +61 -0
  33. unifypy/plugins/external_plugins_loader.py +42 -0
  34. unifypy/plugins/packaging_plugin.py +125 -0
  35. unifypy/plugins/prepare_plugin.py +89 -0
  36. unifypy/plugins/progress_plugin.py +32 -0
  37. unifypy/plugins/pyinstaller_plugin.py +95 -0
  38. unifypy/plugins/rollback_plugin.py +62 -0
  39. unifypy/plugins/summary_plugin.py +36 -0
  40. unifypy/plugins/windows_language_plugin.py +85 -0
  41. unifypy/pyinstaller/__init__.py +7 -0
  42. unifypy/pyinstaller/config_builder.py +908 -0
  43. unifypy/templates/ChineseSimplified.isl.template +403 -0
  44. unifypy/templates/setup.iss.template +51 -0
  45. unifypy/tools/create-dmg/.this-is-the-create-dmg-repo +3 -0
  46. unifypy/tools/create-dmg/LICENSE +22 -0
  47. unifypy/tools/create-dmg/Makefile +33 -0
  48. unifypy/tools/create-dmg/README.md +126 -0
  49. unifypy/tools/create-dmg/builder/create-dmg.builder +26 -0
  50. unifypy/tools/create-dmg/create-dmg +621 -0
  51. unifypy/tools/create-dmg/doc-project/Developer Notes.md +35 -0
  52. unifypy/tools/create-dmg/doc-project/Release Checklist.md +10 -0
  53. unifypy/tools/create-dmg/examples/01-main-example/installer_background.png +0 -0
  54. unifypy/tools/create-dmg/examples/01-main-example/sample +30 -0
  55. unifypy/tools/create-dmg/examples/01-main-example/source_folder/Application.app +0 -0
  56. unifypy/tools/create-dmg/support/eula-resources-template.xml +105 -0
  57. unifypy/tools/create-dmg/support/template.applescript +74 -0
  58. unifypy/tools/create-dmg/tests/007-space-in-dir-name/my files/hello.txt +1 -0
  59. unifypy/tools/create-dmg/tests/007-space-in-dir-name/run-test +5 -0
  60. unifypy/utils/__init__.py +10 -0
  61. unifypy/utils/cache_manager.py +957 -0
  62. unifypy/utils/command_runner.py +195 -0
  63. unifypy/utils/entitlements_generator.py +450 -0
  64. unifypy/utils/file_ops.py +333 -0
  65. unifypy/utils/icon_converter.py +144 -0
  66. unifypy/utils/info_plist_updater.py +247 -0
  67. unifypy/utils/macos_codesign.py +225 -0
  68. unifypy/utils/parallel_builder.py +355 -0
  69. unifypy/utils/progress.py +371 -0
  70. unifypy/utils/progress_callback_factory.py +56 -0
  71. unifypy/utils/rollback.py +484 -0
  72. unifypy/utils/tool_manager.py +701 -0
  73. unifypy-2.0.2.dist-info/METADATA +609 -0
  74. unifypy-2.0.2.dist-info/RECORD +78 -0
  75. unifypy-2.0.2.dist-info/WHEEL +5 -0
  76. unifypy-2.0.2.dist-info/entry_points.txt +2 -0
  77. unifypy-2.0.2.dist-info/licenses/LICENSE +21 -0
  78. unifypy-2.0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,272 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ macOS 后处理器
5
+ 负责 macOS 平台特定的构建后处理操作
6
+ """
7
+
8
+ from unifypy.core.platforms import normalize_platform
9
+ from pathlib import Path
10
+ from typing import Optional
11
+
12
+
13
+ class MacOSPostProcessor:
14
+ """
15
+ macOS 平台后处理器.
16
+ 处理 Info.plist 更新、代码签名等 macOS 特定操作.
17
+ """
18
+
19
+ def __init__(
20
+ self,
21
+ info_plist_updater,
22
+ macos_codesigner,
23
+ pyinstaller_builder,
24
+ verbose: bool = False
25
+ ):
26
+ """
27
+ 初始化 macOS 后处理器.
28
+
29
+ Args:
30
+ info_plist_updater: Info.plist 更新器实例
31
+ macos_codesigner: macOS 代码签名器实例
32
+ pyinstaller_builder: PyInstaller 配置构建器实例
33
+ verbose: 是否显示详细信息
34
+ """
35
+ self.info_plist_updater = info_plist_updater
36
+ self.macos_codesigner = macos_codesigner
37
+ self.pyinstaller_builder = pyinstaller_builder
38
+ self.verbose = verbose
39
+
40
+ def is_macos(self) -> bool:
41
+ """
42
+ 检查当前是否为 macOS 平台.
43
+
44
+ Returns:
45
+ bool: 是否为 macOS
46
+ """
47
+ return normalize_platform() == "macos"
48
+
49
+ def prepare_entitlements_config(
50
+ self,
51
+ config,
52
+ project_dir: Path,
53
+ args
54
+ ) -> dict:
55
+ """
56
+ 准备 macOS entitlements 配置(构建前处理).
57
+
58
+ Args:
59
+ config: ConfigManager 实例
60
+ project_dir: 项目目录
61
+ args: 命令行参数
62
+
63
+ Returns:
64
+ dict: 更新后的配置字典(如果有变化)
65
+ """
66
+ if not self.is_macos():
67
+ return {}
68
+
69
+ # 判断是否为开发版本(默认开启,适用于未签名应用)
70
+ # 只有明确指定 --production 时才禁用开发模式
71
+ production = getattr(args, "production", False)
72
+ development = (
73
+ not production
74
+ or getattr(args, "development", False)
75
+ or getattr(args, "debug", False)
76
+ )
77
+
78
+ # 更新配置以包含自动生成的 entitlements
79
+ # 注意:传递原始配置以保持 platforms 结构
80
+ updated_config = (
81
+ self.pyinstaller_builder.update_config_with_auto_entitlements(
82
+ config.raw_config, project_dir, development
83
+ )
84
+ )
85
+
86
+ return updated_config
87
+
88
+ def process_built_app(
89
+ self,
90
+ app_name: str,
91
+ dist_dir: Path,
92
+ config,
93
+ project_dir: Path
94
+ ) -> bool:
95
+ """
96
+ 处理构建完成的 .app 包(构建后处理).
97
+
98
+ Args:
99
+ app_name: 应用名称
100
+ dist_dir: 输出目录
101
+ config: ConfigManager 实例
102
+ project_dir: 项目目录
103
+
104
+ Returns:
105
+ bool: 是否处理成功
106
+ """
107
+ if not self.is_macos():
108
+ return True # 非 macOS 平台,无需处理
109
+
110
+ # 查找 .app 包
111
+ app_path = dist_dir / f"{app_name}.app"
112
+
113
+ if not app_path.exists():
114
+ print(f"⚠️ 未找到 .app 包: {app_path}")
115
+ return False
116
+
117
+ # 更新 Info.plist
118
+ if not self._update_info_plist(app_path, config):
119
+ return False
120
+
121
+ # 执行代码签名
122
+ self._sign_app(app_path, project_dir)
123
+
124
+ return True
125
+
126
+ def _update_info_plist(self, app_path: Path, config) -> bool:
127
+ """
128
+ 更新 macOS .app 包中的 Info.plist 权限描述.
129
+
130
+ Args:
131
+ app_path: .app 包路径
132
+ config: ConfigManager 实例
133
+
134
+ Returns:
135
+ bool: 是否更新成功
136
+ """
137
+ try:
138
+ # 获取 macOS 配置
139
+ macos_config = config._get_platform_config().get("macos", {})
140
+ if not macos_config:
141
+ # 从原始配置获取
142
+ raw_config = getattr(config, "raw_config", {})
143
+ if "platforms" in raw_config:
144
+ macos_config = raw_config["platforms"].get("macos", {})
145
+
146
+ if not macos_config:
147
+ if self.verbose:
148
+ print("⚠️ 未找到 macOS 平台配置")
149
+ return True # 没有配置不算失败
150
+
151
+ if self.verbose:
152
+ print("🔧 更新 macOS 权限描述...")
153
+
154
+ success = self.info_plist_updater.update_app_info_plist(
155
+ app_path, macos_config
156
+ )
157
+
158
+ if success:
159
+ if self.verbose:
160
+ print("✅ Info.plist 权限描述更新完成")
161
+
162
+ # 显示已添加的权限
163
+ permissions = self.info_plist_updater.list_app_permissions(
164
+ app_path
165
+ )
166
+ if permissions:
167
+ print("📋 已配置的权限描述:")
168
+ for key, desc in permissions.items():
169
+ print(f" • {key}: {desc[:60]}...")
170
+ else:
171
+ print("⚠️ Info.plist 权限描述更新失败") # 错误信息始终显示
172
+
173
+ return success
174
+
175
+ except Exception as e:
176
+ print(f"❌ Info.plist 更新异常: {e}")
177
+ return False
178
+
179
+ def _sign_app(self, app_path: Path, project_dir: Path):
180
+ """
181
+ 对 macOS .app 包执行 ad-hoc 代码签名以应用 entitlements.
182
+
183
+ Args:
184
+ app_path: .app 包路径
185
+ project_dir: 项目目录
186
+ """
187
+ try:
188
+ if self.verbose:
189
+ print(f"🔐 准备对 {app_path.name} 执行代码签名...")
190
+
191
+ # 检查 codesign 工具是否可用
192
+ if not self.macos_codesigner.check_codesign_available():
193
+ print("⚠️ codesign 工具不可用,跳过代码签名") # 错误信息始终显示
194
+ return
195
+
196
+ # 查找 entitlements.plist 文件
197
+ entitlements_path = self._find_entitlements_file(
198
+ app_path, project_dir
199
+ )
200
+
201
+ # 执行签名
202
+ success = self.macos_codesigner.sign_app_with_entitlements(
203
+ app_path, entitlements_path
204
+ )
205
+
206
+ if success:
207
+ if self.verbose:
208
+ print("✅ macOS 代码签名完成,权限应该已生效")
209
+ else:
210
+ print("⚠️ 代码签名失败,但应用仍可正常使用") # 警告信息始终显示
211
+
212
+ except Exception as e:
213
+ print(f"❌ macOS 代码签名异常: {e}")
214
+
215
+ def _find_entitlements_file(
216
+ self,
217
+ app_path: Path,
218
+ project_dir: Path
219
+ ) -> Optional[Path]:
220
+ """
221
+ 查找 entitlements.plist 文件.
222
+
223
+ Args:
224
+ app_path: .app 包路径
225
+ project_dir: 项目目录
226
+
227
+ Returns:
228
+ Optional[Path]: entitlements 文件路径,如果未找到则返回 None
229
+ """
230
+ # 首先检查项目根目录
231
+ project_entitlements = project_dir / "entitlements.plist"
232
+ if project_entitlements.exists():
233
+ if self.verbose:
234
+ print(f"📜 找到 entitlements 文件: {project_entitlements}")
235
+ return project_entitlements
236
+
237
+ # 如果没找到,检查 .app 包内的 entitlements
238
+ app_entitlements = app_path / "Contents" / "entitlements.plist"
239
+ if app_entitlements.exists():
240
+ if self.verbose:
241
+ print(f"📜 使用 .app 包内的 entitlements: {app_entitlements}")
242
+ return app_entitlements
243
+
244
+ return None
245
+
246
+ def print_debug_info(self, command: list):
247
+ """
248
+ 打印 PyInstaller 命令的调试信息(仅在 verbose 模式).
249
+
250
+ Args:
251
+ command: PyInstaller 命令列表
252
+ """
253
+ if not self.verbose or not self.is_macos():
254
+ return
255
+
256
+ print("\n🔍 PyInstaller 命令调试:")
257
+ print(f"完整命令: {' '.join(command)}")
258
+
259
+ # 检查关键参数
260
+ if "--osx-bundle-identifier" in command:
261
+ idx = command.index("--osx-bundle-identifier")
262
+ if idx + 1 < len(command):
263
+ print(f" Bundle ID: {command[idx + 1]}")
264
+
265
+ if "--osx-entitlements-file" in command:
266
+ idx = command.index("--osx-entitlements-file")
267
+ if idx + 1 < len(command):
268
+ entitlements_path = command[idx + 1]
269
+ print(f" Entitlements: {entitlements_path}")
270
+ print(f" 文件存在: {Path(entitlements_path).exists()}")
271
+
272
+ print()
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ 打包器注册表 支持动态添加新的打包格式.
5
+ """
6
+
7
+ from typing import Dict, List, Optional, Type
8
+
9
+ from .base import BasePackager
10
+
11
+
12
+ class PackagerRegistry:
13
+ """
14
+ 打包器注册表.
15
+ """
16
+
17
+ def __init__(self):
18
+ """
19
+ 初始化注册表.
20
+ """
21
+ self._packagers: Dict[str, Dict[str, Type[BasePackager]]] = {}
22
+ self._load_default_packagers()
23
+
24
+ def _load_default_packagers(self):
25
+ """
26
+ 加载默认打包器.
27
+ """
28
+ try:
29
+ # Windows 打包器
30
+ from .windows.inno_setup import InnoSetupPackager
31
+
32
+ self.register_packager("windows", "exe", InnoSetupPackager)
33
+
34
+ # macOS 打包器
35
+ from .macos.dmg_packager import DMGPackager
36
+
37
+ self.register_packager("macos", "dmg", DMGPackager)
38
+
39
+ # Linux 打包器
40
+ from .linux.deb_packager import DEBPackager
41
+ from .linux.rpm_packager import RPMPackager
42
+
43
+ self.register_packager("linux", "deb", DEBPackager)
44
+ self.register_packager("linux", "rpm", RPMPackager)
45
+
46
+ except ImportError:
47
+ # 如果某些平台的打包器模块不存在,忽略错误
48
+ pass
49
+
50
+ def register_packager(
51
+ self, platform: str, format_type: str, packager_class: Type[BasePackager]
52
+ ):
53
+ """注册新的打包器.
54
+
55
+ Args:
56
+ platform: 平台名称 (windows/macos/linux)
57
+ format_type: 格式类型 (exe/dmg/deb等)
58
+ packager_class: 打包器类
59
+ """
60
+ if platform not in self._packagers:
61
+ self._packagers[platform] = {}
62
+
63
+ self._packagers[platform][format_type] = packager_class
64
+
65
+ def get_packager(
66
+ self, platform: str, format_type: str
67
+ ) -> Optional[Type[BasePackager]]:
68
+ """获取指定格式的打包器类.
69
+
70
+ Args:
71
+ platform: 平台名称
72
+ format_type: 格式类型
73
+
74
+ Returns:
75
+ Optional[Type[BasePackager]]: 打包器类,如果不存在则返回None
76
+ """
77
+ return self._packagers.get(platform, {}).get(format_type)
78
+
79
+ def get_supported_formats(self, platform: str) -> List[str]:
80
+ """获取平台支持的所有格式.
81
+
82
+ Args:
83
+ platform: 平台名称
84
+
85
+ Returns:
86
+ List[str]: 支持的格式列表
87
+ """
88
+ return list(self._packagers.get(platform, {}).keys())
89
+
90
+ def get_all_platforms(self) -> List[str]:
91
+ """获取所有支持的平台.
92
+
93
+ Returns:
94
+ List[str]: 平台列表
95
+ """
96
+ return list(self._packagers.keys())
97
+
98
+ def is_format_supported(self, platform: str, format_type: str) -> bool:
99
+ """检查格式是否支持.
100
+
101
+ Args:
102
+ platform: 平台名称
103
+ format_type: 格式类型
104
+
105
+ Returns:
106
+ bool: 是否支持
107
+ """
108
+ return format_type in self._packagers.get(platform, {})
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Windows平台打包器.
5
+ """
6
+
7
+ from .inno_setup import InnoSetupPackager
8
+
9
+ __all__ = ["InnoSetupPackager"]