Mercurial > mamba
comparison setup.py @ 429:965048a33ce4
Untested stab at setup.py
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 17 Sep 2011 19:02:11 +0200 |
parents | 08941f788c15 |
children | 14ea75642dcb |
comparison
equal
deleted
inserted
replaced
428:841648de4b4f | 429:965048a33ce4 |
---|---|
1 import os | 1 # setup.py |
2 # -*- coding: utf8 -*- | |
3 # vim:fileencoding=utf8 ai ts=4 sts=4 et sw=4 | |
2 | 4 |
3 # usage: python setup.py command | 5 """Setuptools setup.py file for Mutable Mamba.""" |
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 | 6 |
7 from setuptools import setup, find_packages | |
12 | 8 |
13 APP_NAME = 'mamba' | |
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': 'mamba', | |
26 #'author_email': '', | |
27 'url': 'http://pyweek.org/e/mamba', | |
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': {'mamba': 'mamba', | |
79 }, | |
80 'packages': ['mamba', | |
81 ], | |
82 'scripts': ['scripts/mamba'], | |
83 } | |
84 | |
85 PACKAGEDATA.update(METADATA) | |
86 | |
87 | |
88 from distutils.core import setup, Extension | |
89 try: | 9 try: |
90 import py2exe | 10 import py2exe # pyflakes: ignore |
91 except: | 11 except ImportError: |
92 pass | 12 pass |
93 | 13 |
94 import sys | 14 VERSION_STR = "0.1" |
95 import glob | |
96 import os | |
97 import shutil | |
98 | 15 |
99 try: | 16 setup( # Metadata |
100 cmd = sys.argv[1] | 17 name="mutable-mamba", |
101 except IndexError: | 18 version=VERSION_STR, |
102 print 'Usage: setup.py install|py2exe|py2app|cx_freeze' | 19 description="Mutable Mamba: Snake game for PyWeek 13", |
103 raise SystemExit | |
104 | 20 |
105 # utility for adding subdirectories | 21 author=("Adrianna Pinska, Desilu Crossman, Jeremy Thurgood, " |
106 def add_files(dest,generator): | 22 "Neil Muller, Simon Cross, Stefano Rivera"), |
107 for dirpath, dirnames, filenames in generator: | 23 author_email="", |
108 for name in 'CVS', '.svn': | |
109 if name in dirnames: | |
110 dirnames.remove(name) | |
111 | 24 |
112 for name in filenames: | 25 maintainer="Mamba Team", |
113 if '~' in name: continue | 26 maintainer_email="ctpug@googlegroups.com", |
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 | 27 |
120 # define what is our data | 28 url="http://ctpug.org.za/", |
121 _DATA_DIR = os.path.join('mamba', 'data') | 29 download_url="https://ctpug.org.za/hg/mamba/", |
122 data = [] | |
123 add_files(data,os.walk(_DATA_DIR)) | |
124 | 30 |
31 license="MIT", | |
125 | 32 |
33 classifiers=[ | |
34 'Development Status :: 4 - Beta', | |
35 'Environment :: MacOS X', | |
36 'Environment :: Win32 (MS Windows)', | |
37 'Environment :: X11 Applications', | |
38 'Intended Audience :: End Users/Desktop', | |
39 'License :: OSI Approved :: MIT License', | |
40 'Natural Language :: English', | |
41 'Operating System :: Microsoft :: Windows', | |
42 'Operating System :: POSIX', | |
43 'Operating System :: MacOS :: MacOS X', | |
44 'Programming Language :: Python :: 2.5', | |
45 'Programming Language :: Python :: 2.6', | |
46 'Topic :: Games/Entertainment :: Role-Playing', | |
47 'Topic :: Games/Entertainment :: Arcade', | |
48 ], | |
126 | 49 |
50 platforms=[ | |
51 'Linux', | |
52 'Mac OS X', | |
53 'Windows', | |
54 ], | |
127 | 55 |
128 #data_dirs = [os.path.join(f2.replace(_DATA_DIR, 'data'), '*') for f2 in data] | 56 # Dependencies |
129 data_dirs = [os.path.join(f2.replace(_DATA_DIR, 'data')) for f2 in data] | 57 install_requires=[], |
130 PACKAGEDATA['package_data'] = {'mamba': data_dirs} | |
131 | 58 |
59 # Files | |
60 packages=find_packages(), | |
61 scripts=[ | |
62 'scripts/mamba', | |
63 ], | |
132 | 64 |
133 | 65 # py2exe |
134 | 66 console=['scripts/testconsole.py'], |
135 | 67 windows=[{ |
136 data.extend(glob.glob('*.txt')) | 68 'script': 'scripts/mamba', |
137 #data.append('MANIFEST.in') | 69 'icon_resources': [(0, "data/icons/program/icon.ico")], |
138 # define what is our source | 70 }], |
139 src = [] | 71 app=['scripts/mamba'], |
140 add_files(src,os.walk('mamba')) | 72 options={ |
141 src.extend(glob.glob('*.py')) | 73 'py2exe': { |
142 | 74 'skip_archive': 1, |
143 | 75 'dist_dir': 'dist/mutable-mamba-%s' % VERSION_STR, |
144 | 76 'packages': [ |
145 | 77 'logging', 'encodings', 'mamba', |
146 # build the sdist target | 78 ], |
147 if cmd not in "py2exe py2app cx_freeze".split(): | 79 'includes': [ |
148 f = open("MANIFEST.in","w") | 80 # pygame |
149 for l in data: f.write("include "+l+"\n") | 81 'pygame', |
150 for l in src: f.write("include "+l+"\n") | 82 ], |
151 f.close() | 83 'excludes': [ |
152 | 84 'numpy', |
153 setup(**PACKAGEDATA) | 85 ], |
154 | 86 'ignores': [ |
155 # build the py2exe target | 87 # all database modules |
156 if cmd in ('py2exe',): | 88 'pgdb', 'Sybase', 'adodbapi', |
157 dist_dir = os.path.join('dist',METADATA['py2exe.target']) | 89 'kinterbasdb', 'psycopg', 'psycopg2', 'pymssql', |
158 data_dir = dist_dir | 90 'sapdb', 'pysqlite2', 'sqlite', 'sqlite3', |
159 | 91 'MySQLdb', 'MySQLdb.connections', |
160 src = 'run_game.py' | 92 'MySQLdb.constants.CR', 'MySQLdb.constants.ER', |
161 dest = METADATA['py2exe.binary']+'.py' | 93 # old datetime equivalents |
162 shutil.copy(src,dest) | 94 'DateTime', 'DateTime.ISO', |
163 | 95 'mx', 'mx.DateTime', 'mx.DateTime.ISO', |
164 setup( | 96 # email modules |
165 options={'py2exe':{ | 97 'email.Generator', 'email.Iterators', 'email.Utils', |
166 'dist_dir':dist_dir, | 98 ], |
167 'dll_excludes':['_dotblas.pyd','_numpy.pyd', 'numpy.linalg.lapack_lite.pyd', 'numpy.core._dotblas.pyd'] + files_to_remove, | 99 }, |
168 'excludes':['matplotlib', 'tcl', 'OpenGL'], | 100 'py2app': { |
169 'ignores':['matplotlib', 'tcl', 'OpenGL'], | 101 'app': ['run_game.py'], |
170 'bundle_files':1, | 102 'argv_emulation': True, |
103 'iconfile': 'data/icons/program/icon.icns', | |
104 # 'dist_dir': 'dist/mutable-mamba-%s' % VERSION_STR, | |
105 # 'bdist_base': 'build/bdist', | |
106 'packages': [ | |
107 'logging', 'encodings', 'pygame', 'mamba', 'data', | |
108 ], | |
109 'excludes': ['numpy'], | |
171 }}, | 110 }}, |
172 # windows=[{ | 111 data_files=[ |
173 console=[{ | 112 # 'COPYRIGHT', |
174 'script':dest, | 113 'LICENSE.txt', |
175 #'icon_resources':[(1,METADATA['py2exe.icon'])], | 114 'README.txt', |
176 }], | 115 ], |
116 include_package_data=True, | |
177 ) | 117 ) |
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("..") |