0f292578cac5599cfb098915cb1588d1615401ad
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
22 origIsSystemDLL
= py2exe
.build_exe
.isSystemDLL
23 def isSystemDLL(pathname
):
24 if os
.path
.basename(pathname
).lower() in ["sdl_ttf.dll"]:
26 return origIsSystemDLL(pathname
)
27 py2exe
.build_exe
.isSystemDLL
= isSystemDLL
30 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
31 def copy_extensions(self
, extensions
):
32 #Get pygame default font
33 pygamedir
= os
.path
.split(pygame
.base
.__file
__)[0]
34 pygame_default_font
= os
.path
.join(pygamedir
, pygame
.font
.get_default_font())
36 #Add font to list of extension to be copied
37 extensions
.append(Module("pygame.font", pygame_default_font
))
38 py2exe
.build_exe
.py2exe
.copy_extensions(self
, extensions
)
43 self
.script
= "src/minwii/start_win.py"
46 self
.project_name
= "MINWii"
49 self
.project_url
= "about:none"
52 self
.project_version
= "0.0"
54 #License of the program
55 self
.license
= "MyApps License"
58 self
.author_name
= "Me"
59 self
.author_email
= "example@example.com"
60 self
.copyright
= "Copyright (c) 2009 Me."
63 self
.project_description
= "MyApps Description"
65 #Icon file (None will use pygame default icon)
68 #Extra files/dirs copied to game
71 #Extra/excludes python modules
72 self
.extra_modules
= []
73 self
.exclude_modules
= []
76 self
.exclude_dll
= ['']
78 #Zip file name (None will bundle files in exe instead of zip file)
79 self
.zipfile_name
= None
84 ## Code from DistUtils tutorial at http://wiki.python.org/moin/Distutils/Tutorial
85 ## Originally borrowed from wxPython's setup and config files
87 path
= os
.path
.join(*args
)
88 return os
.path
.normpath(path
)
90 def find_data_files(self
, srcdir
, *wildcards
, **kw
):
91 # get a list of all files under the srcdir matching wildcards,
92 # returned in a format to be used for install_data
93 def walk_helper(arg
, dirname
, files
):
99 wc_name
= self
.opj(dirname
, wc
)
101 filename
= self
.opj(dirname
, f
)
103 if fnmatch
.fnmatch(filename
, wc_name
) and not os
.path
.isdir(filename
):
104 names
.append(filename
)
106 lst
.append( (dirname
, names
) )
109 recursive
= kw
.get('recursive', True)
111 os
.path
.walk(srcdir
, walk_helper
, (file_list
, wildcards
))
113 walk_helper((file_list
, wildcards
),
115 [os
.path
.basename(f
) for f
in glob
.glob(self
.opj(srcdir
, '*'))])
119 if os
.path
.isdir(self
.dist_dir
): #Erase previous destination dir
120 shutil
.rmtree(self
.dist_dir
)
122 if os
.path
.isdir('build'): #Clean up build dir
123 shutil
.rmtree('build')
126 #Use the default pygame icon, if none given
127 if self
.icon_file
== None:
128 path
= os
.path
.split(pygame
.__file
__)[0]
129 self
.icon_file
= os
.path
.join(path
, 'pygame.ico')
131 #List all data files to add
133 for data
in self
.extra_datas
:
134 if os
.path
.isdir(data
):
135 extra_datas
.extend(self
.find_data_files(data
, '*'))
137 extra_datas
.append(('.', [data
]))
141 cmdclass
= {'py2exe': pygame2exe
},
142 version
= self
.project_version
,
143 description
= self
.project_description
,
144 name
= self
.project_name
,
145 url
= self
.project_url
,
146 author
= self
.author_name
,
147 author_email
= self
.author_email
,
148 license
= self
.license
,
152 'script': self
.script
,
153 'icon_resources': [(0, self
.icon_file
)],
154 'copyright': self
.copyright
156 options
= {'py2exe': {#'optimize': 2,
159 'excludes': self
.exclude_modules
,
160 'packages': self
.extra_modules
,
161 'dll_excludes': self
.exclude_dll
}
163 zipfile
= self
.zipfile_name
,
164 data_files
= extra_datas
,
165 dist_dir
= self
.dist_dir
168 #if os.path.isdir('build'): #Clean up build dir
169 # shutil.rmtree('build')
171 if __name__
== '__main__':
172 if operator
.lt(len(sys
.argv
), 2):
173 sys
.argv
.append('py2exe')
174 BuildExe().run() #Run generation
175 #raw_input("Press any key to continue") #Pause to let user see that things ends