99
1010@author
1111"""
12+
13+ import importlib
1214import os
1315import sys
16+ from glob import glob
17+ from os .path import dirname
18+ from pathlib import Path
19+
1420import enaml
15- import importlib
21+ from cx_Freeze import Executable , hooks , setup
22+ from cx_Freeze .hooks .qthooks import (
23+ IS_WINDOWS ,
24+ QtHook ,
25+ _get_qt_files ,
26+ _qt_implementation ,
27+ )
28+
1629import declaracad
17- import shutil
18- from pathlib import Path
19- from glob import glob
20- from os .path import dirname , split , exists
21- from cx_Freeze import hooks , setup , Executable
30+
31+
32+ def patch_cx_freeze ():
33+ # Patch to fix all libs getting placed in the PySide6 folder
34+ if IS_WINDOWS :
35+ return
36+
37+ def qt_qtcore_patched (self , finder , module ) -> None :
38+ """Include plugins for the module."""
39+ name = _qt_implementation (module )
40+ for source , target in _get_qt_files (name , "LibrariesPath" , "libQt*.so*" ):
41+ finder .lib_files .setdefault (source , target .as_posix ())
42+
43+ QtHook .qt_qtcore = qt_qtcore_patched
2244
2345
2446def load_declaracad (finder , module ):
2547 import OCCT
2648
2749 root = dirname (dirname (dirname (OCCT .__path__ [0 ])))
28- if sys .platform == ' win32' :
29- root = os .path .join (root , ' Library' , ' lib' )
50+ if sys .platform == " win32" :
51+ root = os .path .join (root , " Library" , " lib" )
3052
31- if sys .platform == ' win32' :
32- patterns = [' *.lib' ]
33- elif sys .platform == ' darwin' :
34- patterns = [' *.dylib' ]
53+ if sys .platform == " win32" :
54+ patterns = [" *.lib" ]
55+ elif sys .platform == " darwin" :
56+ patterns = [" *.dylib" ]
3557 else :
36- patterns = [' *.so*' ]
58+ patterns = [" *.so*" ]
3759
3860 # Keep all libraries in venv/lib
3961 for pattern in patterns :
@@ -42,22 +64,22 @@ def load_declaracad(finder, module):
4264 finder .lib_files .setdefault (source , target )
4365 finder .include_module ("declaracad" )
4466
67+
4568# Normal import does not work
4669hooks .load_declaracad = load_declaracad
4770
4871
4972def find_enaml_files (* modules ):
50- """ Find .enaml files to include in the zip """
73+ """Find .enaml files to include in the zip"""
5174 files = {}
5275 for name in modules :
5376 mod = importlib .import_module (name )
5477 mod_path = dirname (mod .__file__ )
5578 pkg_root = dirname (mod_path )
5679
57- for file_type in ['enaml' , 'png' ]:
58- for f in glob ('{}/**/*.{}' .format (mod_path , file_type ),
59- recursive = True ):
60- pkg = f .replace (pkg_root + os .path .sep , '' )
80+ for file_type in ["enaml" , "png" ]:
81+ for f in glob ("{}/**/*.{}" .format (mod_path , file_type ), recursive = True ):
82+ pkg = f .replace (pkg_root + os .path .sep , "" )
6183 files [f ] = pkg
6284
6385 return files .items ()
@@ -66,103 +88,149 @@ def find_enaml_files(*modules):
6688def find_data_files (* modules ):
6789 files = {}
6890 for name in modules :
69- mod = importlib .import_module (name )
7091 mod_path = name
7192 pkg_root = name
7293
73- for f in glob (' {}/**/*.png' .format (mod_path ), recursive = True ):
74- pkg = f .replace (pkg_root + os .path .sep , '' )
94+ for f in glob (" {}/**/*.png" .format (mod_path ), recursive = True ):
95+ pkg = f .replace (pkg_root + os .path .sep , "" )
7596 files [f ] = pkg
7697 return files .items ()
7798
7899
79- is_windows = sys .platform == 'win32'
100+ def find_fonts () -> list [tuple [str , str ]]:
101+ # Include font config on linux
102+ if IS_WINDOWS or "CONDA_PREFIX" not in os .environ :
103+ return []
104+ etc_dir = os .path .join (os .environ ["CONDA_PREFIX" ], "etc" )
105+ return [(os .path .join (etc_dir , "fonts" ), "etc/fonts" )]
106+
80107
108+ patch_cx_freeze ()
81109with enaml .imports ():
82110 setup (
83- name = ' declaracad' ,
111+ name = " declaracad" ,
84112 author = "CodeLV" ,
85113 author_email = "frmdstryr@gmail.com" ,
86- license = ' GPLv3' ,
87- url = ' https://github.com/codelv/declaracad/' ,
114+ license = " GPLv3" ,
115+ url = " https://github.com/codelv/declaracad/" ,
88116 description = "A declarative parametric 3D modeling application" ,
89117 long_description = open ("README.md" ).read (),
90118 version = declaracad .version ,
91119 options = dict (
92120 build_exe = dict (
93121 packages = [
94- 'declaracad' ,
95- 'enaml' ,
96- 'enamlx' ,
97- "parso" , "jedi" , # Needed outsize of zip for autocomplete to work
98- 'markdown' ,
99- 'html.parser' ,
100- 'pygments' ,
101- 'ipykernel' ,
102- 'zmq.utils.garbage' , # Needed for embedded qt console
122+ "declaracad" ,
123+ "enaml" ,
124+ "enamlx" ,
125+ "parso" ,
126+ "jedi" , # Needed outsize of zip for autocomplete to work
127+ "markdown" ,
128+ "html.parser" ,
129+ "pygments" ,
130+ "ipykernel" ,
131+ "zmq.utils.garbage" , # Needed for embedded qt console
103132 ],
133+ include_files = find_fonts (),
104134 zip_include_packages = [
105- 'asttokens' ,
106- 'asyncqtpy' ,
107- 'asyncio' ,
108- 'attr' ,
109- 'backcall' ,
110- 'bytecode' ,
111- 'curses' , 'chardet' , 'collections' , 'concurrent' , 'ctypes' ,
112- 'colorama' , 'comm' ,
113- 'dateutil' , 'distutils' , 'docutils' ,
114- 'email' ,
115- 'executing' ,
116- 'encodings' ,
117- 'ezdxf' ,
118- 'http' , 'html' , 'fontTools' ,
119- 'IPython' , 'ipython_genutils' , 'ipykernel' ,
120- 'importlib' , 'importlib_metadata' ,
121- 'json' , 'jsonpickle' , 'jupyter_client' , 'jupyter_core' ,
122- 'jinja2' ,
123- 'logging' ,
124- 'numpydoc' ,
125- 'multiprocessing' , 'markdown' ,
126- 'pathlib' , 'pdf4py' , 'pygments' , 'pluggy' , 'prompt_toolkit' , 'packaging' ,
127- 'pytz' , 'pydoc_data' , 'pycparser' , 'ptyprocess' , 'pkg_resources' , 'platformdirs' ,
128- 'pyparsing' ,
129- 'qtpy' , 'qtconsole' ,
130- 're' ,
131- 'sqlite3' , 'sphinx' , 'serial' , 'scipy' , 'stack_data' , 'sysconfig' ,
132- 'traitlets' , 'tornado' , 'toml' , 'test' , 'tomlib' ,
133- 'unittest' , 'urllib' ,
134- 'wcwidth' ,
135- 'zipfile' ,
136- 'xml' , 'xmlrpc' ,
137- '_distutils_hack' ,
135+ "asttokens" ,
136+ "asyncqtpy" ,
137+ "asyncio" ,
138+ "attr" ,
139+ "backcall" ,
140+ "bytecode" ,
141+ "curses" ,
142+ "chardet" ,
143+ "collections" ,
144+ "concurrent" ,
145+ "ctypes" ,
146+ "colorama" ,
147+ "comm" ,
148+ "dateutil" ,
149+ "distutils" ,
150+ "docutils" ,
151+ "email" ,
152+ "executing" ,
153+ "encodings" ,
154+ "ezdxf" ,
155+ "http" ,
156+ "html" ,
157+ "fontTools" ,
158+ "IPython" ,
159+ "ipython_genutils" ,
160+ "ipykernel" ,
161+ "importlib" ,
162+ "importlib_metadata" ,
163+ "json" ,
164+ "jsonpickle" ,
165+ "jupyter_client" ,
166+ "jupyter_core" ,
167+ "jinja2" ,
168+ "logging" ,
169+ "numpydoc" ,
170+ "multiprocessing" ,
171+ "markdown" ,
172+ "pathlib" ,
173+ "pdf4py" ,
174+ "pygments" ,
175+ "pluggy" ,
176+ "prompt_toolkit" ,
177+ "packaging" ,
178+ "pytz" ,
179+ "pydoc_data" ,
180+ "pycparser" ,
181+ "ptyprocess" ,
182+ "pkg_resources" ,
183+ "platformdirs" ,
184+ "pyparsing" ,
185+ "qtpy" ,
186+ "qtconsole" ,
187+ "re" ,
188+ "sqlite3" ,
189+ "sphinx" ,
190+ "serial" ,
191+ "scipy" ,
192+ "stack_data" ,
193+ "sysconfig" ,
194+ "traitlets" ,
195+ "tornado" ,
196+ "toml" ,
197+ "test" ,
198+ "tomlib" ,
199+ "unittest" ,
200+ "urllib" ,
201+ "wcwidth" ,
202+ "zipfile" ,
203+ "xml" ,
204+ "xmlrpc" ,
205+ "_distutils_hack" ,
138206 ],
139- zip_includes = find_enaml_files (' enaml' ),
207+ zip_includes = find_enaml_files (" enaml" ),
140208 excludes = [
141- ' alabaster' ,
142- ' babel' ,
143- 'wx' ,
144- ' tkinter' ,
145- ' matplotlib' , 'matplotlib_inline' ,
146- 'lib2to3' ,
147- 'enamlx.qt.qt_occ_viewer' ,
148- 'zmq.eventloop.minitornado' ,
149- 'sphinx' ,
150- 'vtkmodules' ,
151- 'wheel'
152- ' debugpy' ,
209+ " alabaster" ,
210+ " babel" ,
211+ "wx" ,
212+ " tkinter" ,
213+ " matplotlib" ,
214+ "matplotlib_inline" ,
215+ "lib2to3" ,
216+ "enamlx.qt.qt_occ_viewer" ,
217+ "zmq.eventloop.minitornado" ,
218+ "sphinx" ,
219+ "vtkmodules" ,
220+ "wheel" " debugpy" ,
153221 ],
154222 )
155223 ),
156224 executables = [
157225 Executable (
158- ' main.py' ,
226+ " main.py" ,
159227 base = "gui" ,
160- icon = ' declaracad/res/icons/logo.' + (' ico' if is_windows else ' png' ),
161- target_name = ' declaracad' ,
162- shortcut_name = "DeclaraCAD" if is_windows else None ,
163- shortcut_dir = "DesktopFolder" if is_windows else None ,
228+ icon = " declaracad/res/icons/logo." + (" ico" if IS_WINDOWS else " png" ),
229+ target_name = " declaracad" ,
230+ shortcut_name = "DeclaraCAD" if IS_WINDOWS else None ,
231+ shortcut_dir = "DesktopFolder" if IS_WINDOWS else None ,
164232 # stdout doesn't
165233 # base='Win32GUI' is_windows else None
166234 )
167- ]
235+ ],
168236 )
0 commit comments