Skip to content

Commit

Permalink
Internal pyinstaller hook (Fixes #1514)
Browse files Browse the repository at this point in the history
Makes sure that pyinstaller gets all the required libraries when bundling pygame 2 projects into an exe.
  • Loading branch information
Starbuck5 committed Aug 30, 2020
1 parent 1476009 commit a64cc9a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions setup.cfg
Expand Up @@ -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
6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src_py/__pyinstaller/__init__.py
@@ -0,0 +1,5 @@
import os


def get_hook_dirs():
return [os.path.dirname(__file__)]
19 changes: 19 additions & 0 deletions 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, "."))

0 comments on commit a64cc9a

Please sign in to comment.