1717import py2exe
1818import imp
1919import sys , os .path , glob
20+ import pkgutil
2021
2122# This module is meant to be imported from the garlicsim_wx setup.py file, and
2223# should not be used otherwise:
@@ -83,6 +84,13 @@ def get_garlicsim_wx_packages():
8384
8485
8586def get_garlicsim_data_files ():
87+ '''
88+ Get garlicsim's data files.
89+
90+ This returns a list of tuples, where the second item in each tuple is a list
91+ of files and the first item is the path to which these files should be
92+ copied when doing the py2exe packaging.
93+ '''
8694 total_data_files = []
8795 for package in garlicsim_packages :
8896 path = package_to_path (package )
@@ -95,6 +103,13 @@ def get_garlicsim_data_files():
95103
96104
97105def get_garlicsim_lib_data_files ():
106+ '''
107+ Get garlicsim_lib's data files.
108+
109+ This returns a list of tuples, where the second item in each tuple is a list
110+ of files and the first item is the path to which these files should be
111+ copied when doing the py2exe packaging.
112+ '''
98113 total_data_files = []
99114 for package in garlicsim_lib_packages :
100115 path = package_to_path (package )
@@ -107,6 +122,13 @@ def get_garlicsim_lib_data_files():
107122
108123
109124def get_garlicsim_wx_data_files ():
125+ '''
126+ Get garlicsim_wx's data files.
127+
128+ This returns a list of tuples, where the second item in each tuple is a list
129+ of files and the first item is the path to which these files should be
130+ copied when doing the py2exe packaging.
131+ '''
110132 total_data_files = []
111133 for package in garlicsim_wx_packages :
112134 path = package_to_path (package )
@@ -118,6 +140,13 @@ def get_garlicsim_wx_data_files():
118140
119141
120142def get_dlls_and_stuff ():
143+ '''
144+ Get some miscellaneous files that need to be copied to py2exe_dist.
145+
146+ This returns a list of tuples, where the second item in each tuple is a list
147+ of files and the first item is the path to which these files should be
148+ copied when doing the py2exe packaging.
149+ '''
121150 total_data_files = []
122151 path_to_folder = './py2exe_cruft/dlls_and_stuff'
123152 folders_to_do = [path_to_folder ]
@@ -138,12 +167,29 @@ def get_dlls_and_stuff():
138167
139168
140169def get_all_data_files ():
141- '''For use in py2exe only.tododoc'''
170+ '''
171+ Get all the data files that need to be copied to py2exe_dist.
172+
173+ This includes the data files for the `garlicsim`, `garlicsim_lib` and
174+ `garlicsim_wx` packages, and some miscellaneous data files.
175+
176+ This returns a list of tuples, where the second item in each tuple is a list
177+ of files and the first item is the path to which these files should be
178+ copied when doing the py2exe packaging.
179+ '''
142180 return get_garlicsim_data_files () + get_garlicsim_lib_data_files () + \
143181 get_garlicsim_wx_data_files () + get_dlls_and_stuff ()
144182
145183
146- def get_all_subpackages (package_name ):
184+ def get_all_submodules (package_name ):
185+ '''
186+ Get all submodules of a package, recursively.
187+
188+ This includes both modules and packages.
189+
190+ For example:
191+ `get_all_subpackages('numpy') == ['numpy.core', 'numpy.random', ...]`
192+ '''
147193 return [
148194 (package_name + '.' + m ) for m in
149195 setuptools .find_packages (
@@ -152,6 +198,16 @@ def get_all_subpackages(package_name):
152198 ]
153199
154200
201+ def get_strict_modules (package_name ):
202+ '''tododoc'''
203+ package_path = imp .find_module (package_name , sys .path )[1 ]
204+ return [module for (loader , module , is_package ) in
205+ pkgutil .iter_modules (path , package_name + '.' ) if not is_package ]
206+
207+
208+ # This is a list of packages that should be included in the library, with all
209+ # their subpackages. In theory, the `packages` option of py2exe should take care
210+ # of it, but it has bugs in it so we're doing this ourselves.
155211packages_to_include_with_all_subpackages = [
156212
157213 'garlicsim' , 'garlicsim_lib' ,
@@ -161,6 +217,7 @@ def get_all_subpackages(package_name):
161217]
162218
163219
220+ # List of modules to be included in the library.
164221includes = reduce (
165222 list .__add__ ,
166223 [get_all_subpackages (package_name ) for package_name in \
@@ -169,7 +226,11 @@ def get_all_subpackages(package_name):
169226
170227
171228py2exe_kwargs = {
229+
230+ # We're giving a less nerdy description here, because this will be shown on
231+ # the executable, where non-nerds might see it:
172232 'description' : 'Pythonic framework for computer simulations' ,
233+
173234 'windows' : [
174235 {
175236 'script' : 'py2exe_cruft/GarlicSim.py' ,
@@ -181,25 +242,20 @@ def get_all_subpackages(package_name):
181242 ]
182243 }
183244 ],
184- 'zipfile' : 'lib/library.zip' , #tododoc: probably cancel
185245 'data_files' : get_all_data_files (),
246+
247+ # We don't really have a zipfile, this is the path to the library folder:
248+ 'zipfile' : 'lib/library.zip' ,
249+ # Keep in mind that this `library.zip` filename here will simply be ignored.
250+
186251 'options' : {
187252 'py2exe' : {
188253 'dist_dir' : 'py2exe_dist' ,
189- 'skip_archive' : True ,
190-
191- # tododoc.Here you put packages you want py2exe to include with all
192- # subpackages. Problem is, there's a bug in py2exe which will make
193- # it think a non-package directory is a package if it contains a
194- # package within it. Then it'll get listed as a package, and when
195- # import time comes the script will fail.
196254
197- # So there's a danger for us here: For example, we can't include
198- # `numpy` because it has some `tests` folder which falls under this
199- # bug.
255+ # We prefer to have all the files in a folder instead of a zip file.
256+ 'skip_archive' : True ,
200257
201258 'includes' : includes ,
202-
203259 }
204260 }
205261}
0 commit comments