From 4271b4430a04b98aeca1edf1cd6cb967327ab2c8 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Wed, 15 Nov 2017 22:06:53 -0500 Subject: [PATCH] Add pyinstaller bundle support Will allow creating generating pre-made builds for windows that do not require python to be already installed. --- EntranceRandomizer.py | 8 ++++++++ bundle/EntranceRandomizer.spec | 33 +++++++++++++++++++++++++++++++++ bundle/_rt_hook.py | 4 ++++ 3 files changed, 45 insertions(+) create mode 100644 bundle/EntranceRandomizer.spec create mode 100644 bundle/_rt_hook.py diff --git a/EntranceRandomizer.py b/EntranceRandomizer.py index 2a6f7193..80b7e213 100644 --- a/EntranceRandomizer.py +++ b/EntranceRandomizer.py @@ -190,6 +190,14 @@ if __name__ == '__main__': ''') args = parser.parse_args() + if hasattr(sys, 'frozen') and len(sys.argv) == 1 : + # for the Precompiled windows build, if we have no arguments, the user + # probably wants the gui. Users of the windows build who want the command line + # interface shouuld specify at least one option, possibly setting a value to a + # default if they like all the defaults + guiMain() + sys.exit(0) + # ToDo: Validate files further than mere existance if not args.jsonout and not os.path.isfile(args.rom): input('Could not find valid base rom for patching at expected path %s. Please run with -h to see help for further information. \nPress Enter to exit.' % args.rom) diff --git a/bundle/EntranceRandomizer.spec b/bundle/EntranceRandomizer.spec new file mode 100644 index 00000000..975255e6 --- /dev/null +++ b/bundle/EntranceRandomizer.spec @@ -0,0 +1,33 @@ +# -*- mode: python -*- + +block_cipher = None + + +a = Analysis(['..\\EntranceRandomizer.py'], + pathex=['bundle'], + binaries=[], + datas=[('../data/', 'data/'), ('../README.html', '.'), ('../LICENSE.txt', '.')], + hiddenimports=[], + hookspath=[], + runtime_hooks=['bundle/_rt_hook.py'], + excludes=['lzma', 'bz2'], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + exclude_binaries=True, + name='EntranceRandomizer', + debug=False, + strip=False, + upx=False, + console=True ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=False, + name='EntranceRandomizer') diff --git a/bundle/_rt_hook.py b/bundle/_rt_hook.py new file mode 100644 index 00000000..17ea446b --- /dev/null +++ b/bundle/_rt_hook.py @@ -0,0 +1,4 @@ +import sys +import os + +sys.path.append(os.path.join(sys._MEIPASS, "ext"))