comparison setup.py @ 3:04f61ecb89a1

Replace setup.py with our own version.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 01 Sep 2013 10:25:52 +0200
parents 1ea8fa09b70f
children 827ee160ff23
comparison
equal deleted inserted replaced
2:e30d192e9031 3:04f61ecb89a1
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 nagslang."""
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 = 'nagslang' 9 try:
14 DESCRIPTION = open('README.txt').read() 10 import py2exe
15 CHANGES = open('CHANGES.txt').read() 11 py2exe # To make pyflakes happy.
16 TODO = open('TODO.txt').read() 12 except ImportError:
13 pass
17 14
15 # This should probably be pulled from constants.py
16 VERSION_STR = "0.1a"
18 17
18 setup( # Metadata
19 name="nagslang",
20 version=VERSION_STR,
21 description="naglsang: Game for PyWeek 17",
19 22
20 METADATA = { 23 author=(", ".join([
21 'name':APP_NAME, 24 "Adrianna Pinska",
22 'version': '0.0.1', 25 "Jeremy Thurgood",
23 'license': 'short_licence', 26 "Neil Muller",
24 'description': '', 27 "Simon Cross",
25 'author': '', 28 "Stefano Rivera"])),
26 #'author_email': '', 29 author_email="",
27 'url': 'http://pyweek.org/e/nagslang', 30
28 'classifiers': [ 31 maintainer="Nagslang Team",
29 'Development Status :: 4 - Beta', 32 maintainer_email="ctpug@googlegroups.com",
30 'Intended Audience :: End Users/Desktop', 33
31 'Intended Audience :: Information Technology', 34 url="http://ctpug.org.za/",
32 'License :: OSI Approved :: BSD License', 35 download_url="https://ctpug.org.za/hg/nagslang/",
33 'Operating System :: OS Independent', 36
34 'Programming Language :: Python :: 2', 37 license="MIT",
35 'Programming Language :: Python :: 2.5', 38
36 'Programming Language :: Python :: 2.6', 39 classifiers=[
37 'Programming Language :: Python :: 2.7', 40 'Development Status :: 4 - Beta',
38 'Programming Language :: Python :: 3', 41 'Environment :: MacOS X',
39 'Programming Language :: Python :: 3.0', 42 'Environment :: Win32 (MS Windows)',
40 'Programming Language :: Python :: 3.1', 43 'Environment :: X11 Applications',
41 'Programming Language :: Python :: 3.2', 44 'Intended Audience :: End Users/Desktop',
42 'Topic :: Software Development :: Libraries :: pygame', 45 'License :: OSI Approved :: MIT License',
43 'Topic :: Games/Entertainment :: Real Time Strategy', 46 'Natural Language :: English',
47 'Operating System :: Microsoft :: Windows',
48 'Operating System :: POSIX',
49 'Operating System :: MacOS :: MacOS X',
50 'Programming Language :: Python :: 2.5',
51 'Programming Language :: Python :: 2.6',
52 'Topic :: Games/Entertainment :: Role-Playing',
53 'Topic :: Games/Entertainment :: Arcade',
44 ], 54 ],
45 55
56 platforms=[
57 'Linux',
58 'Mac OS X',
59 'Windows',
60 ],
46 61
47 'py2exe.target':'', 62 # Dependencies
48 #'py2exe.icon':'icon.ico', #64x64 63 install_requires=[],
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 64
65 # Files
66 packages=find_packages(),
67 scripts=[
68 'scripts/nagslang',
69 ],
67 70
68 directories_to_remove = [os.path.join('numpy', 'distutils'), 71 # py2exe
69 'distutils', 72 console=['scripts/testconsole.py'],
70 'tcl', 73 windows=[{
71 ] 74 'script': 'scripts/nagslang',
72 75 'icon_resources': [(0, "data/icons/program/icon.ico")],
73 76 }],
74 cmdclass = {} 77 app=['scripts/nagslang'],
75 PACKAGEDATA = { 78 options={
76 'cmdclass': cmdclass, 79 'py2exe': {
77 80 'skip_archive': 1,
78 'package_dir': {'nagslang': 'nagslang', 81 'dist_dir': 'dist/nagslang-%s' % VERSION_STR,
79 }, 82 'packages': [
80 'packages': ['nagslang', 83 'logging', 'encodings', 'nagslang',
81 ], 84 ],
82 'scripts': ['scripts/nagslang'], 85 'includes': [
83 } 86 'pygame',
84 87 ],
85 PACKAGEDATA.update(METADATA) 88 'excludes': [
86 89 'numpy',
87 90 ],
88 from distutils.core import setup, Extension 91 'ignores': [
89 try: 92 # all database modules
90 import py2exe 93 'pgdb', 'Sybase', 'adodbapi',
91 except: 94 'kinterbasdb', 'psycopg', 'psycopg2', 'pymssql',
92 pass 95 'sapdb', 'pysqlite2', 'sqlite', 'sqlite3',
93 96 'MySQLdb', 'MySQLdb.connections',
94 import sys 97 'MySQLdb.constants.CR', 'MySQLdb.constants.ER',
95 import glob 98 # old datetime equivalents
96 import os 99 'DateTime', 'DateTime.ISO',
97 import shutil 100 'mx', 'mx.DateTime', 'mx.DateTime.ISO',
98 101 # email modules
99 try: 102 'email.Generator', 'email.Iterators', 'email.Utils',
100 cmd = sys.argv[1] 103 ],
101 except IndexError: 104 },
102 print 'Usage: setup.py install|py2exe|py2app|cx_freeze' 105 'py2app': {
103 raise SystemExit 106 'app': ['run_game.py'],
104 107 'argv_emulation': True,
105 # utility for adding subdirectories 108 'iconfile': 'data/icons/program/icon.icns',
106 def add_files(dest,generator): 109 'packages': [
107 for dirpath, dirnames, filenames in generator: 110 'logging', 'encodings', 'pygame', 'nagslang', 'data',
108 for name in 'CVS', '.svn': 111 ],
109 if name in dirnames: 112 'excludes': ['numpy'],
110 dirnames.remove(name) 113 }},
111 114 data_files=[
112 for name in filenames: 115 # 'COPYRIGHT',
113 if '~' in name: continue 116 'LICENSE.txt',
114 suffix = os.path.splitext(name)[1] 117 'README.txt',
115 if suffix in ('.pyc', '.pyo'): continue 118 ],
116 if name[0] == '.': continue 119 include_package_data=True,
117 filename = os.path.join(dirpath, name) 120 )
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("..")