Skip to content
Merged

Dev #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/nuitka_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Nuitka Package(dev)

on:
workflow_dispatch:
push:
branches:
- dev
paths:
- 'package/nuitka_config.yml'

jobs:
package-and-release:
runs-on: windows-latest

# 添加必要的权限
permissions:
contents: write # 允许创建发布和上传资源

steps:
- name: Set Timezone to China Standard Time
run: tzutil /s "China Standard Time"
shell: pwsh

- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'


- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nuitka pyyaml

- name: insatll mingw
run: |
midir C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2
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
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\

- name: Fix Python encoding (Windows)
run: |
# 设置Python使用UTF-8编码
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process')
# 设置控制台编码为UTF-8
chcp.com 65001

- name: Run packaging script
run: |
cd package
python nuitka_build.py nuitka_config.yml

- name: Upload files with wildcards
uses: actions/upload-artifact@v4
with:
name: Artifact
path: |
./dist/*.exe
retention-days: 90
if-no-files-found: warn
overwrite: true
104 changes: 0 additions & 104 deletions package/config.yml
Original file line number Diff line number Diff line change
@@ -1,104 +0,0 @@
- name: 'novel_crawler'
version: 'v.25.07.08'
python-file: 'novel_crawler\novel_crawler_v.25.07.08.py'
install-requirements: [
'beautifulsoup4',
'requests',
'ebooklib',
'rich'
]
upx: true
# onefile: 2 # 0:文件夹 1:单文件 2:两者
icon:
windowed: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'

- name: 'Keyboard_monitoring'
version: 'v.24.07.16'
python-file: '键盘监听\v.24.07.16.py'
install-requirements: [
'keyboard',
'configparser',
'pywin32'
]
upx: true
# onefile: 1
icon:
windowed: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'

- name: 'NetEase_Cloud_Music_Download'
version: 'v.24-10-06'
python-file: '网易云音乐歌单批量下载歌曲\v.24-10-06.py'
install-requirements: [
'quote',
'requests',
'tabulate',
'mutagen'
]
upx: true
# onefile: 1
icon:
windowed: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'

- name: 'ftp_server'
version: 'v.25-05-02'
python-file: 'ftp_server\ftp_server_v.25-05-02.py'
install-requirements: [
'pyftpdlib'
]
upx: true
# onefile: 1
icon:
windowed: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'

# - name: 'psql_terminal'
# version:
# os: [
# 'Windows',
# 'Linux'
# ]
# python-file: 'psql_terminal\psql_terminal.py'
# install-requirements: [
# 'psycopg2'
# ]
# upx: true
# icon:
# windowed: False
# distpath: 'dist'
# output-name: '{{name}}_{{os}}_{{arch}}'

# - name: 'package'
# version:
# os: [
# 'Windows',
# 'Linux'
# ]
# python-file: 'package\build.py'
# install-requirements: [
# 'pyinstaller'
# ]
# upx: true
# icon:
# windowed: False
# distpath: 'dist'
# output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'

- name: 'sunrise_sunset_info'
version: 'v.25.05.02'
python-file: 'sunrise_sunset_info\sunrise_sunset_info_v.25.05.02.py'
install-requirements: [
'pyftpdlib'
]
upx: true
# onefile: 1 # 0:文件夹 1:单文件 2:两者
icon:
windowed: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_{{os}}_{{arch}}'
132 changes: 132 additions & 0 deletions package/nuitka_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import os
import sys
import yaml
import subprocess
import platform
import argparse
from pathlib import Path
# from zip import zip_files_and_folders

def main():
print("="*50)
print("="*50)
# 修复编码问题 - 设置UTF-8输出
sys.stdout.reconfigure(encoding='utf-8') # Python 3.7+
sys.stderr.reconfigure(encoding='utf-8')

# 检查Python版本
if sys.version_info < (3, 7):
print("错误: 请使用Python 3.7或更高版本")
return

Machine = platform.system()
arrch = platform.machine()

print(f"当前操作系统: {Machine} {arrch}")
print(f"平台详情: {platform.platform()}")
print(f"Python版本: {sys.version}")

# 解析命令行参数
parser = argparse.ArgumentParser(description='PyInstaller打包脚本')
parser.add_argument('config', help='配置文件路径')
args = parser.parse_args()

# 读取配置文件
with open(args.config, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)

# 基础路径设置
base_dir = Path(__file__).parent.parent # 项目根目录

success_count = 0
task_error_list = []
# 遍历所有打包任务
for i, task in enumerate(config, start=1):
try:
print(f"\n{'='*40}")
print(f"开始打包任务: [{i}/{len(config)}] {task['name']}")
print(f"{'='*40}")

# 解析任务参数
python_file = base_dir / task['python-file']
dist_path = base_dir / task['distpath']
requirements = task.get('install-requirements', [])
use_upx = task.get('upx', False)
# onefile = task.get('onefile', 0)
icon = task.get('icon')
windows_disable_console = task.get('windows-disable-console', False)
name = task.get('name')
version = task.get('version')
output_name_template = task.get('output-name-template', '{{name}}_{{version}}_{{arch}}_{{os}}')
if arrch == "AMD64":
arrch = "x64"
output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine)

# 检查操作系统和架构
# if Machine not in task.get('os', []):
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前操作系统 {Machine}")
# continue
# if arrch not in task.get('arch', []):
# print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前架构 {arrch}")
# continue

# 检查Python文件是否存在
if not python_file.exists():
print(f"错误: Python文件不存在 {python_file}")
continue

# 安装依赖
if requirements:
print(f"安装依赖: {', '.join(requirements)}")
subprocess.run([sys.executable, '-m', 'pip', 'install'] + requirements, check=True)

# 构建PyInstaller命令
cmd = [
sys.executable, '-m', 'nuitka',
f'--output-filename={output_name}.exe',
f'--output-dir={dist_path}', # 输出目录
'--onefile', # 单文件
'--standalone',
'--mingw64'
]

# 添加窗口模式选项
if windows_disable_console:
cmd.append('--windows-disable-console')

# 添加图标选项
if icon:
icon_path = base_dir / icon
if icon_path.exists():
cmd.extend(['--windows-icon-from-ico=icon.ico', str(icon_path)])
else:
print(f"警告: 图标文件不存在 {icon_path}")


# 添加主Python文件
cmd.append(str(python_file))

# 打印并执行命令
print("执行命令:", ' '.join(cmd))
result = subprocess.run(cmd)

if result.returncode == 0:
print(f"(onefile)打包成功: {dist_path / output_name}")
success_count += 1
else:
print(f"(onefile)打包失败,退出码: {result.returncode}")
except Exception as e:
print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}")
task_error_list.append(task['name'])
continue
if success_count != 0:
print(f"打包完成,成功打包 [{success_count}/{len(config)}] 个任务")
if task_error_list != []:
print(f"打包失败的任务: {', '.join(task_error_list)}")
else:
print("打包失败,没有成功打包任何任务")
print(f"失败的任务: {', '.join(task_error_list)}")
sys.exit(0)

if __name__ == '__main__':
main()
15 changes: 15 additions & 0 deletions package/nuitka_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: 'novel_crawler'
version: 'v.25.07.08'
python-file: 'novel_crawler\novel_crawler_v.25.07.08.py'
install-requirements: [
'beautifulsoup4',
'requests',
'ebooklib',
'rich'
]
upx: true
# onefile: 2 # 0:文件夹 1:单文件 2:两者
icon:
windows-disable-console: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
Loading