-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_exe_zip.py
102 lines (94 loc) · 3.58 KB
/
build_exe_zip.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
'''
Script which uses cx freeze to build an exe and zip files for running and distributing on windows
Usage: python build_exe_zip.py build_exe
'''
import shutil
from pathlib import Path
import os
import sys
from setuptools import find_packages
from cx_Freeze import setup, Executable
import matplotlib
import opcode
if Path('build/').exists():
shutil.rmtree(str(Path('build/')))
version_file_path = str(Path(__file__).parent / 'VERSION.txt')
PYTHON_FOLDER_ROOT = Path(os.__file__).parent.parent
print(f'python root folder: {PYTHON_FOLDER_ROOT}')
TCL_PATH = PYTHON_FOLDER_ROOT / 'tcl' / 'tcl8.6'
TK_PATH = PYTHON_FOLDER_ROOT / 'tcl' / 'tk8.6'
if TCL_PATH.exists():
print(f'tcl8.6 exists at path {TCL_PATH}')
else:
raise FileNotFoundError(f'{TCL_PATH} does not exist')
if TK_PATH.exists():
print(f'tk8.6 exists at path {TK_PATH}')
else:
raise FileNotFoundError(f'{TK_PATH} does not exist')
os.environ['TCL_LIBRARY'] = str(TCL_PATH)
os.environ['TK_LIBRARY'] = str(TK_PATH)
SYSTEM_PYTHON_DLLS_FOLDER = str(Path(opcode.__file__).parent.parent / 'DLLs')
SYSTEM_PYTHON_LIB_FOLDER = str(Path(opcode.__file__).parent.parent / 'Lib')
TK_DLL_PATH = Path(SYSTEM_PYTHON_DLLS_FOLDER) / 'tk86t.dll'
TCL_DLL_PATH = Path(SYSTEM_PYTHON_DLLS_FOLDER) / 'tcl86t.dll'
if TK_DLL_PATH.exists():
print(f'tk8.6t.dll exists at path {TK_DLL_PATH}')
else:
raise FileNotFoundError(f'{TK_DLL_PATH} does not exist')
if TCL_DLL_PATH.exists():
print(f'tcl86t.dll exists at path {TCL_DLL_PATH}')
else:
raise FileNotFoundError(f'{TCL_DLL_PATH} does not exist')
with open(version_file_path) as version_file:
VERSION = version_file.read()
build_root = f'build/pyomrx_{VERSION}'
options = {
'build_exe': {
'includes': ['pyomrx', 'tkinter', 'matplotlib.backends.backend_tkagg'],
'path':
sys.path + ['modules'],
# explicitly include packages which cx_freeze doesn't find
'packages': ["numpy", "scipy", "matplotlib.backends.backend_tkagg", 'tkinter'],
"excludes": [
"scipy.spatial.cKDTree", # bug: cKDTree causes ckdtree to not copy
"distutils", # because of virtualenv
"tests"
],
"include_files": [(matplotlib.get_data_path(), "mpl-sub_form_data"),
str(TK_DLL_PATH),
str(TCL_DLL_PATH),
(os.path.join(SYSTEM_PYTHON_LIB_FOLDER,
'distutils'), 'distutils'),
(version_file_path, 'lib/VERSION.txt')],
"build_exe":
build_root,
"include_msvcr":
True
}
}
target = Executable(
script="app.py",
base="Win32GUI" if sys.platform == "win32" else None,
icon='res/logo.ico',
targetName='run.exe')
setup(
name="pyomrx",
version=VERSION,
author='Shaun Howell',
author_email='shaunkhowell@gmail.com',
url='https://github.com/ShaunHowell/py-omrx',
description=
"Library and GUI for optical mark recognition form generation and data extraction",
options=options,
packages=find_packages(include=['pyomrx', 'pyomrx.*']),
executables=[target],
install_requires=Path('requirements.txt').read_text(),
tests_require=['pytest'])
# workaround for cx_freeze naming multiprocessing.pool incorrectly
Path(f'{build_root}/lib/multiprocessing/Pool.pyc').rename(
Path(f'{build_root}/lib/multiprocessing/pool.pyc'))
# workaround for tkinter being called Tkinter
os.rename(f'{build_root}/lib/Tkinter', f'{build_root}/lib/tkinter')
os.makedirs('dist', exist_ok=True)
shutil.make_archive(
str(Path(f'dist/py-omrx-{VERSION}')), 'zip', build_root)