Skip to content
Merged

sync #14

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
33 changes: 21 additions & 12 deletions .github/workflows/nuitka_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,38 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

python-version: '3.10'

- name: UPX Setup
run: |
mkdir upx
curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/windows-amd64/upx.exe

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nuitka pyyaml
pip install nuitka pyyaml ordered-set==4.1.0 wheel==0.38.4 zstandard==0.20.0


- 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: insatll mingw
# run: |
# mkdir 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 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 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)
# - 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: |
# 设置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

Expand Down
7 changes: 5 additions & 2 deletions package/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def main():

success_count = 0
task_error_list = []
if not config:
print("无任务")
sys.exit(0)
# 遍历所有打包任务
for i, task in enumerate(config, start=1):
try:
Expand All @@ -58,7 +61,7 @@ def main():
windowed = task.get('windowed', False)
name = task.get('name')
version = task.get('version')
output_name_template = task.get('output-name-template', '{{name}}_{{version}}_{{arch}}_{{os}}')
output_name_template = task.get('output-name-template', '{{name}}_{{version}}_pyInstaller_{{os}}_{{arch}}')
if arrch == "AMD64":
arrch = "x64"
output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine)
Expand Down Expand Up @@ -157,4 +160,4 @@ def main():
sys.exit(0)

if __name__ == '__main__':
main()
main()
105 changes: 105 additions & 0 deletions package/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
- 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',
'Pillow'
]
upx: true
# onefile: 2 # 0:文件夹 1:单文件 2:两者
icon:
windowed: False
distpath: 'dist'
output-name-template: '{{name}}_{{version}}_pyInstaller_{{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-template: '{{name}}_{{version}}_pyInstaller_{{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-template: '{{name}}_{{version}}_pyInstaller_{{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-template: '{{name}}_{{version}}_pyInstaller_{{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-template: '{{name}}_{{version}}_pyInstaller_{{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-template: '{{name}}_{{version}}_pyInstaller_{{os}}_{{arch}}'
32 changes: 24 additions & 8 deletions package/nuitka_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
print(f"Python版本: {sys.version}")

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

Expand All @@ -37,6 +37,7 @@ def main():

# 基础路径设置
base_dir = Path(__file__).parent.parent # 项目根目录
upx_dir = base_dir / './upx/' # UPX目录

success_count = 0
task_error_list = []
Expand All @@ -57,7 +58,7 @@ def main():
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}}')
output_name_template = task.get('output-name-template', '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}')
if arrch == "AMD64":
arrch = "x64"
output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine)
Expand Down Expand Up @@ -87,7 +88,11 @@ def main():
f'--output-dir={dist_path}', # 输出目录
'--onefile', # 单文件
'--standalone',
'--mingw64'
'--mingw64',
# '--mode',
'--assume-yes-for-downloads', #自动下载外部代码
'--show-memory'

]

# 添加窗口模式选项
Expand All @@ -101,8 +106,19 @@ def main():
cmd.extend(['--windows-icon-from-ico=icon.ico', str(icon_path)])
else:
print(f"警告: 图标文件不存在 {icon_path}")



# if arrch == "ARM64":
# print("UPX不支持当前架构")
# else:
# if use_upx:
# if upx_dir.exists():
# cmd.append('--plugin-enable=upx')
# cmd.extend(['--upx-binary', str(upx_dir)])
# print(f"使用UPX压缩: {upx_dir}")
# else:
# print(f"警告: UPX目录不存在 {upx_dir}")
# else:
# print("不使用UPX压缩")
# 添加主Python文件
cmd.append(str(python_file))

Expand All @@ -114,7 +130,7 @@ def main():
print(f"(onefile)打包成功: {dist_path / output_name}")
success_count += 1
else:
print(f"(onefile)打包失败,退出码: {result.returncode}")
print(f"打包失败,退出码: {result.returncode}")
except Exception as e:
print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}")
task_error_list.append(task['name'])
Expand All @@ -126,7 +142,7 @@ def main():
else:
print("打包失败,没有成功打包任何任务")
print(f"失败的任务: {', '.join(task_error_list)}")
sys.exit(0)
sys.exit(1)

if __name__ == '__main__':
main()
main()
5 changes: 3 additions & 2 deletions package/nuitka_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
'beautifulsoup4',
'requests',
'ebooklib',
'rich'
'rich',
'Pillow'
]
upx: true
# onefile: 2 # 0:文件夹 1:单文件 2:两者
icon:
windows-disable-console: False
distpath: 'dist'
output-name: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'
output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}'