-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_exe.py
More file actions
107 lines (85 loc) · 3.67 KB
/
build_exe.py
File metadata and controls
107 lines (85 loc) · 3.67 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
from cx_Freeze import setup, Executable
import os
import scipy
import skimage
import opcode
import sys
if os.environ['VIRTUAL_ENV']:
VENV_DIR = os.environ['VIRTUAL_ENV']
else:
VENV_DIR = os.path.dirname(os.path.dirname(os.__file__))
LIB_DIR = os.path.join(VENV_DIR, "Lib")
SITE_PACKAGES_DIR = os.path.join(LIB_DIR, "site-packages")
PROJECT_DIR = os.path.abspath(os.path.curdir)
APP_NAME = 'IAN Annotation Tool'
SCRIPT_PATH = os.path.join(PROJECT_DIR, "annotation_tool.py")
ICON_PATH = os.path.join(PROJECT_DIR, "annotation", "images", "icon.ico")
## installs in Program Files --> the installer fails because it has not enough privileges
# if 'bdist_msi' in sys.argv:
# sys.argv += ['--initial-target-dir', r'C:\Program Files\{}'.format(APP_NAME)]
version = "1.3"
def collect_dist_info(packages):
"""
Recursively collects the path to the packages' dist-info.
From https://github.com/marcelotduarte/cx_Freeze/issues/438#issuecomment-472954154
"""
import pkg_resources
from os.path import join, basename
if not isinstance(packages, list):
packages = [packages]
dirs = []
for pkg in packages:
distrib = pkg_resources.get_distribution(pkg)
for req in distrib.requires():
dirs.extend(collect_dist_info(req.key))
dirs.append((distrib.egg_info, join('Lib', basename(distrib.egg_info))))
return dirs
packages_dist_info = ['apptools', 'configobj', 'envisage', 'mayavi', 'numpy', 'pygments',
'six', 'traits', 'traitsui', 'vtk', 'pyface', 'setuptools']
packages = ['sys', 'os', 'ctypes', 'platform', 'shutil', 'numpy', 'traits', 'traits.api', 'mayavi',
'mayavi.core', 'traitsui', 'traitsui.qt4.toolkit', 'mayavi.core.ui', 'mayavi.core.ui.api',
'tvtk', 'tvtk.tools', 'tvtk.api', 'json', 'math', 'time', 'sqlite3',
'pyface', 'pyface.ui', 'pyface.ui.qt4', 'pkg_resources', 'pyface.qt.QtGui', 'pyface.qt.QtCore',
'pkg_resources._vendor', 'pkg_resources.extern', "tvtk.pyface.ui.qt4", 'pygments', 'vtkmodules',
'pyface.ui.qt4', 'pyface.qt', 'numpy', 'matplotlib', 'mayavi', 'traits', 'traitsui',
'scipy.linalg', 'pyqt5', 'pyface']
def get_site_package(name):
return ((os.path.join(SITE_PACKAGES_DIR, name)), name)
include_files = collect_dist_info(packages_dist_info)
# fix for scipy
scipy_path = os.path.dirname(scipy.__file__)
include_files.append((str(scipy_path), "scipy"))
# fix for skimage
skimage_path = os.path.dirname(skimage.__file__)
include_files.append((str(skimage_path), "skimage"))
# fix for mpl_toolkits
include_files.append(get_site_package('mpl_toolkits'))
# fix for distutils
# from https://gist.github.com/nicoddemus/ca0acd93a20acbc42d1d#workaround
distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils')
include_files.append((distutils_path, 'distutils'))
build_exe_options = {
"packages": packages,
"excludes": ['tkinter', 'multiprocessing.Pool'],
"includes": [],
"include_files": include_files
}
executable = Executable(
script=SCRIPT_PATH,
targetName="{}.exe".format(APP_NAME),
base='Win32GUI',
icon=ICON_PATH,
shortcutName=APP_NAME,
shortcutDir="DesktopFolder",
)
setup(name=APP_NAME,
version=version,
description=APP_NAME,
author="AImageLab",
options={"build_exe": build_exe_options},
executables=[executable]
)
# fix multiprocessing Pool.pyc --> pool.pyc
# from https://github.com/marcelotduarte/cx_Freeze/issues/353#issuecomment-376829379
multiprocessing_dir = os.path.join("build", "exe.win-amd64-3.7", "lib", "multiprocessing")
os.rename(os.path.join(multiprocessing_dir, "Pool.pyc"), os.path.join(multiprocessing_dir, "pool.pyc"))