-
Notifications
You must be signed in to change notification settings - Fork 4
/
freeze.py
121 lines (98 loc) · 3.87 KB
/
freeze.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import glob
import os
import shutil
import sys
import setupdata as sd
from guidata import disthelpers as dh
def copytree(src, dst, symlinks=False, ignore=None):
if not os.path.exists(dst):
os.makedirs(dst)
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
copytree(s, d, symlinks, ignore)
else:
if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
shutil.copy2(s, d)
dest = "./dist/"
name = sd.name
version = sd.version
license = sd.license
description = sd.description
author = sd.author
author_email = sd.author_email
url = sd.url
start_file = './src/rrpamwds.pyw'
icon = "./src/rrpam_wds/gui/images/main_logo.ico"
if (len(sys.argv) > 1 and str.lower(sys.argv[1]) == "debug"):
start_file = './src/rrpamwds.py'
sys.argv.pop()
print("tragetting start file %s" % (start_file))
qtlibloc = None
qtlibloc = os.environ.get('QT_QPA_PLATFORM_PLUGIN_PATH', None)
if (not qtlibloc):
p = os.path.join(sys.exec_prefix, "Library", "plugins", "platforms")
print("I did not find QT_QPA_PLATFORM_PLUGIN_PATH set. So, trying usual place %s ..." % (p))
if (os.path.isdir(p)):
qtlibloc = p
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = qtlibloc
print("Set QT_QPA_PLATFORM_PLUGIN_PATH=%s" % (p))
else:
p = os.path.join(sys.exec_prefix, "plugins", "platforms")
if (os.path.isdir(p)):
qtlibloc = p
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = qtlibloc
print("Set QT_QPA_PLATFORM_PLUGIN_PATH=%s" % (p))
else:
print("I can not find it!")
if (not qtlibloc):
print(
" Need to define environmental variable QT_QPA_PLATFORM_PLUGIN_PATH pointing to qt dll files. ")
raise Exception
sys.modules["PyQt4"] = None # block loading PyQt4 to avoid conflicts with PyQt5!
dist = dh.Distribution()
dist.setup(name, version, description, start_file, includes=[], icon=icon)
# dist.add_modules('PyQt5', 'guidata', 'guiqwt', 'matplotlib')
dist.add_modules('PyQt5', 'guidata', 'guiqwt')
dist.build_cx_freeze() # use `build_py2exe` to use py2exe instead
src_files = os.listdir(qtlibloc)
for file_name in src_files:
full_file_name = os.path.join(qtlibloc, file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, dest)
print("Copied: %s to ./dist/." % (full_file_name))
with open("./service/rrpamwds_setup.iss_", mode='r') as script:
text = script.read()
text = text.format(name=name, version=version, url=url, rootlocation=os.getcwd() + os.sep)
with open("./service/rrpamwds_setup.iss", mode='w') as sc:
sc.write(text)
def copy_necessary_files(sys, os, glob, dest, shutil):
# copy the needed dll files and libraries that cx_free misses
l = os.path.dirname(sys.executable)
loc = os.path.join(l, "Library", "bin")
if (os.path.isdir(loc)):
for file in glob.glob(os.path.join(loc, "mkl_core.dll")):
print("Copying mkl library %s" % (file))
shutil.copy(file, dest)
# for file in glob.glob(os.path.join(loc, "libiomp5md.dll")):
# print("Copying library %s" % (file))
# shutil.copy(file, dest)
#
loc = os.path.join(l, "Lib", "site-packages", "numpy")
dst = os.path.join(dest, "numpy")
if (os.path.isdir(loc)):
print("Copying %s" % (loc))
copytree(loc, dst)
else:
print("can not find %s " % loc)
# loc = os.path.join(l, "Lib", "email")
# dst = os.path.join(dest, "email")
# if ((not os.path.isdir(dst)) and os.path.isdir(loc)):
# print("Copying %s" % (loc))
# copytree(loc, dst)
# loc = os.path.join(l, "Lib", "uu.py")
# if (os.path.isfile(loc)):
# print("Copying %s" % (loc))
# shutil.copy(loc, dest)
copy_necessary_files(sys, os, glob, dest, shutil)