import os import sys import glob import platform import subprocess from pathlib import Path from zipfile import ZIP_DEFLATED, ZipFile from main import APP_NAME, APP_VERSION COMPILER = "mingw64" OUTPUT_PATH = Path('output') RESOURCES_PATH = Path("resources") RELEASE_PATH = OUTPUT_PATH / APP_NAME BUILD_PATH = OUTPUT_PATH / f'{platform.system().lower()}-{platform.machine().lower()}' def build_main(): nuitka_cmd = [ 'python', '-m', 'nuitka', '--standalone', '--show-memory', '--show-progress', '--plugin-enable=pyside6', '--include-module=qt_material', f"--include-data-dir={RESOURCES_PATH}=resources", ] icon_path = str(RESOURCES_PATH / "main.ico") if os.path.exists(icon_path): nuitka_cmd.extend([ f'--windows-icon-from-ico={icon_path}', ]) nuitka_cmd.append(f'--output-dir={BUILD_PATH}') if platform.system() == 'Windows': nuitka_cmd.append('--windows-console-mode=disable') nuitka_cmd.append(f'--{COMPILER}') nuitka_cmd.append('./main.py') result = subprocess.run(nuitka_cmd,shell=True) if result.returncode != 0: raise RuntimeError('Nuitka building failed.') print('Building done.') def create_zip(): file_list = glob.glob(f'{BUILD_PATH / APP_NAME / "dist"}', recursive=True) file_list.sort() if not os.path.exists(RELEASE_PATH): os.mkdir(RELEASE_PATH) portable_file = RELEASE_PATH / f'{APP_NAME}-{platform.system()}-{platform.machine()}-{APP_VERSION}.zip' print('Creating portable package...') with ZipFile(portable_file, 'w', compression=ZIP_DEFLATED) as zf: for file in file_list: file = Path(file) name_in_zip = f'{APP_NAME}/{"/".join(file.parts[3:])}' print(name_in_zip) zf.write(file, name_in_zip) print('Creating portable package done.') if __name__ == '__main__': build_main()