-
Notifications
You must be signed in to change notification settings - Fork 0
/
the_freezer.py
62 lines (58 loc) · 2.05 KB
/
the_freezer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import PyInstaller.__main__
from flexx.util import freeze
from tempfile import TemporaryDirectory
import os, asyncio, inspect, shutil
def app_main():
# Install hook so we we can import modules from source when frozen.
from flexx.util import freeze
freeze.install()
# Run your app as usual
import flexx as flx
from cpcp import main
main()
return
def create_executable(app_main, *args, exec_name='MyFlexxApp', js_modules=['flexx']):
here = os.path.dirname(os.path.abspath(__file__))
with TemporaryDirectory() as tmp:
tmp_app = '_tmp_app_main.py'
try:
with open(tmp_app, 'w') as f:
f.write(inspect.getsource(app_main))
f.write(f'\n{app_main.__name__}()\n')
for mod in js_modules:
freeze.copy_module(mod, tmp)
tmp_build = os.path.join(tmp, 'build')
tmp_source = os.path.join(tmp, 'source')
PyInstaller.__main__.run([
f'--name={exec_name}', '--onefile', '--windowed', '--clean',
f'--workpath={tmp_build}', '--distpath=.',
f'--add-data={tmp_source}{os.pathsep}source',
*args, tmp_app
])
print(f'FINISHED\n-----\nContents of {exec_name}.spec:')
with open(f'{exec_name}.spec') as f:
print(f.read())
print(f'SUCCESS')
finally:
try: os.remove(tmp_app)
except OSError: pass
try: os.remove(f'{exec_name}.spec')
except OSError: pass
try: shutil.rmtree(f'__pycache__')
except: pass
return
create_executable(
app_main,
'--hidden-import=pkg_resources.py2_warn', # BUG between pyinstaller and setuptools
'--exclude-module=numpy', # Custom numpy exclusion
'--icon=_cpcp/icon.png',
'--add-data=_cpcp/icon.png:_cpcp',
'--add-data=_cpcp/settings.json:_cpcp',
'--add-data=_cpcp/initial_userdir:_cpcp/initial_userdir',
exec_name='CPCP',
js_modules=[
'flexx',
'widgets',
'app',
],
)