From c456d5616f1d2dee66f703118349baa74152499d Mon Sep 17 00:00:00 2001 From: Kissablecho Date: Tue, 8 Jul 2025 12:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0Nuitka=E5=92=8CPyInstaller?= =?UTF-8?q?=E7=9A=84=E6=9E=84=E5=BB=BA=E5=B7=A5=E4=BD=9C=E6=B5=81=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B6=85=E6=97=B6=E8=AE=BE=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96=E9=A1=B9=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BB=A5=E6=94=AF=E6=8C=81=E5=A4=9A=E4=B8=AA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev_package_and_upload.yml | 35 ++- ...package.yml => nuitka_package_release.yml} | 35 ++- ...ml => pyinstaller_package_and_release.yml} | 14 +- novel_crawler/requirements.txt | 3 +- package/nuitka_build.py | 12 +- package/nuitka_config.yml | 64 +++++- package/{build.py => pyinstaller_build.py} | 12 +- .../{config.yml => pyinstaller_config.yml} | 215 +++++++++--------- 8 files changed, 252 insertions(+), 138 deletions(-) rename .github/workflows/{nuitka_package.yml => nuitka_package_release.yml} (72%) rename .github/workflows/{auto_package_and_release.yml => pyinstaller_package_and_release.yml} (92%) rename package/{build.py => pyinstaller_build.py} (91%) rename package/{config.yml => pyinstaller_config.yml} (95%) diff --git a/.github/workflows/dev_package_and_upload.yml b/.github/workflows/dev_package_and_upload.yml index 08943f7..72f6873 100644 --- a/.github/workflows/dev_package_and_upload.yml +++ b/.github/workflows/dev_package_and_upload.yml @@ -1,4 +1,4 @@ -name: Dev Package and Upload(dev) +name: Nuitka Package and Release on: workflow_dispatch: @@ -6,7 +6,7 @@ on: branches: - dev paths: - - 'package/config.yml' + - 'package/nuitka_config.yml' jobs: package-and-release: @@ -27,29 +27,40 @@ 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 pyinstaller pyyaml + pip install nuitka pyyaml ordered-set==4.1.0 wheel==0.38.4 zstandard==0.20.0 + + + # - 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 build.py config.yml + python nuitka_build.py nuitka_config.yml - name: Upload files with wildcards uses: actions/upload-artifact@v4 @@ -59,4 +70,4 @@ jobs: ./dist/*.exe retention-days: 90 if-no-files-found: warn - overwrite: true \ No newline at end of file + overwrite: true diff --git a/.github/workflows/nuitka_package.yml b/.github/workflows/nuitka_package_release.yml similarity index 72% rename from .github/workflows/nuitka_package.yml rename to .github/workflows/nuitka_package_release.yml index 23653df..a76f7a1 100644 --- a/.github/workflows/nuitka_package.yml +++ b/.github/workflows/nuitka_package_release.yml @@ -1,10 +1,10 @@ -name: Nuitka Package(dev) +name: Nuitka Package and Release on: workflow_dispatch: push: branches: - - dev + - main paths: - 'package/nuitka_config.yml' @@ -23,6 +23,17 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + + - name: Generate version tag + id: version + run: | + # 使用 UTC 时间确保一致性 + $date = (Get-Date).ToUniversalTime().ToString("yy.MM.dd") + $tag = "v$date" + $release = "Release $date" + echo "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + echo "release_name=$release" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + - name: Set up Python uses: actions/setup-python@v5 @@ -62,12 +73,16 @@ jobs: cd package python nuitka_build.py nuitka_config.yml - - name: Upload files with wildcards - uses: actions/upload-artifact@v4 + - name: Create Release + id: create_release + uses: softprops/action-gh-release@v1 # 使用更活跃维护的 release 操作 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - name: Artifact - path: | - ./dist/*.exe - retention-days: 90 - if-no-files-found: warn - overwrite: true + tag_name: ${{ steps.version.outputs.tag }} + name: ${{ steps.version.outputs.release_name }} + generate_release_notes: true + draft: false + prerelease: false + files: | + dist/*.exe diff --git a/.github/workflows/auto_package_and_release.yml b/.github/workflows/pyinstaller_package_and_release.yml similarity index 92% rename from .github/workflows/auto_package_and_release.yml rename to .github/workflows/pyinstaller_package_and_release.yml index a203dda..8b9dec5 100644 --- a/.github/workflows/auto_package_and_release.yml +++ b/.github/workflows/pyinstaller_package_and_release.yml @@ -1,12 +1,12 @@ -name: Auto Package and Release +name: Pyinstaller Package and Release on: workflow_dispatch: - push: - branches: - - main - paths: - - 'package/config.yml' + # push: + # branches: + # - main + # paths: + # - 'package/config.yml' jobs: package-and-release: @@ -59,7 +59,7 @@ jobs: - name: Run packaging script run: | cd package - python build.py config.yml + python pyinstaller_build.py pyinstaller_config.yml - name: Create Release id: create_release diff --git a/novel_crawler/requirements.txt b/novel_crawler/requirements.txt index dab618a..4050fd0 100644 --- a/novel_crawler/requirements.txt +++ b/novel_crawler/requirements.txt @@ -2,4 +2,5 @@ beautifulsoup4 requests ebooklib yaml -rich \ No newline at end of file +rich +Pillow \ No newline at end of file diff --git a/package/nuitka_build.py b/package/nuitka_build.py index 4d150e7..d2ae578 100644 --- a/package/nuitka_build.py +++ b/package/nuitka_build.py @@ -58,6 +58,7 @@ def main(): windows_disable_console = task.get('windows-disable-console', False) name = task.get('name') version = task.get('version') + timeout = task.get('timeout', 60 * 45) output_name_template = task.get('output-name-template', '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}') if arrch == "AMD64": arrch = "x64" @@ -124,7 +125,16 @@ def main(): # 打印并执行命令 print("执行命令:", ' '.join(cmd)) - result = subprocess.run(cmd) + if timeout: + try: + result = subprocess.run(cmd,timeout=timeout) + except subprocess.TimeoutExpired: + print(f"任务[{i}/{len(config)} {task['name']}] 执行超时 {timeout} 秒") + print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}") + task_error_list.append(task['name']) + continue + else: + result = subprocess.run(cmd) if result.returncode == 0: print(f"(onefile)打包成功: {dist_path / output_name}") diff --git a/package/nuitka_config.yml b/package/nuitka_config.yml index 7245973..43fb293 100644 --- a/package/nuitka_config.yml +++ b/package/nuitka_config.yml @@ -8,9 +8,71 @@ 'rich', 'Pillow' ] - upx: true + # upx: true # onefile: 2 # 0:文件夹 1:单文件 2:两者 icon: windows-disable-console: False distpath: 'dist' + timeout: 1200 + output-name-template: '{{name}}_{{version}}_nuitka_{{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: + windows-disable-console: False + distpath: 'dist' + timeout: 1200 + output-name-template: '{{name}}_{{version}}_nuitka_{{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: + windows-disable-console: False + distpath: 'dist' + timeout: 1200 + output-name-template: '{{name}}_{{version}}_nuitka_{{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: + windows-disable-console: False + distpath: 'dist' + timeout: 1200 + output-name-template: '{{name}}_{{version}}_nuitka_{{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: + windows-disable-console: False + distpath: 'dist' + timeout: 1200 output-name-template: '{{name}}_{{version}}_nuitka_{{os}}_{{arch}}' diff --git a/package/build.py b/package/pyinstaller_build.py similarity index 91% rename from package/build.py rename to package/pyinstaller_build.py index 83b9729..2a66034 100644 --- a/package/build.py +++ b/package/pyinstaller_build.py @@ -61,6 +61,7 @@ def main(): windowed = task.get('windowed', False) name = task.get('name') version = task.get('version') + timeout = task.get('timeout', 60 * 45) output_name_template = task.get('output-name-template', '{{name}}_{{version}}_pyInstaller_{{os}}_{{arch}}') if arrch == "AMD64": arrch = "x64" @@ -135,7 +136,16 @@ def main(): # 打印并执行命令 print("执行命令:", ' '.join(cmd)) - result = subprocess.run(cmd) + if timeout: + try: + result = subprocess.run(cmd,timeout=timeout) + except subprocess.TimeoutExpired: + print(f"任务[{i}/{len(config)} {task['name']}] 执行超时 {timeout} 秒") + print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}") + task_error_list.append(task['name']) + continue + else: + result = subprocess.run(cmd) # if onefile == 2: # cmd.append(str(python_file)) diff --git a/package/config.yml b/package/pyinstaller_config.yml similarity index 95% rename from package/config.yml rename to package/pyinstaller_config.yml index 41c8d03..76ade5b 100644 --- a/package/config.yml +++ b/package/pyinstaller_config.yml @@ -1,105 +1,110 @@ -- 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}}' +- 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' + timeout: 1200 + 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' + timeout: 1200 + 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' + timeout: 1200 + 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' + timeout: 1200 + 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' + timeout: 1200 + output-name-template: '{{name}}_{{version}}_pyInstaller_{{os}}_{{arch}}'