From cdf68cb7abfe84e98357b90fb47937a4e864d786 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Wed, 29 May 2024 15:56:41 +0200 Subject: [PATCH] Use new pyinstaller pathing and remove onefile flags + macfix --- .github/workflows/main.yml | 8 +-- pyinst.py | 110 +++++++++---------------------------- 2 files changed, 29 insertions(+), 89 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index baca6da3..a9716002 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - name: Install PyInstaller run: python -m pip install --upgrade PyInstaller - name: Run pyinst.py - run: python3 pyinst.py --no-prompts --onefile --no-upx --no-crt --no-clean --windowed + run: python3 pyinst.py --no-prompts --no-upx --no-crt --no-clean --windowed - name: Create archive (.tar.xz) run: tar -cavf Pesterchum_linux64.tar.xz -C dist Pesterchum - uses: actions/upload-artifact@v3 @@ -47,7 +47,7 @@ jobs: - name: Install PyInstaller run: python -m pip install --upgrade PyInstaller - name: Run PyInstaller - run: python3 pyinst.py --no-prompts --onefile --no-upx --crt --no-clean --windowed + run: python3 pyinst.py --no-prompts --no-upx --crt --no-clean --windowed - name: Create archive (.zip) run: tar.exe -a -c -f Pesterchum_win64_py311.zip -C dist Pesterchum - uses: actions/upload-artifact@v3 @@ -73,7 +73,7 @@ jobs: - name: Install PyInstaller run: python -m pip install --upgrade PyInstaller - name: Run PyInstaller - run: python3 pyinst.py --prompts False --onefile True --upx False --crt True --clean False --windowed True + run: python3 pyinst.py --prompts False True --upx False --crt True --clean False --windowed True - name: Create archive (.zip) run: tar.exe -a -c -f Pesterchum_win32_py38.zip -C dist Pesterchum - uses: actions/upload-artifact@v3 @@ -99,7 +99,7 @@ jobs: - name: Install PyInstaller run: python -m pip install --upgrade PyInstaller - name: Run pyinst.py - run: python3 pyinst.py --no-prompts --onefile --no-upx --no-crt --no-clean --windowed + run: python3 pyinst.py --no-prompts --no-upx --no-crt --no-clean --windowed - name: Create archive (.tar.xz) run: tar -cavf Pesterchum_macOS64.tar.xz -C dist Pesterchum.app - uses: actions/upload-artifact@v3 diff --git a/pyinst.py b/pyinst.py index bfe89bd0..117c85fa 100644 --- a/pyinst.py +++ b/pyinst.py @@ -9,6 +9,7 @@ is_64bit = sys.maxsize > 2**32 # is_linux = sys.platform.startswith("linux") exclude_modules = [] + add_data = [ "quirks;quirks", "smilies;smilies", @@ -36,6 +37,7 @@ "LICENSE": "LICENSE.txt", "CHANGELOG.md": "CHANGELOG.md", } + # Some of these might not be required anymore, # newer versions of PyInstaller claim to exclude certain problematic DDLs automatically. upx_exclude = [ @@ -95,7 +97,6 @@ delete_builddist = "" upx_enabled = "" package_universal_crt = "" -onefile = "" windowed = "" upx_dir = "" crt_path = "" @@ -114,11 +115,6 @@ help="Prompt for the options below on run", action=argparse.BooleanOptionalAction, ) - parser.add_argument( - "--onefile", - help="Create a one-file bundled executable.", - action=argparse.BooleanOptionalAction, - ) parser.add_argument( "--upx", help="Try to compress binaries with UPX.", @@ -155,11 +151,6 @@ elif _ARGUMENTS.crt is False: package_universal_crt = "n" - if _ARGUMENTS.onefile: - onefile = "y" - elif _ARGUMENTS.onefile is False: - onefile = "n" - if _ARGUMENTS.windowed: windowed = "y" elif _ARGUMENTS.windowed is False: @@ -172,12 +163,6 @@ action="store", choices=["True", "False"], ) - parser.add_argument( - "--onefile", - help="Create a one-file bundled executable.", - action="store", - choices=["True", "False"], - ) parser.add_argument( "--upx", help="Try to compress binaries with UPX.", @@ -215,10 +200,6 @@ package_universal_crt = "y" elif _ARGUMENTS.crt == "False": package_universal_crt = "n" - if _ARGUMENTS.onefile == "True": - onefile = "y" - elif _ARGUMENTS.onefile == "False": - onefile = "n" if _ARGUMENTS.windowed == "True": windowed = "y" elif _ARGUMENTS.windowed == "False": @@ -296,10 +277,6 @@ ) print("crt_path = " + crt_path) - if sys.platform in ("win32", "linux"): - while onefile not in ("y", "n"): - onefile = input("Build with '--onefile'? (Y/N): ").lower() - except KeyboardInterrupt: sys.exit("KeyboardInterrupt") else: @@ -333,8 +310,6 @@ ) print("crt_path = " + crt_path) package_universal_crt = "y" - if _ARGUMENTS.onefile is None: - onefile = "y" if _ARGUMENTS.windowed is None: windowed = "y" @@ -374,11 +349,6 @@ run_win32.append("--exclude-module=%s" % x) if windowed == "y": run_win32.append("--windowed") - if onefile == "y": - run_win32.append("--onefile") - elif onefile == "n": - for x in add_data: - run_win32.append("--add-data=%s" % x) if package_universal_crt == "y": run_win32.append("--paths=%s" % crt_path) @@ -657,28 +627,17 @@ print(run_win32) PyInstaller.__main__.run(run_win32) - if onefile == "y": - # There's more proper ways to do this, but this doesn't require changing our paths - for x in data_folders: - print(x) - shutil.copytree( - x, - os.path.join("dist", data_folders[x]), - ignore=shutil.ignore_patterns( - "*.psd", "*.xcf*", "ebg2.png", "ebg1.png" - ), - ) - for x in data_files: - print(x) - shutil.copy(x, os.path.join("dist", data_files[x])) - - files = os.listdir("dist") - try: - os.mkdir(os.path.join("dist", "Pesterchum")) - except FileExistsError: - pass - for x in files: - shutil.move(os.path.join("dist", x), os.path.join("dist", "Pesterchum")) + # There's more proper ways to do this, but this doesn't require changing our paths + for x in data_folders: + print(x) + shutil.copytree( + x, + os.path.join("dist", "Pesterchum", data_folders[x]), + ignore=shutil.ignore_patterns("*.psd", "*.xcf*", "ebg2.png", "ebg1.png"), + ) + for x in data_files: + print(x) + shutil.copy(x, os.path.join("dist", "Pesterchum", data_files[x])) # shutil.copy(os.path.join('build', 'Pesterchum', 'xref-Pesterchum.html'), # os.path.join('dist', 'Pesterchum', 'xref-Pesterchum.html')) @@ -740,43 +699,24 @@ run_linux.append("--noupx") for x in exclude_modules: run_linux.append("--exclude-module=%s" % x) - if onefile == "y": - run_linux.append("--onefile") - elif onefile == "n": - for x in add_data: - run_linux.append("--add-data=%s" % x.replace(";", ":")) if windowed == "y": run_linux.append("--windowed") print(run_linux) PyInstaller.__main__.run(run_linux) - if onefile == "y": - # There's more proper ways to do this, but this doesn't require changing our paths - for x in data_folders: - print(x) - shutil.copytree( - x, - os.path.join("dist", data_folders[x]), - ignore=shutil.ignore_patterns( - "*.psd", "*.xcf*", "ebg2.png", "ebg1.png" - ), - ) - for x in data_files_linux: - print(x) - shutil.copy(x, os.path.join("dist", data_files_linux[x])) - - files = os.listdir("dist") - try: - os.mkdir(os.path.join("dist", ".cache")) - except FileExistsError as e: - print(e) - for x in files: - try: - shutil.move(os.path.join("dist", x), os.path.join("dist", ".cache", x)) - except FileExistsError as e: - print(e) - shutil.move(os.path.join("dist", ".cache"), os.path.join("dist", "Pesterchum")) + # There's more proper ways to do this, but this doesn't require changing our paths + for x in data_folders: + print(x) + shutil.copytree( + x, + os.path.join("dist", "Pesterchum", data_folders[x]), + ignore=shutil.ignore_patterns("*.psd", "*.xcf*", "ebg2.png", "ebg1.png"), + ) + for x in data_files_linux: + print(x) + shutil.copy(x, os.path.join("dist", "Pesterchum", data_files_linux[x])) + # shutil.copy(os.path.join('build', 'Pesterchum', 'xref-Pesterchum.html'), # os.path.join('dist', 'Pesterchum', 'xref-Pesterchum.html')) # shutil.copy(os.path.join('build', 'Pesterchum', 'Analysis-00.toc'),