3 # usage: python setup.py command
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)
10 # the goods are placed in the dist dir for you to .zip up or whatever...
13 APP_NAME = 'erdslangetjie'
14 DESCRIPTION = open('README.txt').read()
15 CHANGES = open('CHANGES.txt').read()
16 TODO = open('TODO.txt').read()
23 'license': 'short_licence',
24 'description': 'TODO',
25 'author': 'Neil Muller',
27 'url': 'http://www.pyweek.org/e/erdslangetjie',
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',
48 #'py2exe.icon':'icon.ico', #64x64
49 'py2exe.binary':APP_NAME, #leave off the .exe, it will be added
51 'py2app.target':APP_NAME,
52 'py2app.icon':'icon.icns', #128x128
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,
60 files_to_remove = ['tk84.dll',
63 os.path.join('numpy','core', '_dotblas.pyd'),
64 os.path.join('numpy', 'linalg', 'lapack_lite.pyd'),
68 directories_to_remove = [os.path.join('numpy', 'distutils'),
78 'package_dir': {'erdslangetjie': 'erdslangetjie',
80 'packages': ['erdslangetjie',
82 'scripts': ['scripts/erdslangetjie'],
85 PACKAGEDATA.update(METADATA)
88 from distutils.core import setup, Extension
102 print 'Usage: setup.py install|py2exe|py2app|cx_freeze'
105 # utility for adding subdirectories
106 def add_files(dest,generator):
107 for dirpath, dirnames, filenames in generator:
108 for name in 'CVS', '.svn':
110 dirnames.remove(name)
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)
120 # define what is our data
121 _DATA_DIR = os.path.join('erdslangetjie', 'data')
123 add_files(data,os.walk(_DATA_DIR))
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'] = {'erdslangetjie': data_dirs}
136 data.extend(glob.glob('*.txt'))
137 #data.append('MANIFEST.in')
138 # define what is our source
140 add_files(src,os.walk('erdslangetjie'))
141 src.extend(glob.glob('*.py'))
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")
155 # build the py2exe target
156 if cmd in ('py2exe',):
157 dist_dir = os.path.join('dist',METADATA['py2exe.target'])
161 dest = METADATA['py2exe.binary']+'.py'
162 shutil.copy(src,dest)
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'],
175 #'icon_resources':[(1,METADATA['py2exe.icon'])],
179 # build the py2app target
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
186 dest = METADATA['py2app.target']+'.py'
187 shutil.copy(src,dest)
191 OPTIONS = {'argv_emulation': True,
192 #'iconfile':METADATA['py2app.icon']
197 data_files=DATA_FILES,
198 options={'py2app': OPTIONS},
199 setup_requires=['py2app'],
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)
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
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") )
222 # recursively make a bunch of folders
223 def make_dirs(dname_):
224 parts = list(os.path.split(dname_))
230 dname = os.path.join(dname,parts.pop(0))
231 if not os.path.isdir(dname):
234 # copy data into the binaries
235 if cmd in ('py2exe','cx_freeze','py2app'):
238 dname = os.path.join(dest,os.path.dirname(fname))
240 if not os.path.isdir(fname):
242 shutil.copy(fname,dname)
245 if cmd == 'cx_freeze':
246 sys_cmd = "cd dist; tar -vczf %s.tgz %s/" % (app_dist_dir,app_dist_dir)
250 # remove files from the zip.
251 if 0 and cmd in ('py2exe'):
254 #shutil.rmtree( os.path.join('dist') )
255 #shutil.rmtree( os.path.join('build') )
258 os.system("unzip dist/library.zip -d dist\library")
260 for fn in files_to_remove:
261 os.remove( os.path.join('dist', 'library', fn) )
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) )
268 os.remove( os.path.join('dist', 'library.zip') )
274 os.system("zip -r -9 ..\library.zip .")