0
|
1 import os
|
|
2
|
|
3 # usage: python setup.py command
|
|
4 #
|
|
5 # sdist - build a source dist
|
|
6 # py2exe - build an exe
|
|
7 # py2app - build an app
|
|
8 # cx_freeze - build a linux binary (not implemented)
|
|
9 #
|
|
10 # the goods are placed in the dist dir for you to .zip up or whatever...
|
|
11
|
|
12
|
|
13 APP_NAME = 'skaapsteker'
|
|
14 DESCRIPTION = open('README.txt').read()
|
|
15 CHANGES = open('CHANGES.txt').read()
|
|
16 TODO = open('TODO.txt').read()
|
|
17
|
|
18
|
|
19
|
|
20 METADATA = {
|
|
21 'name':APP_NAME,
|
|
22 'version': '0.0.1',
|
|
23 'license': 'short_licence',
|
|
24 'description': '',
|
|
25 'author': 'Adrianna Pinska, Anna Malczyk, Jeremy Thurgood, Neil Muller, Oliver Hambsch, Simon Cross, Stefano Rivera',
|
|
26 #'author_email': '',
|
|
27 'url': 'http://pyweek.org/e/skaapsteker',
|
|
28 'classifiers': [
|
|
29 'Development Status :: 4 - Beta',
|
|
30 'Intended Audience :: End Users/Desktop',
|
|
31 'Intended Audience :: Information Technology',
|
|
32 'License :: OSI Approved :: BSD License',
|
|
33 'Operating System :: OS Independent',
|
|
34 'Programming Language :: Python :: 2',
|
|
35 'Programming Language :: Python :: 2.6',
|
|
36 'Programming Language :: Python :: 2.7',
|
|
37 'Topic :: Software Development :: Libraries :: pygame',
|
|
38 'Topic :: Games/Entertainment :: Real Time Strategy',
|
|
39 ],
|
|
40
|
|
41
|
|
42 'py2exe.target':'',
|
|
43 #'py2exe.icon':'icon.ico', #64x64
|
|
44 'py2exe.binary':APP_NAME, #leave off the .exe, it will be added
|
|
45
|
|
46 'py2app.target':APP_NAME,
|
|
47 'py2app.icon':'icon.icns', #128x128
|
|
48
|
|
49 #'cx_freeze.cmd':'~/src/cx_Freeze-3.0.3/FreezePython',
|
|
50 'cx_freeze.cmd':'cxfreeze',
|
|
51 'cx_freeze.target':'%s_linux' % APP_NAME,
|
|
52 'cx_freeze.binary':APP_NAME,
|
|
53 }
|
|
54
|
|
55 files_to_remove = ['tk84.dll',
|
|
56 '_ssl.pyd',
|
|
57 'tcl84.dll',
|
|
58 os.path.join('numpy','core', '_dotblas.pyd'),
|
|
59 os.path.join('numpy', 'linalg', 'lapack_lite.pyd'),
|
|
60 ]
|
|
61
|
|
62
|
|
63 directories_to_remove = [os.path.join('numpy', 'distutils'),
|
|
64 'distutils',
|
|
65 'tcl',
|
|
66 ]
|
|
67
|
|
68
|
|
69 cmdclass = {}
|
|
70 PACKAGEDATA = {
|
|
71 'cmdclass': cmdclass,
|
|
72
|
|
73 'package_dir': {'skaapsteker': 'skaapsteker',
|
|
74 },
|
|
75 'packages': ['skaapsteker',
|
|
76 ],
|
|
77 'scripts': ['scripts/skaapsteker'],
|
|
78 }
|
|
79
|
|
80 PACKAGEDATA.update(METADATA)
|
|
81
|
|
82
|
|
83 from distutils.core import setup, Extension
|
|
84 try:
|
|
85 import py2exe
|
|
86 except:
|
|
87 pass
|
|
88
|
|
89 import sys
|
|
90 import glob
|
|
91 import os
|
|
92 import shutil
|
|
93
|
|
94 try:
|
|
95 cmd = sys.argv[1]
|
|
96 except IndexError:
|
|
97 print 'Usage: setup.py install|py2exe|py2app|cx_freeze'
|
|
98 raise SystemExit
|
|
99
|
|
100 # utility for adding subdirectories
|
|
101 def add_files(dest,generator):
|
|
102 for dirpath, dirnames, filenames in generator:
|
|
103 for name in 'CVS', '.svn':
|
|
104 if name in dirnames:
|
|
105 dirnames.remove(name)
|
|
106
|
|
107 for name in filenames:
|
|
108 if '~' in name: continue
|
|
109 suffix = os.path.splitext(name)[1]
|
|
110 if suffix in ('.pyc', '.pyo'): continue
|
|
111 if name[0] == '.': continue
|
|
112 filename = os.path.join(dirpath, name)
|
|
113 dest.append(filename)
|
|
114
|
|
115 # define what is our data
|
|
116 _DATA_DIR = os.path.join('skaapsteker', 'data')
|
|
117 data = []
|
|
118 add_files(data,os.walk(_DATA_DIR))
|
|
119
|
|
120
|
|
121
|
|
122
|
|
123 #data_dirs = [os.path.join(f2.replace(_DATA_DIR, 'data'), '*') for f2 in data]
|
|
124 data_dirs = [os.path.join(f2.replace(_DATA_DIR, 'data')) for f2 in data]
|
|
125 PACKAGEDATA['package_data'] = {'skaapsteker': data_dirs}
|
|
126
|
|
127
|
|
128
|
|
129
|
|
130
|
|
131 data.extend(glob.glob('*.txt'))
|
|
132 #data.append('MANIFEST.in')
|
|
133 # define what is our source
|
|
134 src = []
|
|
135 add_files(src,os.walk('skaapsteker'))
|
|
136 src.extend(glob.glob('*.py'))
|
|
137
|
|
138
|
|
139
|
|
140
|
|
141 # build the sdist target
|
|
142 if cmd not in "py2exe py2app cx_freeze".split():
|
|
143 f = open("MANIFEST.in","w")
|
|
144 for l in data: f.write("include "+l+"\n")
|
|
145 for l in src: f.write("include "+l+"\n")
|
|
146 f.close()
|
|
147
|
|
148 setup(**PACKAGEDATA)
|
|
149
|
|
150 # build the py2exe target
|
|
151 if cmd in ('py2exe',):
|
|
152 dist_dir = os.path.join('dist',METADATA['py2exe.target'])
|
|
153 data_dir = dist_dir
|
|
154
|
|
155 src = 'run_game.py'
|
|
156 dest = METADATA['py2exe.binary']+'.py'
|
|
157 shutil.copy(src,dest)
|
|
158
|
|
159 setup(
|
|
160 options={'py2exe':{
|
|
161 'dist_dir':dist_dir,
|
|
162 'dll_excludes':['_dotblas.pyd','_numpy.pyd', 'numpy.linalg.lapack_lite.pyd', 'numpy.core._dotblas.pyd'] + files_to_remove,
|
|
163 'excludes':['matplotlib', 'tcl', 'OpenGL'],
|
|
164 'ignores':['matplotlib', 'tcl', 'OpenGL'],
|
|
165 'bundle_files':1,
|
|
166 }},
|
|
167 # windows=[{
|
|
168 console=[{
|
|
169 'script':dest,
|
|
170 #'icon_resources':[(1,METADATA['py2exe.icon'])],
|
|
171 }],
|
|
172 )
|
|
173
|
|
174 # build the py2app target
|
|
175 if cmd == 'py2app':
|
|
176 dist_dir = os.path.join('dist',METADATA['py2app.target']+'.app')
|
|
177 data_dir = os.path.join(dist_dir,'Contents','Resources')
|
|
178 from setuptools import setup
|
|
179
|
|
180 src = 'run_game.py'
|
|
181 dest = METADATA['py2app.target']+'.py'
|
|
182 shutil.copy(src,dest)
|
|
183
|
|
184 APP = [dest]
|
|
185 DATA_FILES = []
|
|
186 OPTIONS = {'argv_emulation': True,
|
|
187 #'iconfile':METADATA['py2app.icon']
|
|
188 }
|
|
189
|
|
190 setup(
|
|
191 app=APP,
|
|
192 data_files=DATA_FILES,
|
|
193 options={'py2app': OPTIONS},
|
|
194 setup_requires=['py2app'],
|
|
195 )
|
|
196
|
|
197 # make the cx_freeze target
|
|
198 if cmd == 'cx_freeze':
|
|
199 app_dist_dir = METADATA['cx_freeze.target'] + "_" + METADATA['version']
|
|
200 dist_dir = os.path.join('dist', app_dist_dir)
|
|
201 data_dir = dist_dir
|
|
202
|
|
203 modules_exclude = "tcl,tk"
|
|
204 cmd_args = (METADATA['cx_freeze.cmd'], dist_dir, METADATA['cx_freeze.binary'], modules_exclude)
|
|
205 sys_cmd = '%s --install-dir=%s --target-name=%s --exclude-modules=%s run_game.py' % cmd_args
|
|
206 print sys_cmd
|
|
207 os.system(sys_cmd)
|
|
208
|
|
209 import shutil
|
|
210 if os.path.exists(os.path.join(data_dir, "tcl")):
|
|
211 shutil.rmtree( os.path.join(data_dir, "tcl") )
|
|
212 if os.path.exists(os.path.join(data_dir, "tk")):
|
|
213 shutil.rmtree( os.path.join(data_dir, "tk") )
|
|
214
|
|
215
|
|
216
|
|
217 # recursively make a bunch of folders
|
|
218 def make_dirs(dname_):
|
|
219 parts = list(os.path.split(dname_))
|
|
220 dname = None
|
|
221 while len(parts):
|
|
222 if dname == None:
|
|
223 dname = parts.pop(0)
|
|
224 else:
|
|
225 dname = os.path.join(dname,parts.pop(0))
|
|
226 if not os.path.isdir(dname):
|
|
227 os.mkdir(dname)
|
|
228
|
|
229 # copy data into the binaries
|
|
230 if cmd in ('py2exe','cx_freeze','py2app'):
|
|
231 dest = data_dir
|
|
232 for fname in data:
|
|
233 dname = os.path.join(dest,os.path.dirname(fname))
|
|
234 make_dirs(dname)
|
|
235 if not os.path.isdir(fname):
|
|
236 #print (fname,dname)
|
|
237 shutil.copy(fname,dname)
|
|
238
|
|
239 # make a tgz files.
|
|
240 if cmd == 'cx_freeze':
|
|
241 sys_cmd = "cd dist; tar -vczf %s.tgz %s/" % (app_dist_dir,app_dist_dir)
|
|
242 os.system(sys_cmd)
|
|
243
|
|
244
|
|
245 # remove files from the zip.
|
|
246 if 0 and cmd in ('py2exe'):
|
|
247 import shutil
|
|
248
|
|
249 #shutil.rmtree( os.path.join('dist') )
|
|
250 #shutil.rmtree( os.path.join('build') )
|
|
251
|
|
252
|
|
253 os.system("unzip dist/library.zip -d dist\library")
|
|
254
|
|
255 for fn in files_to_remove:
|
|
256 os.remove( os.path.join('dist', 'library', fn) )
|
|
257
|
|
258
|
|
259 for d in directories_to_remove:
|
|
260 if os.path.exists( os.path.join('dist', 'library', d) ):
|
|
261 shutil.rmtree( os.path.join('dist', 'library', d) )
|
|
262
|
|
263 os.remove( os.path.join('dist', 'library.zip') )
|
|
264
|
|
265
|
|
266 os.chdir("dist")
|
|
267 os.chdir("library")
|
|
268
|
|
269 os.system("zip -r -9 ..\library.zip .")
|
|
270
|
|
271 os.chdir("..")
|
|
272 os.chdir("..")
|