Changeset 3:04f61ecb89a1
Legend:
- Unmodified
- Added
- Removed
-
setup.py
r0 r3 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 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... 5 """Setuptools setup.py file for nagslang.""" 11 6 7 from setuptools import setup, find_packages 12 8 13 APP_NAME = 'nagslang' 14 DESCRIPTION = open('README.txt').read() 15 CHANGES = open('CHANGES.txt').read() 16 TODO = open('TODO.txt').read() 9 try: 10 import py2exe 11 py2exe # To make pyflakes happy. 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 = { 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', 23 author=(", ".join([ 24 "Adrianna Pinska", 25 "Jeremy Thurgood", 26 "Neil Muller", 27 "Simon Cross", 28 "Stefano Rivera"])), 29 author_email="", 30 31 maintainer="Nagslang Team", 32 maintainer_email="ctpug@googlegroups.com", 33 34 url="http://ctpug.org.za/", 35 download_url="https://ctpug.org.za/hg/nagslang/", 36 37 license="MIT", 38 39 classifiers=[ 40 'Development Status :: 4 - Beta', 41 'Environment :: MacOS X', 42 'Environment :: Win32 (MS Windows)', 43 'Environment :: X11 Applications', 44 'Intended Audience :: End Users/Desktop', 45 'License :: OSI Approved :: MIT License', 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':'', 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 ] 62 # Dependencies 63 install_requires=[], 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'), 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("..") 71 # py2exe 72 console=['scripts/testconsole.py'], 73 windows=[{ 74 'script': 'scripts/nagslang', 75 'icon_resources': [(0, "data/icons/program/icon.ico")], 76 }], 77 app=['scripts/nagslang'], 78 options={ 79 'py2exe': { 80 'skip_archive': 1, 81 'dist_dir': 'dist/nagslang-%s' % VERSION_STR, 82 'packages': [ 83 'logging', 'encodings', 'nagslang', 84 ], 85 'includes': [ 86 'pygame', 87 ], 88 'excludes': [ 89 'numpy', 90 ], 91 'ignores': [ 92 # all database modules 93 'pgdb', 'Sybase', 'adodbapi', 94 'kinterbasdb', 'psycopg', 'psycopg2', 'pymssql', 95 'sapdb', 'pysqlite2', 'sqlite', 'sqlite3', 96 'MySQLdb', 'MySQLdb.connections', 97 'MySQLdb.constants.CR', 'MySQLdb.constants.ER', 98 # old datetime equivalents 99 'DateTime', 'DateTime.ISO', 100 'mx', 'mx.DateTime', 'mx.DateTime.ISO', 101 # email modules 102 'email.Generator', 'email.Iterators', 'email.Utils', 103 ], 104 }, 105 'py2app': { 106 'app': ['run_game.py'], 107 'argv_emulation': True, 108 'iconfile': 'data/icons/program/icon.icns', 109 'packages': [ 110 'logging', 'encodings', 'pygame', 'nagslang', 'data', 111 ], 112 'excludes': ['numpy'], 113 }}, 114 data_files=[ 115 # 'COPYRIGHT', 116 'LICENSE.txt', 117 'README.txt', 118 ], 119 include_package_data=True, 120 )
Note: See TracChangeset
for help on using the changeset viewer.