forked from spine-tools/Spine-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cx_Freeze_setup.py
156 lines (142 loc) · 7.11 KB
/
cx_Freeze_setup.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
######################################################################################################################
# Copyright (C) 2017-2020 Spine project consortium
# This file is part of Spine Toolbox.
# Spine Toolbox is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################
"""
cx-Freeze setup file for Spine Toolbox.
Tested on Python3.6-64bit.
To make a Spine Toolbox installation bundle please follow the next steps:
On Windows:
1. Build the application into build/spinetoolbox directory with command 'python cx_Freeze_setup.py build'
2. Build importer_program into /build/importer_program with command 'python cx_Freeze_importer_program_setup.py build'
3. Copy importer_program manually from directory /build/importer_program to build/spinetoolbox/importer_program
4. Check version numbers and CHANGELOG
5. Compile setup.iss file with Inno Setup. This will create a single-file (.exe) installer.
6. When Spine Toolbox is installed Importer Program is added to importer_program/ directory
On other platforms (not tested):
1. Build the application into build/ directory with command 'python cx_Freeze_setup.py build'
2. Use cx_Freeze_setup.py (this file) and Cx_Freeze (see Cx_Freeze documentation for help)
:author: P. Savolainen (VTT)
:date: 29.5.2018
"""
import os
import sys
from cx_Freeze import setup, Executable
from spinetoolbox.config import APPLICATION_PATH
version = {}
with open("spinetoolbox/version.py") as fp:
exec(fp.read(), version)
def main(argv):
"""Main of cx_Freeze_setup.py."""
python_dir = os.path.dirname(sys.executable)
os.environ['TCL_LIBRARY'] = os.path.join(python_dir, "tcl", "tcl8.6")
os.environ['TK_LIBRARY'] = os.path.join(python_dir, "tcl", "tk8.6")
# tcl86t.dll and tk86t.dll are required by tkinter, which in turn is required by matplotlib
tcl86t_dll = os.path.join(python_dir, "DLLs", "tcl86t.dll")
tk86t_dll = os.path.join(python_dir, "DLLs", "tk86t.dll")
# Path to built documentation (No need for sources)
doc_path = os.path.abspath(os.path.join(APPLICATION_PATH, os.path.pardir, "docs", "build"))
# Paths to files that should be included (Changelog, readme, licence files)
changelog_file = os.path.abspath(os.path.join(APPLICATION_PATH, os.path.pardir, "CHANGELOG.md"))
readme_file = os.path.abspath(os.path.join(APPLICATION_PATH, os.path.pardir, "README.md"))
copying_file = os.path.abspath(os.path.join(APPLICATION_PATH, os.path.pardir, "COPYING"))
copying_lesser_file = os.path.abspath(os.path.join(APPLICATION_PATH, os.path.pardir, "COPYING.LESSER"))
alembic_version_files = alembic_files(python_dir)
# Most dependencies are automatically detected but some need to be manually included.
# NOTE: Excluding 'scipy.spatial.cKDTree' and including 'scipy.spatial.ckdtree' is a workaround
# for a bug in cx_Freeze affecting Windows (https://github.com/anthony-tuininga/cx_Freeze/issues/233)
build_exe_options = {
"packages": ["packaging", "pkg_resources", "spine_engine"],
"excludes": ["scipy.spatial.cKDTree"],
"includes": [
"atexit",
"asyncio.base_futures",
"asyncio.base_subprocess",
"asyncio.base_tasks",
"asyncio.compat",
"asyncio.constants",
"asyncio.proactor_events",
"asyncio.selector_events",
"asyncio.windows_utils",
"idna.idnadata",
"pygments.lexers.markup",
"pygments.lexers.python",
"pygments.lexers.shell",
"pygments.lexers.julia",
"pygments.styles.default",
"qtconsole.client",
"sqlalchemy.sql.default_comparator",
"sqlalchemy.ext.baked",
"numpy.core._methods",
"matplotlib.backends.backend_tkagg",
"scipy._distributor_init",
"scipy.sparse.csgraph._validation",
"scipy.spatial.ckdtree",
"pymysql",
"tabulator.loaders.local",
"tabulator.parsers.csv",
"ijson.compat",
"ijson.utils",
"ijson.backends.__init__",
"ijson.backends.python",
"ijson.backends.yajl",
"ijson.backends.yajl2",
"ijson.backends.yajl2_c",
"ijson.backends.yajl2_cffi"
],
"include_files": [
(doc_path, "docs/"),
tcl86t_dll,
tk86t_dll,
changelog_file,
readme_file,
copying_file,
copying_lesser_file,
]
+ alembic_version_files,
"include_msvcr": True,
"build_exe": "./build/spinetoolbox/"
}
# Windows specific options
if os.name == "nt": # Windows specific options
base = "Win32GUI" # set this to "Win32GUI" to not show console, "Console" shows console
# Set Windows .msi installer default install path to C:\SpineToolbox-version
systemdrive = os.environ['SYSTEMDRIVE']
# Hardcoded path to msvcr120.dll because include_msvcr option does not seem to do anything
msvcr120_dll = os.path.join(systemdrive, os.path.sep, "Windows", "System32", "msvcr120.dll")
if not os.path.isfile(msvcr120_dll):
print("\nmsvcr120.dll not found in path:{0}".format(msvcr120_dll))
return
# Append msvcr120.dll for Windows 7/8 support
build_exe_options["include_files"].append(msvcr120_dll)
# Other platforms
else:
base = None
executables = [Executable("spinetoolbox.py", base=base, icon="spinetoolbox/ui/resources/app.ico")]
setup(
name="Spine Toolbox",
version=version["__version__"],
description="An application to define, manage, and execute various energy system simulation models.",
author="Spine project consortium",
options={"build_exe": build_exe_options},
executables=executables,
)
def alembic_files(python_dir):
"""Returns a list of tuples of files in python/Lib/site-packages/spinedb_api/alembic/versions.
First item in tuple is the source file. Second item is the relative destination path to the install directory.
"""
dest_dir = os.path.join("lib", "spinedb_api", "alembic", "versions")
p = os.path.join(python_dir, "Lib", "site-packages", "spinedb_api", "alembic", "versions")
files = list()
for f in os.listdir(p):
if f.endswith(".py"):
files.append((os.path.abspath(os.path.join(p, f)), os.path.join(dest_dir, f)))
return files
if __name__ == '__main__':
sys.exit(main(sys.argv))