-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrelease.py
More file actions
275 lines (239 loc) · 8.22 KB
/
release.py
File metadata and controls
275 lines (239 loc) · 8.22 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"""
Copyright (c) 2017, Jairus Martin.
Distributed under the terms of the GPL v3 License.
The full license is in the file COPYING.txt, distributed with this software.
Created on Dec 5, 2017
@author
"""
import importlib
import os
import sys
from glob import glob
from os.path import dirname
from pathlib import Path
import enaml
from cx_Freeze import Executable, hooks, setup
from cx_Freeze.hooks.qthooks import (
IS_WINDOWS,
QtHook,
_get_qt_files,
_qt_implementation,
)
import declaracad
def patch_cx_freeze():
# Patch to fix all libs getting placed in the PySide6 folder
if IS_WINDOWS:
return
from cx_Freeze.command.bdist_appimage import bdist_appimage
original_save_as_file = bdist_appimage.save_as_file
def save_as_file_patched(self, data, outfile, mode="r"):
# Patch AppRun to use the embedded font config.
# Otherwise it tries to use a path in the build hosts conda env
# which does not exist at runtime (unless built locally)
if outfile.endswith("AppRun"):
lines = data.split("\n")
lines.insert(
len(lines) - 2,
'export FONTCONFIG_FILE="${FONTCONFIG_FILE:-$APPDIR/etc/fonts/fonts.conf}"',
)
lines.insert(
len(lines) - 2,
'export FONTCONFIG_PATH="${FONTCONFIG_PATH:-$APPDIR/etc/fonts/}"',
)
data = "\n".join(lines)
print("Patched AppRun")
print(data)
original_save_as_file(self, data, outfile, mode)
bdist_appimage.save_as_file = save_as_file_patched
def qt_qtcore_patched(self, finder, module) -> None:
"""Include plugins for the module."""
name = _qt_implementation(module)
for source, target in _get_qt_files(name, "LibrariesPath", "libQt*.so*"):
finder.lib_files.setdefault(source, target.as_posix())
QtHook.qt_qtcore = qt_qtcore_patched
def load_declaracad(finder, module):
import OCCT
root = dirname(dirname(dirname(OCCT.__path__[0])))
if sys.platform == "win32":
root = os.path.join(root, "Library", "lib")
if sys.platform == "win32":
patterns = ["*.lib"]
elif sys.platform == "darwin":
patterns = ["*.dylib"]
else:
patterns = ["*.so*"]
# Keep all libraries in venv/lib
for pattern in patterns:
for source in Path(root).glob(pattern):
target = f"lib/{source.name}"
finder.lib_files.setdefault(source, target)
finder.include_module("declaracad")
# Normal import does not work
hooks.load_declaracad = load_declaracad
def find_enaml_files(*modules):
"""Find .enaml files to include in the zip"""
files = {}
for name in modules:
mod = importlib.import_module(name)
mod_path = dirname(mod.__file__)
pkg_root = dirname(mod_path)
for file_type in ["enaml", "png"]:
for f in glob("{}/**/*.{}".format(mod_path, file_type), recursive=True):
pkg = f.replace(pkg_root + os.path.sep, "")
files[f] = pkg
return files.items()
def find_data_files(*modules):
files = {}
for name in modules:
mod_path = name
pkg_root = name
for f in glob("{}/**/*.png".format(mod_path), recursive=True):
pkg = f.replace(pkg_root + os.path.sep, "")
files[f] = pkg
return files.items()
def find_fonts() -> list[tuple[str, str]]:
# Include font config on linux
if IS_WINDOWS or "CONDA_PREFIX" not in os.environ:
return []
etc_dir = os.path.join(os.environ["CONDA_PREFIX"], "etc")
return [(os.path.join(etc_dir, "fonts"), "etc/fonts")]
def find_bin_excludes():
# Exclude QtQuick and QtQml libs
if IS_WINDOWS or "CONDA_PREFIX" not in os.environ:
return []
lib_dir = os.path.join(os.environ["CONDA_PREFIX"], "lib")
bin_excludes = []
for pattern in ("libQt6Qml*.so*", "libQt6Quick*.so*"):
for source in Path(lib_dir).glob(pattern):
bin_excludes.append(source.name)
return bin_excludes
patch_cx_freeze()
with enaml.imports():
setup(
name="declaracad",
author="CodeLV",
author_email="frmdstryr@gmail.com",
license="GPLv3",
url="https://github.com/codelv/declaracad/",
description="A declarative parametric 3D modeling application",
long_description=open("README.md").read(),
version=declaracad.version,
options=dict(
build_exe=dict(
packages=[
"declaracad",
"enaml",
"enamlx",
"parso",
"jedi", # Needed outsize of zip for autocomplete to work
"markdown",
"html.parser",
"pygments",
"ipykernel",
"zmq.utils.garbage", # Needed for embedded qt console
],
include_files=find_fonts(),
zip_include_packages=[
"asttokens",
"asyncqtpy",
"asyncio",
"attr",
"backcall",
"bytecode",
"curses",
"chardet",
"collections",
"concurrent",
"ctypes",
"colorama",
"comm",
"dateutil",
"distutils",
"docutils",
"email",
"executing",
"encodings",
"ezdxf",
"http",
"html",
"fontTools",
"IPython",
"ipython_genutils",
"ipykernel",
"importlib",
"importlib_metadata",
"json",
"jsonpickle",
"jupyter_client",
"jupyter_core",
"jinja2",
"logging",
"numpydoc",
"multiprocessing",
"markdown",
"pathlib",
"pdf4py",
"pygments",
"pluggy",
"prompt_toolkit",
"packaging",
"pytz",
"pydoc_data",
"pycparser",
"ptyprocess",
"pkg_resources",
"platformdirs",
"pyparsing",
"qtpy",
"qtconsole",
"re",
"sqlite3",
"serial",
"scipy",
"stack_data",
"sysconfig",
"traitlets",
"tornado",
"toml",
"test",
"tomlib",
"unittest",
"urllib",
"wcwidth",
"zipfile",
"xml",
"_distutils_hack",
],
zip_includes=find_enaml_files("enaml"),
excludes=[
"alabaster",
"babel",
"debugpy",
"enamlx.qt.qt_occ_viewer",
"lib2to3",
"matplotlib",
"matplotlib_inline",
"pytest",
"_pytest",
"sphinx",
"tkinter",
"vtkmodules",
"wheel",
"wx",
"xmlrpc",
"zmq.eventloop.minitornado",
],
bin_excludes=find_bin_excludes(),
)
),
executables=[
Executable(
"main.py",
base="gui",
icon="declaracad/res/icons/logo." + ("ico" if IS_WINDOWS else "png"),
target_name="declaracad",
shortcut_name="DeclaraCAD" if IS_WINDOWS else None,
shortcut_dir="DesktopFolder" if IS_WINDOWS else None,
)
],
)