From 64e1a717fb5ef07302da9d94d87c27ad2a810b41 Mon Sep 17 00:00:00 2001 From: bwoodsend Date: Mon, 14 Sep 2020 22:37:37 +0100 Subject: [PATCH] Hooks: numpy: Add filter for valid binaries. --- PyInstaller/hooks/hook-numpy.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/PyInstaller/hooks/hook-numpy.py b/PyInstaller/hooks/hook-numpy.py index 214361ecf51..f60593c7656 100644 --- a/PyInstaller/hooks/hook-numpy.py +++ b/PyInstaller/hooks/hook-numpy.py @@ -147,3 +147,23 @@ def _is_required(name): # from PyInstaller.utils.hooks import collect_submodules # is_tests = lambda x: "tests" in x.split(".") # excludedimports += collect_submodules("numpy", filter=is_tests) + + +# --- Remove binaries that aren't DLLs --- + + +import ctypes + +def _is_valid(source, dest): + # There really should be a less brute-force way of doing this. + if source.endswith(".pdb"): + # Attempting to load a pdb causes a pop-up window. Check for and exclude + # them here. + return False + try: + ctypes.CDLL(source) + return True + except OSError: + return False + +binaries = [i for i in binaries if _is_valid(*i)]