11# -*- mode: python ; coding: utf-8 -*-
22
3+ import pkgutil
34import os
45import sys
56from PyInstaller .building .build_main import Analysis , PYZ , EXE , COLLECT , BUNDLE , TOC
67import PyInstaller .utils .hooks
8+ import pkg_resources
9+ import importlib .metadata
10+ import alphatims
711
812
913##################### User definitions
1014exe_name = 'alphatims_gui'
1115script_name = 'alphatims_pyinstaller.py'
1216if sys .platform [:6 ] == "darwin" :
13- icon = '../logos/ alpha_logo.icns'
17+ icon = '../alpha_logo.icns'
1418else :
15- icon = '../logos/ alpha_logo.ico'
19+ icon = '../alpha_logo.ico'
1620block_cipher = None
1721location = os .getcwd ()
1822project = "alphatims"
19- bundle_name = "alphatims"
23+ remove_tests = True
24+ bundle_name = "AlphaTims"
2025#####################
2126
2227
23- datas , binaries , hidden_imports = PyInstaller .utils .hooks .collect_all (
24- project ,
25- include_py_files = True
26- )
28+ requirements = {
29+ req .split ()[0 ] for req in importlib .metadata .requires (project )
30+ }
31+ requirements .add (project )
32+ requirements .add ("distributed" )
33+ hidden_imports = set ()
34+ datas = []
35+ binaries = []
36+ checked = set ()
37+ while requirements :
38+ requirement = requirements .pop ()
39+ checked .add (requirement )
40+ if requirement in ["pywin32" ]:
41+ continue
42+ try :
43+ module_version = importlib .metadata .version (requirement )
44+ except (
45+ importlib .metadata .PackageNotFoundError ,
46+ ModuleNotFoundError ,
47+ ImportError
48+ ):
49+ continue
50+ try :
51+ datas_ , binaries_ , hidden_imports_ = PyInstaller .utils .hooks .collect_all (
52+ requirement ,
53+ include_py_files = True
54+ )
55+ except ImportError :
56+ continue
57+ datas += datas_
58+ # binaries += binaries_
59+ hidden_imports_ = set (hidden_imports_ )
60+ if "" in hidden_imports_ :
61+ hidden_imports_ .remove ("" )
62+ if None in hidden_imports_ :
63+ hidden_imports_ .remove (None )
64+ requirements |= hidden_imports_ - checked
65+ hidden_imports |= hidden_imports_
66+
67+ if remove_tests :
68+ hidden_imports = sorted (
69+ [h for h in hidden_imports if "tests" not in h .split ("." )]
70+ )
71+ else :
72+ hidden_imports = sorted (hidden_imports )
2773
28- # add extra packages that don't have pyinstaller hooks
29- # extra_pkgs = ["alphabase", ] # other alphaX packages would be added here
30- # for pkg in extra_pkgs:
31- # _datas, _binaries, _hidden_imports = PyInstaller.utils.hooks.collect_all(
32- # pkg,
33- # include_py_files=True
34- # )
35- # datas+=_datas
36- # binaries+=_binaries
37- # hidden_imports+=_hidden_imports
3874
39- # prepare hidden imports and datas
4075hidden_imports = [h for h in hidden_imports if "__pycache__" not in h ]
41- # hidden_imports = sorted(
42- # [h for h in hidden_imports if "tests" not in h.split(".")]
43- # )
4476datas = [d for d in datas if ("__pycache__" not in d [0 ]) and (d [1 ] not in ["." , "Resources" , "scripts" ])]
4577
78+ # if sys.platform[:5] == "win32":
79+ # base_path = os.path.dirname(sys.executable)
80+ # library_path = os.path.join(base_path, "Library", "bin")
81+ # dll_path = os.path.join(base_path, "DLLs")
82+ # libcrypto_dll_path = os.path.join(dll_path, "libcrypto-1_1-x64.dll")
83+ # libssl_dll_path = os.path.join(dll_path, "libssl-1_1-x64.dll")
84+ # libcrypto_lib_path = os.path.join(library_path, "libcrypto-1_1-x64.dll")
85+ # libssl_lib_path = os.path.join(library_path, "libssl-1_1-x64.dll")
86+ # if not os.path.exists(libcrypto_dll_path):
87+ # datas.append((libcrypto_lib_path, "."))
88+ # if not os.path.exists(libssl_dll_path):
89+ # datas.append((libssl_lib_path, "."))
90+
4691a = Analysis (
4792 [script_name ],
4893 pathex = [location ],
@@ -51,7 +96,7 @@ a = Analysis(
5196 hiddenimports = hidden_imports ,
5297 hookspath = [],
5398 runtime_hooks = [],
54- excludes = [],
99+ excludes = [h for h in hidden_imports if "datashader" in h ],
55100 win_no_prefer_redirects = False ,
56101 win_private_assemblies = False ,
57102 cipher = block_cipher ,
@@ -79,7 +124,7 @@ if sys.platform[:5] == "linux":
79124 upx_exclude = [],
80125 icon = icon
81126 )
82- else : # non-linux
127+ else :
83128 exe = EXE (
84129 pyz ,
85130 a .scripts ,
@@ -104,4 +149,4 @@ else: # non-linux
104149 upx = True ,
105150 upx_exclude = [],
106151 name = exe_name
107- )
152+ )
0 commit comments