From a64cc9a4e72dc8ffc108fab0bdd92854e0d0ccb8 Mon Sep 17 00:00:00 2001 From: Starbuck5 Date: Sat, 29 Aug 2020 20:59:16 -0700 Subject: [PATCH] Internal pyinstaller hook (Fixes #1514) Makes sure that pyinstaller gets all the required libraries when bundling pygame 2 projects into an exe. --- setup.cfg | 4 ++++ setup.py | 6 ++++-- src_py/__pyinstaller/__init__.py | 5 +++++ src_py/__pyinstaller/hook-pygame.py | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src_py/__pyinstaller/__init__.py create mode 100644 src_py/__pyinstaller/hook-pygame.py diff --git a/setup.cfg b/setup.cfg index c8154b9a37..edf6fc3266 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,3 +19,7 @@ commands = [pylint.MESSAGES CONTROL] extension-pkg-whitelist=pygame disable=useless-object-inheritance + +[options.entry_points] +pyinstaller40 = + hook-dirs = pygame.__pyinstaller:get_hook_dirs \ No newline at end of file diff --git a/setup.py b/setup.py index 28c805b2e0..85db5cb533 100644 --- a/setup.py +++ b/setup.py @@ -792,13 +792,15 @@ def run(self): 'pygame.tests.run_tests__tests.timeout', 'pygame.tests.run_tests__tests.everything', 'pygame.docs', - 'pygame.examples'], + 'pygame.examples', + 'pygame.__pyinstaller'], "package_dir": {'pygame': 'src_py', 'pygame._sdl2': 'src_py/_sdl2', 'pygame.threads': 'src_py/threads', 'pygame.tests': 'test', 'pygame.docs': 'docs', - 'pygame.examples': 'examples'}, + 'pygame.examples': 'examples', + 'pygame.__pyinstaller': 'src_py/__pyinstaller'}, "headers": headers, "ext_modules": extensions, "data_files": data_files, diff --git a/src_py/__pyinstaller/__init__.py b/src_py/__pyinstaller/__init__.py new file mode 100644 index 0000000000..1c52aadf4b --- /dev/null +++ b/src_py/__pyinstaller/__init__.py @@ -0,0 +1,5 @@ +import os + + +def get_hook_dirs(): + return [os.path.dirname(__file__)] diff --git a/src_py/__pyinstaller/hook-pygame.py b/src_py/__pyinstaller/hook-pygame.py new file mode 100644 index 0000000000..b934d38dbb --- /dev/null +++ b/src_py/__pyinstaller/hook-pygame.py @@ -0,0 +1,19 @@ +""" +binaries hook for pygame seems to be required for pygame 2.0 Windows. +Otherwise some essential DLLs will not be transfered to the exe. +""" + +import platform + +if platform.system() == "Windows": + + from PyInstaller.utils.hooks import collect_dynamic_libs + + pre_binaries = collect_dynamic_libs('pygame') + binaries = [] + + for b in pre_binaries: + binary, location = b + # settles all the DLLs into the top level folder, which prevents duplication + # with the DLLs already being put there. + binaries.append((binary, "."))