From 335a8bc88ce2a4a8bcb46c25585985a93d839935 Mon Sep 17 00:00:00 2001 From: Georg Sieber Date: Fri, 14 Jun 2024 14:10:30 +0200 Subject: [PATCH] add pyinstaller linux spec files for future use --- laps-client/laps-client.linux.spec | 107 +++++++++++++++++++++++++++++ laps-runner/laps-runner.linux.spec | 74 ++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 laps-client/laps-client.linux.spec create mode 100644 laps-runner/laps-runner.linux.spec diff --git a/laps-client/laps-client.linux.spec b/laps-client/laps-client.linux.spec new file mode 100644 index 0000000..4ce7001 --- /dev/null +++ b/laps-client/laps-client.linux.spec @@ -0,0 +1,107 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + +def Entrypoint(dist, group, name, **kwargs): + import pkg_resources + + # get toplevel packages of distribution from metadata + def get_toplevel(dist): + distribution = pkg_resources.get_distribution(dist) + if distribution.has_metadata('top_level.txt'): + return list(distribution.get_metadata('top_level.txt').split()) + else: + return [] + + kwargs.setdefault('hiddenimports', []) + packages = [] + for distribution in kwargs['hiddenimports']: + packages += get_toplevel(distribution) + + kwargs.setdefault('pathex', []) + # get the entry point + ep = pkg_resources.get_entry_info(dist, group, name) + # insert path of the egg at the verify front of the search path + kwargs['pathex'] = [ep.dist.location] + kwargs['pathex'] + # script name must not be a valid module name to avoid name clashes on import + script_path = os.path.join(workpath, name + '-script.py') + print("creating script for entry point", dist, group, name) + with open(script_path, 'w') as fh: + print("import", ep.module_name, file=fh) + print("%s.%s()" % (ep.module_name, '.'.join(ep.attrs)), file=fh) + for package in packages: + print("import", package, file=fh) + + return Analysis( + [script_path] + kwargs.get('scripts', []), + **kwargs + ) + +gui_a = Entrypoint('laps4linux_client', 'gui_scripts', 'laps-gui', + pathex=['.'], + binaries=[], + datas=[ ('../assets/laps.png', '.') ], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + cipher=block_cipher, + noarchive=False, + optimize=0, +) +cli_a = Entrypoint('laps4linux_client', 'console_scripts', 'laps-cli', + pathex=['.'], + binaries=[], + datas=[ ('../assets/laps.png', '.') ], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + cipher=block_cipher, + noarchive=False, + optimize=0, +) +MERGE( (gui_a, 'laps-gui', 'laps-gui'), (cli_a, 'laps-cli', 'laps-cli') ) + +gui_pyz = PYZ(gui_a.pure, gui_a.zipped_data, cipher=block_cipher) +gui_exe = EXE(gui_pyz, gui_a.scripts, [], + exclude_binaries=True, + name='laps-gui', + contents_directory='.', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) + +cli_pyz = PYZ(cli_a.pure, cli_a.zipped_data, cipher=block_cipher) +cli_exe = EXE(cli_pyz, cli_a.scripts, [], + exclude_binaries=True, + name='laps-cli', + contents_directory='.', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) + +coll = COLLECT( + gui_exe, gui_a.binaries, gui_a.zipfiles, gui_a.datas, + cli_exe, cli_a.binaries, cli_a.zipfiles, cli_a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='laps-client' +) diff --git a/laps-runner/laps-runner.linux.spec b/laps-runner/laps-runner.linux.spec new file mode 100644 index 0000000..0730941 --- /dev/null +++ b/laps-runner/laps-runner.linux.spec @@ -0,0 +1,74 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + +def Entrypoint(dist, group, name, **kwargs): + import pkg_resources + + # get toplevel packages of distribution from metadata + def get_toplevel(dist): + distribution = pkg_resources.get_distribution(dist) + if distribution.has_metadata('top_level.txt'): + return list(distribution.get_metadata('top_level.txt').split()) + else: + return [] + + kwargs.setdefault('hiddenimports', []) + packages = [] + for distribution in kwargs['hiddenimports']: + packages += get_toplevel(distribution) + + kwargs.setdefault('pathex', []) + # get the entry point + ep = pkg_resources.get_entry_info(dist, group, name) + # insert path of the egg at the verify front of the search path + kwargs['pathex'] = [ep.dist.location] + kwargs['pathex'] + # script name must not be a valid module name to avoid name clashes on import + script_path = os.path.join(workpath, name + '-script.py') + print("creating script for entry point", dist, group, name) + with open(script_path, 'w') as fh: + print("import", ep.module_name, file=fh) + print("%s.%s()" % (ep.module_name, '.'.join(ep.attrs)), file=fh) + for package in packages: + print("import", package, file=fh) + + return Analysis( + [script_path] + kwargs.get('scripts', []), + **kwargs + ) + +a = Entrypoint('laps4linux_runner', 'console_scripts', 'laps-runner', + pathex=['.'], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + cipher=block_cipher, + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE(pyz, a.scripts, [], + exclude_binaries=True, + name='laps-runner', + contents_directory='.', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +coll = COLLECT(exe, a.binaries, a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='laps-runner', +)