de4ccd9919385ed21ca664a98229e5d74314cc8a
1 # This will create a dist directory containing the executable file, all the data
2 # directories. All Libraries will be bundled in executable file.
4 # Run the build process by entering 'pygame2exe.py' or
5 # 'python pygame2exe.py' in a console prompt.
7 # To build exe, python, pygame, and py2exe have to be installed. After
8 # building exe none of this libraries are needed.
11 from distutils
.core
import setup
13 from modulefinder
import Module
15 import sys
, os
, shutil
17 except ImportError, message
:
18 raise SystemExit, "Unable to load module. %s" % message
20 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
21 def copy_extensions(self
, extensions
):
22 #Get pygame default font
23 pygamedir
= os
.path
.split(pygame
.base
.__file
__)[0]
24 pygame_default_font
= os
.path
.join(pygamedir
, pygame
.font
.get_default_font())
26 #Add font to list of extension to be copied
27 extensions
.append(Module("pygame.font", pygame_default_font
))
28 py2exe
.build_exe
.py2exe
.copy_extensions(self
, extensions
)
33 self
.script
= "MyApps.py"
36 self
.project_name
= "MyApps"
39 self
.project_url
= "about:none"
42 self
.project_version
= "0.0"
44 #License of the program
45 self
.license
= "MyApps License"
48 self
.author_name
= "Me"
49 self
.author_email
= "example@example.com"
50 self
.copyright
= "Copyright (c) 2009 Me."
53 self
.project_description
= "MyApps Description"
55 #Icon file (None will use pygame default icon)
58 #Extra files/dirs copied to game
61 #Extra/excludes python modules
62 self
.extra_modules
= []
63 self
.exclude_modules
= []
66 self
.exclude_dll
= ['']
68 #Zip file name (None will bundle files in exe instead of zip file)
69 self
.zipfile_name
= None
74 ## Code from DistUtils tutorial at http://wiki.python.org/moin/Distutils/Tutorial
75 ## Originally borrowed from wxPython's setup and config files
77 path
= os
.path
.join(*args
)
78 return os
.path
.normpath(path
)
80 def find_data_files(self
, srcdir
, *wildcards
, **kw
):
81 # get a list of all files under the srcdir matching wildcards,
82 # returned in a format to be used for install_data
83 def walk_helper(arg
, dirname
, files
):
89 wc_name
= self
.opj(dirname
, wc
)
91 filename
= self
.opj(dirname
, f
)
93 if fnmatch
.fnmatch(filename
, wc_name
) and not os
.path
.isdir(filename
):
94 names
.append(filename
)
96 lst
.append( (dirname
, names
) )
99 recursive
= kw
.get('recursive', True)
101 os
.path
.walk(srcdir
, walk_helper
, (file_list
, wildcards
))
103 walk_helper((file_list
, wildcards
),
105 [os
.path
.basename(f
) for f
in glob
.glob(self
.opj(srcdir
, '*'))])
109 if os
.path
.isdir(self
.dist_dir
): #Erase previous destination dir
110 shutil
.rmtree(self
.dist_dir
)
112 #Use the default pygame icon, if none given
113 if self
.icon_file
== None:
114 path
= os
.path
.split(pygame
.__file
__)[0]
115 self
.icon_file
= os
.path
.join(path
, 'pygame.ico')
117 #List all data files to add
119 for data
in self
.extra_datas
:
120 if os
.path
.isdir(data
):
121 extra_datas
.extend(self
.find_data_files(data
, '*'))
123 extra_datas
.append(('.', [data
]))
126 cmdclass
= {'py2exe': pygame2exe
},
127 version
= self
.project_version
,
128 description
= self
.project_description
,
129 name
= self
.project_name
,
130 url
= self
.project_url
,
131 author
= self
.author_name
,
132 author_email
= self
.author_email
,
133 license
= self
.license
,
137 'script': self
.script
,
138 'icon_resources': [(0, self
.icon_file
)],
139 'copyright': self
.copyright
141 options
= {'py2exe': {'optimize': 2, 'bundle_files': 1, 'compressed': True, \
142 'excludes': self
.exclude_modules
, 'packages': self
.extra_modules
, \
143 'dll_excludes': self
.exclude_dll
} },
144 zipfile
= self
.zipfile_name
,
145 data_files
= extra_datas
,
146 dist_dir
= self
.dist_dir
149 if os
.path
.isdir('build'): #Clean up build dir
150 shutil
.rmtree('build')
152 if __name__
== '__main__':
153 if operator
.lt(len(sys
.argv
), 2):
154 sys
.argv
.append('py2exe')
155 BuildExe().run() #Run generation
156 raw_input("Press any key to continue") #Pause to let user see that things ends