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,371 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ 进度条管理系统 提供统一的进度显示和状态管理.
5
+ """
6
+
7
+ import time
8
+ from typing import Any, Dict
9
+
10
+ from rich.console import Console
11
+ from rich.panel import Panel
12
+ from rich.progress import (
13
+ BarColumn,
14
+ MofNCompleteColumn,
15
+ Progress,
16
+ ProgressColumn,
17
+ SpinnerColumn,
18
+ TaskID,
19
+ TextColumn,
20
+ )
21
+ from rich.table import Table
22
+ from rich.text import Text
23
+
24
+
25
+ class CustomTimeColumn(ProgressColumn):
26
+ """
27
+ 自定义时间列,显示阶段用时.
28
+ """
29
+
30
+ def __init__(self, progress_manager):
31
+ super().__init__()
32
+ self.progress_manager = progress_manager
33
+
34
+ def render(self, task):
35
+ """
36
+ 渲染时间显示.
37
+ """
38
+ # 查找对应的阶段名称
39
+ stage_name = None
40
+ for name, task_id in self.progress_manager.tasks.items():
41
+ if task_id == task.id:
42
+ stage_name = name
43
+ break
44
+
45
+ if stage_name and stage_name in self.progress_manager.stage_start_times:
46
+ # 如果任务已完成(包括进度超过100%的情况),显示最终用时
47
+ if task.completed >= task.total or task.percentage >= 100:
48
+ if stage_name in self.progress_manager.stage_durations:
49
+ duration = self.progress_manager.stage_durations[stage_name]
50
+ return Text(
51
+ self.progress_manager._format_duration(duration), style="green"
52
+ )
53
+ else:
54
+ # 如果还没有记录最终用时,计算当前用时
55
+ current_time = time.time()
56
+ elapsed = (
57
+ current_time
58
+ - self.progress_manager.stage_start_times[stage_name]
59
+ )
60
+ return Text(
61
+ self.progress_manager._format_duration(elapsed), style="green"
62
+ )
63
+ else:
64
+ # 如果任务进行中,显示实时用时
65
+ current_time = time.time()
66
+ elapsed = (
67
+ current_time - self.progress_manager.stage_start_times[stage_name]
68
+ )
69
+ return Text(
70
+ self.progress_manager._format_duration(elapsed), style="yellow"
71
+ )
72
+
73
+ return Text("0:00:00", style="dim")
74
+
75
+
76
+ class ProgressManager:
77
+ """
78
+ 统一的进度管理器.
79
+ """
80
+
81
+ def __init__(self, verbose: bool = False):
82
+ """初始化进度管理器.
83
+
84
+ Args:
85
+ verbose: 是否显示详细输出
86
+ """
87
+ self.console = Console()
88
+ self.verbose = verbose
89
+ self.current_stage = ""
90
+
91
+ # 创建进度条组件
92
+ self.custom_time_column = CustomTimeColumn(self)
93
+ self.progress = Progress(
94
+ SpinnerColumn(),
95
+ TextColumn("[progress.description]{task.description}"),
96
+ BarColumn(complete_style="green", finished_style="green"),
97
+ TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
98
+ MofNCompleteColumn(),
99
+ self.custom_time_column,
100
+ console=self.console,
101
+ expand=True,
102
+ refresh_per_second=10, # 每秒刷新10次,确保时间显示实时更新
103
+ )
104
+
105
+ self.tasks: Dict[str, TaskID] = {}
106
+ self.stage_start_times: Dict[str, float] = {}
107
+ self.stage_durations: Dict[str, float] = {}
108
+ self.stage_weights = {
109
+ "环境检查": 10,
110
+ "PyInstaller打包": 40,
111
+ "安装包生成": 40,
112
+ "验证和清理": 10,
113
+ }
114
+
115
+ def start(self):
116
+ """
117
+ 启动进度显示.
118
+ """
119
+ if not self.verbose:
120
+ self.progress.start()
121
+ self._show_header()
122
+
123
+ def stop(self):
124
+ """
125
+ 停止进度显示.
126
+ """
127
+ if not self.verbose:
128
+ self.progress.stop()
129
+
130
+ def _show_header(self):
131
+ """
132
+ 显示程序头部信息.
133
+ """
134
+ header = Panel(
135
+ Text("🚀 UnifyPy 2.0 - 跨平台Python应用打包工具", style="bold blue"),
136
+ subtitle="正在打包您的应用程序...",
137
+ border_style="blue",
138
+ )
139
+ self.console.print(header)
140
+ self.console.print()
141
+
142
+ def start_stage(
143
+ self, stage_name: str, description: str = "", total: int = 100
144
+ ) -> TaskID:
145
+ """开始新的阶段.
146
+
147
+ Args:
148
+ stage_name: 阶段名称
149
+ description: 阶段描述
150
+ total: 总进度值
151
+
152
+ Returns:
153
+ TaskID: 任务ID
154
+ """
155
+ self.current_stage = stage_name
156
+ self.stage_start_times[stage_name] = time.time()
157
+
158
+ if self.verbose:
159
+ self.console.print(f"\n🔄 开始阶段: {stage_name}")
160
+ if description:
161
+ self.console.print(f" {description}")
162
+ return None
163
+
164
+ display_name = f"{stage_name}: {description}" if description else stage_name
165
+ task_id = self.progress.add_task(display_name, total=total)
166
+ self.tasks[stage_name] = task_id
167
+
168
+ return task_id
169
+
170
+ def update_stage(
171
+ self,
172
+ stage_name: str,
173
+ advance: int = 1,
174
+ description: str = None,
175
+ absolute: bool = False,
176
+ ):
177
+ """更新阶段进度.
178
+
179
+ Args:
180
+ stage_name: 阶段名称
181
+ advance: 进度增量或绝对进度值
182
+ description: 更新描述
183
+ absolute: 如果为True,advance表示绝对进度值;如果为False,表示增量
184
+ """
185
+ if self.verbose and description:
186
+ self.console.print(f" • {description}")
187
+ return
188
+
189
+ if stage_name in self.tasks:
190
+ task_id = self.tasks[stage_name]
191
+ if absolute:
192
+ # 绝对进度设置
193
+ if description:
194
+ self.progress.update(
195
+ task_id,
196
+ completed=advance,
197
+ description=f"{stage_name}: {description}",
198
+ )
199
+ else:
200
+ self.progress.update(task_id, completed=advance)
201
+ else:
202
+ # 增量进度更新
203
+ if description:
204
+ self.progress.update(
205
+ task_id,
206
+ advance=advance,
207
+ description=f"{stage_name}: {description}",
208
+ )
209
+ else:
210
+ self.progress.update(task_id, advance=advance)
211
+
212
+ def complete_stage(self, stage_name: str):
213
+ """完成阶段.
214
+
215
+ Args:
216
+ stage_name: 阶段名称
217
+ """
218
+ # 计算阶段耗时
219
+ if stage_name in self.stage_start_times:
220
+ duration = time.time() - self.stage_start_times[stage_name]
221
+ self.stage_durations[stage_name] = duration
222
+ duration_str = self._format_duration(duration)
223
+
224
+ if self.verbose:
225
+ self.console.print(f"✅ 完成阶段: {stage_name} (用时: {duration_str})")
226
+ return
227
+
228
+ # 标记任务完成,时间显示由自定义时间列处理
229
+ if stage_name in self.tasks:
230
+ task_id = self.tasks[stage_name]
231
+ self.progress.update(task_id, completed=100)
232
+ else:
233
+ if self.verbose:
234
+ self.console.print(f"✅ 完成阶段: {stage_name}")
235
+ return
236
+
237
+ if stage_name in self.tasks:
238
+ task_id = self.tasks[stage_name]
239
+ self.progress.update(task_id, completed=100)
240
+
241
+ def on_error(self, error: Exception, stage: str, details: str = ""):
242
+ """错误处理.
243
+
244
+ Args:
245
+ error: 异常对象
246
+ stage: 发生错误的阶段
247
+ details: 错误详情
248
+ """
249
+ if not self.verbose:
250
+ self.progress.stop()
251
+
252
+ # 显示错误信息
253
+ error_panel = Panel(
254
+ f"[red]❌ 错误发生在 {stage}[/red]\n\n"
255
+ f"[yellow]错误信息:[/yellow] {str(error)}\n"
256
+ f"{details if details else ''}",
257
+ title="[red]打包失败[/red]",
258
+ border_style="red",
259
+ )
260
+ self.console.print(error_panel)
261
+
262
+ # 提供解决建议
263
+ self._show_error_suggestions(error, stage)
264
+
265
+ def _show_error_suggestions(self, error: Exception, stage: str):
266
+ """
267
+ 显示错误解决建议.
268
+ """
269
+ suggestions = []
270
+ error_str = str(error).lower()
271
+
272
+ if "permission" in error_str or "access" in error_str:
273
+ suggestions.append("• 尝试以管理员权限运行")
274
+ suggestions.append("• 检查文件/目录权限设置")
275
+
276
+ if "not found" in error_str or "command not found" in error_str:
277
+ suggestions.append("• 检查相关工具是否已安装")
278
+ suggestions.append("• 确认PATH环境变量设置正确")
279
+
280
+ if "pyinstaller" in error_str:
281
+ suggestions.append(
282
+ "• 尝试升级PyInstaller: pip install --upgrade pyinstaller"
283
+ )
284
+ suggestions.append("• 检查Python依赖是否完整")
285
+
286
+ if stage == "环境检查":
287
+ suggestions.append("• 确认配置文件格式正确")
288
+ suggestions.append("• 检查项目目录结构")
289
+
290
+ if suggestions:
291
+ suggestion_text = "\n".join(suggestions)
292
+ suggestion_panel = Panel(
293
+ suggestion_text,
294
+ title="[yellow]💡 解决建议[/yellow]",
295
+ border_style="yellow",
296
+ )
297
+ self.console.print(suggestion_panel)
298
+
299
+ def show_success(self, output_info: Dict[str, Any]):
300
+ """显示成功信息.
301
+
302
+ Args:
303
+ output_info: 输出信息字典
304
+ """
305
+ if not self.verbose:
306
+ self.progress.stop()
307
+
308
+ # 创建结果表格
309
+ table = Table(
310
+ title="🎉 打包成功完成!", show_header=True, header_style="bold green"
311
+ )
312
+ table.add_column("类型", style="cyan")
313
+ table.add_column("文件路径", style="green")
314
+ table.add_column("大小", style="yellow")
315
+
316
+ for item_type, file_path in output_info.items():
317
+ if isinstance(file_path, str) and file_path:
318
+ try:
319
+ import os
320
+
321
+ size = self._format_size(os.path.getsize(file_path))
322
+ table.add_row(item_type, file_path, size)
323
+ except:
324
+ table.add_row(item_type, file_path, "未知")
325
+
326
+ self.console.print(table)
327
+ self.console.print(
328
+ "\n[green]✨ 打包完成!您可以分发这些文件给用户使用。[/green]"
329
+ )
330
+
331
+ def _format_size(self, size: int) -> str:
332
+ """
333
+ 格式化文件大小.
334
+ """
335
+ for unit in ["B", "KB", "MB", "GB"]:
336
+ if size < 1024.0:
337
+ return f"{size:.1f} {unit}"
338
+ size /= 1024.0
339
+ return f"{size:.1f} TB"
340
+
341
+ def _format_duration(self, duration: float) -> str:
342
+ """
343
+ 格式化持续时间.
344
+ """
345
+ if duration < 1:
346
+ return f"{duration*1000:.0f}ms"
347
+ elif duration < 60:
348
+ return f"{duration:.1f}s"
349
+ else:
350
+ minutes = int(duration // 60)
351
+ seconds = duration % 60
352
+ return f"{minutes}m{seconds:.1f}s"
353
+
354
+ def info(self, message: str):
355
+ """
356
+ 显示信息.
357
+ """
358
+ if self.verbose:
359
+ self.console.print(f"ℹ️ {message}")
360
+
361
+ def warning(self, message: str):
362
+ """
363
+ 显示警告.
364
+ """
365
+ self.console.print(f"[yellow]⚠️ {message}[/yellow]")
366
+
367
+ def success(self, message: str):
368
+ """
369
+ 显示成功信息.
370
+ """
371
+ self.console.print(f"[green]✅ {message}[/green]")
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ 进度回调工厂
5
+ 统一创建和管理进度回调函数
6
+ """
7
+
8
+ from typing import Callable
9
+
10
+
11
+ class ProgressCallbackFactory:
12
+ """
13
+ 进度回调函数工厂类.
14
+ 用于创建统一的进度回调函数,避免重复代码.
15
+ """
16
+
17
+ @staticmethod
18
+ def create_callback(
19
+ progress_manager,
20
+ verbose: bool = False
21
+ ) -> Callable[[str, str], None]:
22
+ """
23
+ 创建进度回调函数.
24
+
25
+ Args:
26
+ progress_manager: 进度管理器实例
27
+ verbose: 是否启用详细模式
28
+
29
+ Returns:
30
+ Callable: 进度回调函数 callback(message, level='info')
31
+ """
32
+ def progress_callback(message: str, level: str = 'info'):
33
+ """
34
+ 处理进度消息的回调函数.
35
+
36
+ Args:
37
+ message: 消息内容
38
+ level: 消息级别 ('info', 'success', 'warning', 'error')
39
+ """
40
+ # 非 verbose 模式下不显示详细消息
41
+ if not verbose:
42
+ return
43
+
44
+ # 根据级别添加emoji前缀并调用对应的方法
45
+ if level == 'success':
46
+ progress_manager.info(f"✅ {message}")
47
+ elif level == 'warning':
48
+ progress_manager.warning(f"⚠️ {message}")
49
+ elif level == 'error':
50
+ progress_manager.warning(f"❌ {message}")
51
+ else: # info
52
+ progress_manager.info(f"📋 {message}")
53
+
54
+ return progress_callback
55
+
56
+ # 注意:create_summary_callback 未被使用,已移除以简化接口