forked from jnettels/trnpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_exe.py
256 lines (223 loc) · 10.4 KB
/
setup_exe.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
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
# Copyright (C) 2020 Joris Zimmermann
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.
"""TRNpy: Parallelized TRNSYS simulation with Python.
TRNpy: Parallelized TRNSYS simulation with Python
=================================================
Simulate TRNSYS deck files in serial or parallel and use parametric tables to
perform simulations for different sets of parameters. TRNpy helps to automate
these and similar operations by providing functions to manipulate deck files
and run TRNSYS simulations from a programmatic level.
Module Setup
------------
This module defines the setup script for the TRNpy project.
Run with the following command prompt to create a Windows executable:
.. code::
python setup_exe.py build
To create a standalone installer:
.. code::
python setup_exe.py bdist_msi
Lots of modules are excluded from the build and some unnecessary folders are
removed from the resulting folder. This can cause the program to fail, but
also dramatically decreases the folder size.
**Troubleshooting**
* ``Module X is missing``
* Remove the module from the ``excludes`` list
* ``Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll``
* Make sure the following files are in a folder with the trnpy.exe, they can
be found at e.g. C:/Users/nettelstroth/Anaconda3/Library/bin
* libiomp5md.dll
* mkl_core.dll
* mkl_def.dll
* mkl_intel_thread.dll
"""
from setuptools_scm import get_version
from cx_Freeze import setup, Executable
import os
import shutil
import sys
try:
version = get_version(version_scheme='post-release')
except LookupError:
version = '0.0.0.0'
print('Warning: setuptools-scm requires an intact git repository to detect'
' the version number for this build.')
if 'g' in version: # 'Dirty' version, does not fit to Windows' version scheme
version_list = []
for i in version.split('.'):
try: # Sort out all parts of the version name that are not integers
version_list.append(str(int(i)))
except Exception:
pass
if len(version_list) < 3: # Version is X.Y -> make it X.Y.0.1
version_list.append('0.1') # Use this to mark as a dev build
elif len(version_list) < 4: # Windows version has a maximum length
version_list.append('1') # Use this to mark as a dev build
version = '.'.join(version_list)
print('Building TRNpy with version tag: ' + version)
# These settings solved an error (set to folders in python directory)
os.environ['TCL_LIBRARY'] = os.path.join(sys.exec_prefix, r'tcl\tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(sys.exec_prefix, r'tcl\tk8.6')
mkl_dlls = os.path.join(sys.exec_prefix, r'Library\bin')
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa371847(v=vs.85).aspx
shortcut_table = [
("DesktopShortcut", # Shortcut
"DesktopFolder", # Directory_
"TRNpy", # Name
"TARGETDIR", # Component_
"[TARGETDIR]TRNpy.exe", # Target
None, # Arguments
'Parallelized TRNSYS simulation with Python', # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
'TARGETDIR' # WkDir
),
("ProgramMenuShortcut", # Shortcut
"ProgramMenuFolder", # Directory_
"TRNpy", # Name
"TARGETDIR", # Component_
"[TARGETDIR]TRNpy.exe", # Target
None, # Arguments
'Parallelized TRNSYS simulation with Python', # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
'TARGETDIR' # WkDir
),
]
author = 'Joris Zimmermann'
description = 'Parallelized TRNSYS simulation with Python'
# The setup function
setup(
name='trnpy',
version=version,
description=description,
long_description=open('README.md').read(),
license='GPL-3.0',
author=author,
author_email='[email protected]',
url='https://github.com/jnettels/trnpy',
# Options for building the Windows .exe
executables=[Executable(r'trnpy/trnpy_script.py',
base=None, # None for cmd-line
icon=r'./res/icon.ico',
targetName='trnpy.exe',
shortcutName="TRNpy",
shortcutDir="ProgramMenuFolder",
)],
options={'build_exe': {'packages': ['numpy', 'asyncio'],
'zip_include_packages': ["*"], # reduze file size
'zip_exclude_packages': [],
'includes': ['pandas._libs.tslibs.base'],
'excludes': ['adodbapi',
'alabaster'
'asn1crypto',
'babel',
'backports',
'bokeh',
'bottleneck',
'bs4',
'certifi',
'cffi',
'chardet',
'cloudpickle',
'colorama',
'concurrent',
'cryptography',
# 'ctypes',
'curses',
'Cython',
'cytoolz',
'dask',
'et_xmlfile',
'h5netcdf',
'h5py',
'html',
'html5lib',
'ipykernel',
'IPython',
'ipython_genutils',
'jedi',
'jinja2',
'jupyter_client',
'jupyter_core',
'lib2to3',
'lxml',
'markupsafe',
'matplotlib',
'matplotlib.tests',
'msgpack',
'nbconvert',
'nbformat',
'netCDF4',
'nose',
'notebook',
'numexpr',
'numpy.random._examples',
'openpyxl',
'OpenSSL',
'PIL',
'pkg_resources',
'prompt_toolkit',
'pycparser',
'pydoc_data',
'pygments',
'PyQt5',
'requests',
'scipy',
'seaborn',
'setuptools',
'sphinx',
'sphinxcontrib',
'sqlalchemy',
'sqlite3',
'tables',
'testpath',
'tornado',
'traitlets',
'wcwidth',
'webencodings',
'win32com',
'zict',
'zmq',
'_pytest',
],
'include_files': [
os.path.join(mkl_dlls, 'libiomp5md.dll'),
os.path.join(mkl_dlls, 'mkl_core.dll'),
os.path.join(mkl_dlls, 'mkl_def.dll'),
os.path.join(mkl_dlls, 'mkl_intel_thread.dll'),
r'./res/icon.png',
]
},
'bdist_msi': {'data': {"Shortcut": shortcut_table},
'summary_data': {'author': author,
'comments': description},
'install_icon': r'./res/icon.ico',
'upgrade_code':
'{0f4794c7-5129-4414-8fd5-b8fff2816e45}',
},
},
)
# Remove some more specific folders:
remove_folders = [
r'.\build\exe.win-amd64-3.7\mpl-data',
r'.\build\exe.win-amd64-3.7\tk\demos',
r'.\build\exe.win-amd64-3.7\tcl\tzdata',
r'.\build\exe.win-amd64-3.7\lib\pandas\tests',
]
for folder in remove_folders:
shutil.rmtree(folder, ignore_errors=True)
# Copy the README.md file to the build folder, changing extension to .txt
shutil.copy2(r'.\README.md', r'.\build\exe.win-amd64-3.7\README.txt')