Skip to content

Commit bf9f6ea

Browse files
authored
Merge pull request #13 from God-2077/dev
Dev
2 parents 08ea81c + 9423e6d commit bf9f6ea

4 files changed

Lines changed: 211 additions & 104 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Nuitka Package(dev)
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- dev
8+
paths:
9+
- 'package/nuitka_config.yml'
10+
11+
jobs:
12+
package-and-release:
13+
runs-on: windows-latest
14+
15+
# 添加必要的权限
16+
permissions:
17+
contents: write # 允许创建发布和上传资源
18+
19+
steps:
20+
- name: Set Timezone to China Standard Time
21+
run: tzutil /s "China Standard Time"
22+
shell: pwsh
23+
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: '3.12'
31+
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install nuitka pyyaml
37+
38+
- name: insatll mingw
39+
run: |
40+
midir C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2
41+
curl -o winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-19.1.1-12.0.0-msvcrt-r2/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip
42+
tar -xf C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip -C C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\
43+
44+
- name: Fix Python encoding (Windows)
45+
run: |
46+
# 设置Python使用UTF-8编码
47+
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process')
48+
# 设置控制台编码为UTF-8
49+
chcp.com 65001
50+
51+
- name: Run packaging script
52+
run: |
53+
cd package
54+
python nuitka_build.py nuitka_config.yml
55+
56+
- name: Upload files with wildcards
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: Artifact
60+
path: |
61+
./dist/*.exe
62+
retention-days: 90
63+
if-no-files-found: warn
64+
overwrite: true

package/config.yml

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +0,0 @@
1-
- name: 'novel_crawler'
2-
version: 'v.25.07.08'
3-
python-file: 'novel_crawler\novel_crawler_v.25.07.08.py'
4-
install-requirements: [
5-
'beautifulsoup4',
6-
'requests',
7-
'ebooklib',
8-
'rich'
9-
]
10-
upx: true
11-
# onefile: 2 # 0:文件夹 1:单文件 2:两者
12-
icon:
13-
windowed: False
14-
distpath: 'dist'
15-
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'
16-
17-
- name: 'Keyboard_monitoring'
18-
version: 'v.24.07.16'
19-
python-file: '键盘监听\v.24.07.16.py'
20-
install-requirements: [
21-
'keyboard',
22-
'configparser',
23-
'pywin32'
24-
]
25-
upx: true
26-
# onefile: 1
27-
icon:
28-
windowed: False
29-
distpath: 'dist'
30-
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'
31-
32-
- name: 'NetEase_Cloud_Music_Download'
33-
version: 'v.24-10-06'
34-
python-file: '网易云音乐歌单批量下载歌曲\v.24-10-06.py'
35-
install-requirements: [
36-
'quote',
37-
'requests',
38-
'tabulate',
39-
'mutagen'
40-
]
41-
upx: true
42-
# onefile: 1
43-
icon:
44-
windowed: False
45-
distpath: 'dist'
46-
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'
47-
48-
- name: 'ftp_server'
49-
version: 'v.25-05-02'
50-
python-file: 'ftp_server\ftp_server_v.25-05-02.py'
51-
install-requirements: [
52-
'pyftpdlib'
53-
]
54-
upx: true
55-
# onefile: 1
56-
icon:
57-
windowed: False
58-
distpath: 'dist'
59-
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'
60-
61-
# - name: 'psql_terminal'
62-
# version:
63-
# os: [
64-
# 'Windows',
65-
# 'Linux'
66-
# ]
67-
# python-file: 'psql_terminal\psql_terminal.py'
68-
# install-requirements: [
69-
# 'psycopg2'
70-
# ]
71-
# upx: true
72-
# icon:
73-
# windowed: False
74-
# distpath: 'dist'
75-
# output-name: '{{name}}_{{os}}_{{arch}}'
76-
77-
# - name: 'package'
78-
# version:
79-
# os: [
80-
# 'Windows',
81-
# 'Linux'
82-
# ]
83-
# python-file: 'package\build.py'
84-
# install-requirements: [
85-
# 'pyinstaller'
86-
# ]
87-
# upx: true
88-
# icon:
89-
# windowed: False
90-
# distpath: 'dist'
91-
# output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'
92-
93-
- name: 'sunrise_sunset_info'
94-
version: 'v.25.05.02'
95-
python-file: 'sunrise_sunset_info\sunrise_sunset_info_v.25.05.02.py'
96-
install-requirements: [
97-
'pyftpdlib'
98-
]
99-
upx: true
100-
# onefile: 1 # 0:文件夹 1:单文件 2:两者
101-
icon:
102-
windowed: False
103-
distpath: 'dist'
104-
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'

package/nuitka_build.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import os
2+
import sys
3+
import yaml
4+
import subprocess
5+
import platform
6+
import argparse
7+
from pathlib import Path
8+
# from zip import zip_files_and_folders
9+
10+
def main():
11+
print("="*50)
12+
print("="*50)
13+
# 修复编码问题 - 设置UTF-8输出
14+
sys.stdout.reconfigure(encoding='utf-8') # Python 3.7+
15+
sys.stderr.reconfigure(encoding='utf-8')
16+
17+
# 检查Python版本
18+
if sys.version_info < (3, 7):
19+
print("错误: 请使用Python 3.7或更高版本")
20+
return
21+
22+
Machine = platform.system()
23+
arrch = platform.machine()
24+
25+
print(f"当前操作系统: {Machine} {arrch}")
26+
print(f"平台详情: {platform.platform()}")
27+
print(f"Python版本: {sys.version}")
28+
29+
# 解析命令行参数
30+
parser = argparse.ArgumentParser(description='PyInstaller打包脚本')
31+
parser.add_argument('config', help='配置文件路径')
32+
args = parser.parse_args()
33+
34+
# 读取配置文件
35+
with open(args.config, 'r', encoding='utf-8') as f:
36+
config = yaml.safe_load(f)
37+
38+
# 基础路径设置
39+
base_dir = Path(__file__).parent.parent # 项目根目录
40+
41+
success_count = 0
42+
task_error_list = []
43+
# 遍历所有打包任务
44+
for i, task in enumerate(config, start=1):
45+
try:
46+
print(f"\n{'='*40}")
47+
print(f"开始打包任务: [{i}/{len(config)}] {task['name']}")
48+
print(f"{'='*40}")
49+
50+
# 解析任务参数
51+
python_file = base_dir / task['python-file']
52+
dist_path = base_dir / task['distpath']
53+
requirements = task.get('install-requirements', [])
54+
use_upx = task.get('upx', False)
55+
# onefile = task.get('onefile', 0)
56+
icon = task.get('icon')
57+
windows_disable_console = task.get('windows-disable-console', False)
58+
name = task.get('name')
59+
version = task.get('version')
60+
output_name_template = task.get('output-name-template', '{{name}}_{{version}}_{{arch}}_{{os}}')
61+
if arrch == "AMD64":
62+
arrch = "x64"
63+
output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine)
64+
65+
# 检查操作系统和架构
66+
# if Machine not in task.get('os', []):
67+
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前操作系统 {Machine}")
68+
# continue
69+
# if arrch not in task.get('arch', []):
70+
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前架构 {arrch}")
71+
# continue
72+
73+
# 检查Python文件是否存在
74+
if not python_file.exists():
75+
print(f"错误: Python文件不存在 {python_file}")
76+
continue
77+
78+
# 安装依赖
79+
if requirements:
80+
print(f"安装依赖: {', '.join(requirements)}")
81+
subprocess.run([sys.executable, '-m', 'pip', 'install'] + requirements, check=True)
82+
83+
# 构建PyInstaller命令
84+
cmd = [
85+
sys.executable, '-m', 'nuitka',
86+
f'--output-filename={output_name}.exe',
87+
f'--output-dir={dist_path}', # 输出目录
88+
'--onefile', # 单文件
89+
'--standalone',
90+
'--mingw64'
91+
]
92+
93+
# 添加窗口模式选项
94+
if windows_disable_console:
95+
cmd.append('--windows-disable-console')
96+
97+
# 添加图标选项
98+
if icon:
99+
icon_path = base_dir / icon
100+
if icon_path.exists():
101+
cmd.extend(['--windows-icon-from-ico=icon.ico', str(icon_path)])
102+
else:
103+
print(f"警告: 图标文件不存在 {icon_path}")
104+
105+
106+
# 添加主Python文件
107+
cmd.append(str(python_file))
108+
109+
# 打印并执行命令
110+
print("执行命令:", ' '.join(cmd))
111+
result = subprocess.run(cmd)
112+
113+
if result.returncode == 0:
114+
print(f"(onefile)打包成功: {dist_path / output_name}")
115+
success_count += 1
116+
else:
117+
print(f"(onefile)打包失败,退出码: {result.returncode}")
118+
except Exception as e:
119+
print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}")
120+
task_error_list.append(task['name'])
121+
continue
122+
if success_count != 0:
123+
print(f"打包完成,成功打包 [{success_count}/{len(config)}] 个任务")
124+
if task_error_list != []:
125+
print(f"打包失败的任务: {', '.join(task_error_list)}")
126+
else:
127+
print("打包失败,没有成功打包任何任务")
128+
print(f"失败的任务: {', '.join(task_error_list)}")
129+
sys.exit(0)
130+
131+
if __name__ == '__main__':
132+
main()

package/nuitka_config.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- name: 'novel_crawler'
2+
version: 'v.25.07.08'
3+
python-file: 'novel_crawler\novel_crawler_v.25.07.08.py'
4+
install-requirements: [
5+
'beautifulsoup4',
6+
'requests',
7+
'ebooklib',
8+
'rich'
9+
]
10+
upx: true
11+
# onefile: 2 # 0:文件夹 1:单文件 2:两者
12+
icon:
13+
windows-disable-console: False
14+
distpath: 'dist'
15+
output-name: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'

0 commit comments

Comments
 (0)