forked from Ultimaker/cura-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_win32.py.in
176 lines (153 loc) · 6.14 KB
/
setup_win32.py.in
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from cx_Freeze import setup, Executable, hooks
import glob
import UM
import UM.Qt
import cura
import os
import sys
import re
import shutil
import site
import Arcus
import scipy
import numpy
import numpy.core
import stl
import stl.mesh
def load_scipy_patched(finder, module):
"""the scipy module loads items within itself in a way that causes
problems without the entire package and a number of other subpackages
being present."""
finder.IncludePackage("scipy._lib") # Changed include from scipy.lib to scipy._lib
finder.IncludePackage("scipy.misc")
hooks.load_scipy = load_scipy_patched
def load_pyqt5_qtquick(finder, module):
finder.IncludeModule("PyQt5.QtCore")
finder.IncludeModule("PyQt5.QtGui")
finder.IncludeModule("PyQt5.QtQml")
finder.IncludeModule("PyQt5.QtNetwork")
finder.IncludeModule("PyQt5._QOpenGLFunctions_2_0")
hooks.load_PyQt5_QtQuick = load_pyqt5_qtquick
# work around the limitation that shutil.copytree does not allow the target directory to exist
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:
shutil.copy2(s, d)
def findSubPackages(root_package_path, package_name):
includes = []
for dirpath, dirnames, filenames in os.walk(os.path.dirname(root_package_path)):
if "__" in dirpath:
continue
if "tests" in dirnames:
dirnames.remove("tests")
module_path = dirpath.replace(os.path.dirname(root_package_path), package_name)
module_path = module_path.split(os.path.sep)
module_name = ".".join(module_path)
if os.path.isfile(dirpath + "/__init__.py"):
includes.append(module_name)
for filename in filenames:
if "__" not in filename and os.path.splitext(filename)[1] in [".py", ".pyd"]:
includes.append(module_name + "." + os.path.splitext(filename)[0])
return includes
includes = [
"sip",
"ctypes",
"uuid",
"UM",
"PyQt5.QtNetwork",
"PyQt5._QOpenGLFunctions_2_0",
"serial",
"Arcus",
"xml.etree",
"xml.etree.ElementTree",
"cura",
"cura.OneAtATimeIterator",
"zeroconf"
]
# Include all the UM modules in the includes. As py2exe fails to properly find all the dependencies due to the plugin architecture.
includes += findSubPackages(UM.__file__, "UM")
includes += findSubPackages(cura.__file__, "cura")
includes += findSubPackages(scipy.__file__, "scipy")
includes += findSubPackages(stl.__file__, "stl")
# Filter out the known bad apples.
includes = [x for x in includes if x not in [
"scipy.interpolate.interpnd_info",
"scipy.misc.pilutil",
"scipy.special.generate_ufuncs",
"scipy.special._testutils",
"scipy.linalg._testutils",
"scipy._lib._testutils"] and "cp35-win_amd64" not in x]
print("Removing previous distribution package")
shutil.rmtree("dist", True)
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable(script="@EXTERNALPROJECT_INSTALL_PREFIX@/bin/cura_app.py",
base="Win32GUI",
targetName = "Cura.exe",
icon="@CMAKE_SOURCE_DIR@/cura.ico"
)
]
setup(
name="Cura",
version="@CURA_MAJOR_VERSION@.@CURA_MINOR_VERSION@.@CURA_PATCH_VERSION@",
author="Ultimaker",
author_email="a.hiemstra@ultimaker.com",
url="http://software.ultimaker.com/",
license="GNU AFFERO GENERAL PUBLIC LICENSE (AGPL)",
scripts=["inst/bin/cura_app.py"],
#console=[{"script": "cura_app.py"}],
options={"build_exe": {"packages": includes, "excludes": ["tkinter"]}},
executables = executables
)
if not os.path.isdir("dist"):
os.mkdir("dist")
build_path = "build\\exe.win-amd64-3.5"
for fname in os.listdir(build_path):
print("Moving " + fname)
shutil.move(os.path.join(build_path, fname), os.path.join("dist", fname))
print("Copying Cura plugins.")
copytree("@EXTERNALPROJECT_INSTALL_PREFIX@/lib/uranium/plugins", "dist/plugins", ignore = shutil.ignore_patterns("OBJWriter", "MLPWriter", "MLPReader"))
copytree("@EXTERNALPROJECT_INSTALL_PREFIX@/lib/cura/plugins", "dist/plugins")
print("Copying resources.")
copytree("@EXTERNALPROJECT_INSTALL_PREFIX@/share/uranium/resources", "dist/resources")
copytree("@EXTERNALPROJECT_INSTALL_PREFIX@/share/cura/resources", "dist/resources")
print("Copying Uranium QML.")
copytree("@EXTERNALPROJECT_INSTALL_PREFIX@/lib/python3.5/site-packages/UM/Qt/qml/UM", "dist/qml/UM")
qt_lib_dir = None
qt_bin_dir = None
if os.path.exists("@EXTERNALPROJECT_INSTALL_PREFIX@/lib/plugins"):
qt_lib_dir = "@EXTERNALPROJECT_INSTALL_PREFIX@/lib"
qt_bin_dir = "@EXTERNALPROJECT_INSTALL_PREFIX@/bin"
else:
import PyQt5.QtCore
qt_lib_dir = os.path.join(os.path.dirname(PyQt5.QtCore.__file__), "Qt")
qt_bin_dir = os.path.join(os.path.dirname(PyQt5.QtCore.__file__), "Qt", "bin")
print("Copying Qt5 plugins")
copytree(os.path.join(qt_lib_dir, "plugins"), "dist/PyQt5/plugins")
print("Copying QtQuick plugins")
copytree(os.path.join(qt_lib_dir, "qml"), "dist/qml")
print("Copying Qt5 svg library")
shutil.copy(os.path.join(qt_bin_dir, "Qt5Svg.dll"), "dist/Qt5Svg.dll")
print("Copying numpy DLLs")
numpy_core_dir = os.path.dirname(numpy.core.__file__)
for item in os.listdir(numpy_core_dir):
if item.endswith(".dll"):
shutil.copy(os.path.join(numpy_core_dir, item), os.path.join("dist", item))
print("Copying CuraEngine")
shutil.copy("@EXTERNALPROJECT_INSTALL_PREFIX@/bin/CuraEngine.exe", "dist/CuraEngine.exe")
shutil.copy("@compiler_dir@/libstdc++-6.dll", "dist/libstdc++-6.dll")
shutil.copy("@compiler_dir@/libwinpthread-1.dll", "dist/libwinpthread-1.dll")
try:
shutil.copy("@compiler_dir@/libgcc_s_seh-1.dll", "dist/libgcc_s_seh-1.dll")
except FileNotFoundError:
shutil.copy("@compiler_dir@/libgcc_s_dw2-1.dll", "dist/libgcc_s_dw2-1.dll")