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