-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
160 lines (135 loc) · 6.23 KB
/
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
157
158
159
160
# http://stackoverflow.com/questions/18596410/importerror-no-module-named-mpl-toolkits-with-maptlotlib-1-3-0-and-py2exe
# http://www.py2exe.org/index.cgi/DealingWithWarnings
from distutils.core import setup
import py2exe
import sys
import matplotlib
import os
import glob
import re
# -----------------------------------
# Package dependencies and versions
# -----------------------------------
# from numpy import __version__ as NUMPY_VERSION_STR
# from matplotlib import __version__ as MPL_VERSION_STR
# from scipy import __version__ as SCIPY_VERSION_STR
# from py2exe import __version__ as PY2EXE_VERSION_STR
# from PyQt4.Qt import PYQT_VERSION_STR
# from sip import SIP_VERSION_STR
# from PyQt4.QtCore import QT_VERSION_STR
# assert(NUMPY_VERSION_STR == "1.9.0")
# assert(MPL_VERSION_STR == "1.5.1")
# assert(SCIPY_VERSION_STR == "0.15.1")
# assert(PY2EXE_VERSION_STR == "0.6.9")
# assert(PYQT_VERSION_STR == "4.11.3")
# assert(SIP_VERSION_STR == "4.16.4")
# assert(QT_VERSION_STR == "4.8.6")
# Additional DLLs
# Intel compiler dlls related to blas
# C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016.3.207\windows\redist\ia32_win\compiler
## libifcoremd.dll
## libiomp5md.dll
## libmmd.dll
import DentalClientBaseSettings as DCBS
APP_SETTINGS_SCRIPT = str(DCBS.__file__).replace(".pyc", ".py")
verbose = False
sys.argv.append('py2exe')
def main():
res_files = find_data_files("res", "res", ["*.*"])
invoice_files=find_data_files("invoice", "invoice", ["*.*"])
# sample_files = find_data_files("samples", "samples", ["*.*"])
# mplfiles = matplotlib.get_py2exe_datafiles()
# pyqt_files=[('imageformats',[
# 'C:\\Python27/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll',
# 'C:\\Python27/Lib/site-packages/PyQt4/plugins/imageformats/qgif4.dll',
# 'C:\\Python27/Lib/site-packages/PyQt4/plugins/imageformats/qico4.dll',
# 'C:\\Python27/Lib/site-packages/PyQt4/plugins/imageformats/qmng4.dll',
# 'C:\\Python27/Lib/site-packages/PyQt4/plugins/imageformats/qsvg4.dll',
# 'C:\\Python27/Lib/site-packages/PyQt4/plugins/imageformats/qtiff4.dll'
# ])]
opts = {
'py2exe': {
"bundle_files" : 3,
"compressed" : True,
# "includes" : [ "mainwindow_rc", "matplotlib.backends",
# "matplotlib.backends.backend_qt4agg",
# "pylab", "numpy", "scipy.sparse.csgraph._validation",
# "scipy.special._ufuncs_cxx", "scipy.integrate" ,
# "numpy.core.multiarray",
# "matplotlib.backends.backend_tkagg"
# ],
# 'excludes': ['_gtkagg', '_tkagg', '_agg2',
# '_cairo', '_cocoaagg',
# '_fltkagg', '_gtk', '_gtkcairo', ],
'dll_excludes': [ 'libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'w9xpopen.exe',
'numpy-atlas.dll', # after upgrading numpy from 1.9 to 1.11
'MSVCP90.dll']
}
}
code = setup(
windows=[{
'script': DCBS.APP_MAIN_SCRIPT,
'icon_resources':[(1, DCBS.APP_LOGO_ICO_PATH)],
# 'bitmap_resources ':bitmap_resources,
# other_resources = [get_manifest_resource("Your app name")],
"dest_base" : "DentalClientBase", #exe name
"copyright" : "Copyright (c) 2017 Ali Saad",
"company_name" : "Ali Saad Developments",
"version" : "".join(grep('__version__',APP_SETTINGS_SCRIPT).split()),
"Name" : "Dental Client Base", # name in properties
}],
zipfile=None,
options=opts,
data_files =res_files+invoice_files)
return code
### ******* convenience functions ********
# Grep-like function to catch version from setup.py (it should be done the opposite way)
# version finding from source : http://stackoverflow.com/a/40263000/2192115
def grep(attrname, fname):
pattern = r"{0}\W*=\W*'([^']+)'".format(attrname)
strval = ""
with open(fname, 'r') as myfile:
file_text = myfile.read()
file_text.replace("\n"," ")
strval, = re.findall(pattern, file_text)
return strval
def find_data_files(source,target,patterns):
"""Locates the specified data-files and returns the matches
in a data_files compatible format.
source is the root of the source data tree.
Use '' or '.' for current directory.
target is the root of the target data tree.
Use '' or '.' for the distribution directory.
patterns is a sequence of glob-patterns for the
files you want to copy.
"""
if glob.has_magic(source) or glob.has_magic(target):
raise ValueError("Magic not allowed in src, target")
ret = {}
for pattern in patterns:
pattern = os.path.join(source,pattern)
for filename in glob.glob(pattern):
if os.path.isfile(filename):
targetpath = os.path.join(target,os.path.relpath(filename,source))
path = os.path.dirname(targetpath)
ret.setdefault(path,[]).append(filename)
return sorted(ret.items())
if __name__ == "__main__":
print(">>> [0%] Building ... please wait")
if verbose:
code = main()
else:
# http://stackoverflow.com/questions/2828953/silence-the-stdout-of-a-function-in-python-without-trashing-sys-stdout-and-resto
old_stdout = sys.stdout
sys.stdout = open(os.devnull, "w")
try:
code = main()
finally:
sys.stdout.close()
sys.stdout = old_stdout
if code is None:
print(">>> [xx%] Errors found ... check you configuration")
else:
print(">>> [100%] Binary building complete in the 'dist' directory")