Skip to content

Commit 34541ce

Browse files
committed
添加对插件的支持,更新配置文件以启用UPX插件和自定义命令
1 parent 92f2afe commit 34541ce

2 files changed

Lines changed: 53 additions & 14 deletions

File tree

package/nuitka_build.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def main():
5656
dist_path = base_dir / task['distpath']
5757
requirements = task.get('install-requirements', [])
5858
use_upx = task.get('upx', False)
59+
enable_plugins = task.get('enable-plugins', [])
60+
5961
# onefile = task.get('onefile', 0)
6062
icon = task.get('icon')
6163
windows_disable_console = task.get('windows-disable-console', False)
@@ -66,7 +68,7 @@ def main():
6668
if arrch == "AMD64":
6769
arrch = "x64"
6870
output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine)
69-
71+
custom_command = task.get('custom-command')
7072
# 检查操作系统和架构
7173
# if Machine not in task.get('os', []):
7274
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前操作系统 {Machine}")
@@ -113,20 +115,42 @@ def main():
113115
print(f"警告: 图标文件不存在 {icon_path}")
114116

115117

116-
if arrch == "ARM64":
117-
print("UPX不支持当前架构")
118-
else:
119-
if use_upx:
118+
# if arrch == "ARM64":
119+
# print("UPX不支持当前架构")
120+
# else:
121+
# if use_upx:
122+
# if upx_dir.exists():
123+
# cmd.append('--plugin-enable=upx')
124+
# cmd.append(f'--upx-binary={str(upx_dir)}')
125+
# print(f"使用UPX压缩: {upx_dir}")
126+
# else:
127+
# print(f"警告: UPX目录不存在 {upx_dir}")
128+
# else:
129+
# print("不使用UPX压缩")
130+
131+
if enable_plugins:
132+
plugin_list = ''
133+
if len(enable_plugins) == 1:
134+
plugin_list = enable_plugins[0]
135+
else:
136+
plugin_list = ','.join(enable_plugins)
137+
cmd.append(f'--plugin-enable={plugin_list}')
138+
if 'upx' in enable_plugins:
120139
if upx_dir.exists():
121-
cmd.append('--plugin-enable=upx')
122140
cmd.append(f'--upx-binary={str(upx_dir)}')
123141
print(f"使用UPX压缩: {upx_dir}")
124142
else:
125143
print(f"警告: UPX目录不存在 {upx_dir}")
126-
else:
127-
print("不使用UPX压缩")
128144

129-
# 添加主Python文件
145+
if custom_command:
146+
# custom_command 为 str
147+
if isinstance(custom_command, str):
148+
cmd.extend(custom_command.split())
149+
# custom_command 为 list
150+
elif isinstance(custom_command, list):
151+
cmd.extend(custom_command)
152+
153+
# 避免中文等特殊字符导致编译报错
130154
t_file = str(uuid.uuid4()) + ".py"
131155
t_file_path = base_dir / t_file
132156
shutil.copy(str(python_file), t_file_path)

package/nuitka_config.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
'rich',
99
'Pillow'
1010
]
11-
upx: true
11+
enable-plugins: [
12+
'upx'
13+
]
1214
# onefile: 2 # 0:文件夹 1:单文件 2:两者
1315
icon: package\assets\favicon.ico
1416
windows-disable-console: False
1517
distpath: 'dist'
1618
timeout: 2700
1719
output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
20+
custom-command: []
1821

1922
- name: 'Keyboard_monitoring'
2023
version: 'v.24.07.16'
@@ -25,13 +28,16 @@
2528
'pywin32',
2629
'psutil'
2730
]
28-
upx: true
31+
enable-plugins: [
32+
'upx'
33+
]
2934
# onefile: 1
3035
icon: package\assets\favicon.ico
3136
windows-disable-console: False
3237
distpath: 'dist'
3338
timeout: 2700
3439
output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
40+
custom-command: []
3541

3642
- name: 'NetEase_Cloud_Music_Download'
3743
version: 'v.25-07-08'
@@ -42,27 +48,33 @@
4248
'tabulate',
4349
'mutagen'
4450
]
45-
upx: true
51+
enable-plugins: [
52+
'upx'
53+
]
4654
# onefile: 1
4755
icon: package\assets\favicon.ico
4856
windows-disable-console: False
4957
distpath: 'dist'
5058
timeout: 2700
5159
output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
60+
custom-command: []
5261

5362
- name: 'ftp_server'
5463
version: 'v.25-05-02'
5564
python-file: 'ftp_server\ftp_server_v.25-05-02.py'
5665
install-requirements: [
5766
'pyftpdlib'
5867
]
59-
upx: true
68+
enable-plugins: [
69+
'upx'
70+
]
6071
# onefile: 1
6172
icon: package\assets\favicon.ico
6273
windows-disable-console: False
6374
distpath: 'dist'
6475
timeout: 2700
6576
output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
77+
custom-command: []
6678

6779
- name: 'sunrise_sunset_info'
6880
version: 'v.25.05.02'
@@ -71,10 +83,13 @@
7183
'pyftpdlib',
7284
'astropy'
7385
]
74-
upx: true
86+
enable-plugins: [
87+
'upx'
88+
]
7589
# onefile: 1 # 0:文件夹 1:单文件 2:两者
7690
icon: package\assets\favicon.ico
7791
windows-disable-console: False
7892
distpath: 'dist'
7993
timeout: 2700
8094
output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
95+
custom-command: []

0 commit comments

Comments
 (0)