c903cd93e6670a60651ffdf56517a050be3d8c4d
1 # -*- coding: utf-8 -*-
2 # This will create a dist directory containing the executable file, all the data
3 # directories. All Libraries will be bundled in executable file.
5 # Run the build process by entering 'pygame2exe.py' or
6 # 'python pygame2exe.py' in a console prompt.
8 # To build exe, python, pygame, and py2exe have to be installed. After
9 # building exe none of this libraries are needed.
12 from distutils
.core
import setup
14 from modulefinder
import Module
16 import sys
, os
, shutil
18 except ImportError, message
:
19 raise SystemExit, "Unable to load module. %s" % message
21 class pygame2exe(py2exe
.build_exe
.py2exe
): #This hack make sure that pygame default font is copied: no need to modify code for specifying default font
22 def copy_extensions(self
, extensions
):
23 #Get pygame default font
24 pygamedir
= os
.path
.split(pygame
.base
.__file
__)[0]
25 pygame_default_font
= os
.path
.join(pygamedir
, pygame
.font
.get_default_font())
27 #Add font to list of extension to be copied
28 extensions
.append(Module("pygame.font", pygame_default_font
))
29 py2exe
.build_exe
.py2exe
.copy_extensions(self
, extensions
)
34 self
.script
= "src/minwii/start_win.py"
37 self
.project_name
= "MINWii"
40 self
.project_url
= "about:none"
43 self
.project_version
= "0.0"
45 #License of the program
46 self
.license
= "MyApps License"
49 self
.author_name
= "Me"
50 self
.author_email
= "example@example.com"
51 self
.copyright
= "Copyright (c) 2009 Me."
54 self
.project_description
= "MyApps Description"
56 #Icon file (None will use pygame default icon)
59 #Extra files/dirs copied to game
62 #Extra/excludes python modules
63 self
.extra_modules
= []
64 self
.exclude_modules
= []
67 self
.exclude_dll
= ['']
69 #Zip file name (None will bundle files in exe instead of zip file)
70 self
.zipfile_name
= None
75 ## Code from DistUtils tutorial at http://wiki.python.org/moin/Distutils/Tutorial
76 ## Originally borrowed from wxPython's setup and config files
78 path
= os
.path
.join(*args
)
79 return os
.path
.normpath(path
)
81 def find_data_files(self
, srcdir
, *wildcards
, **kw
):
82 # get a list of all files under the srcdir matching wildcards,
83 # returned in a format to be used for install_data
84 def walk_helper(arg
, dirname
, files
):
90 wc_name
= self
.opj(dirname
, wc
)
92 filename
= self
.opj(dirname
, f
)
94 if fnmatch
.fnmatch(filename
, wc_name
) and not os
.path
.isdir(filename
):
95 names
.append(filename
)
97 lst
.append( (dirname
, names
) )
100 recursive
= kw
.get('recursive', True)
102 os
.path
.walk(srcdir
, walk_helper
, (file_list
, wildcards
))
104 walk_helper((file_list
, wildcards
),
106 [os
.path
.basename(f
) for f
in glob
.glob(self
.opj(srcdir
, '*'))])
110 if os
.path
.isdir(self
.dist_dir
): #Erase previous destination dir
111 shutil
.rmtree(self
.dist_dir
)
113 #Use the default pygame icon, if none given
114 if self
.icon_file
== None:
115 path
= os
.path
.split(pygame
.__file
__)[0]
116 self
.icon_file
= os
.path
.join(path
, 'pygame.ico')
118 #List all data files to add
120 for data
in self
.extra_datas
:
121 if os
.path
.isdir(data
):
122 extra_datas
.extend(self
.find_data_files(data
, '*'))
124 extra_datas
.append(('.', [data
]))
127 cmdclass
= {'py2exe': pygame2exe
},
128 version
= self
.project_version
,
129 description
= self
.project_description
,
130 name
= self
.project_name
,
131 url
= self
.project_url
,
132 author
= self
.author_name
,
133 author_email
= self
.author_email
,
134 license
= self
.license
,
138 'script': self
.script
,
139 'icon_resources': [(0, self
.icon_file
)],
140 'copyright': self
.copyright
142 options
= {'py2exe': {#'optimize': 2,
145 'excludes': self
.exclude_modules
,
146 'packages': self
.extra_modules
,
147 'dll_excludes': self
.exclude_dll
}
149 zipfile
= self
.zipfile_name
,
150 data_files
= extra_datas
,
151 dist_dir
= self
.dist_dir
154 #if os.path.isdir('build'): #Clean up build dir
155 # shutil.rmtree('build')
157 if __name__
== '__main__':
158 if operator
.lt(len(sys
.argv
), 2):
159 sys
.argv
.append('py2exe')
160 BuildExe().run() #Run generation
161 #raw_input("Press any key to continue") #Pause to let user see that things ends