1- # tododoc: document extensively
1+ # Copyright 2009-2010 Ram Rachum. No part of this program may be used, copied
2+ # or distributed without explicit written permission from Ram Rachum.
3+
4+ '''
5+ Module for packaging garlicsim_wx as executable using py2exe.
6+
7+ Normally the contents of this module would be in setup.py; But py2exe introduces
8+ so much cruft, and I wanted to keep it away from my setup.py. So setup.py
9+ imports this module when it gets a `py2exe` command. This module should not be
10+ used otherwise.
11+
12+ This module assumes that the `garlicsim` and `garlicsim_lib` folders are
13+ alongside the `garlicsim_wx` folder, as in the official git repo of GarlicSim.
14+ '''
215
316import setuptools
417import py2exe
518import imp
619import sys , os .path , glob
720
8- path_to_garlicsim = os .path .abspath ('../../garlicsim' )
9- path_to_garlicsim_lib = os .path .abspath ('../../garlicsim_lib' )
21+ # This module is meant to be imported from the garlicsim_wx setup.py file, and
22+ # should not be used otherwise:
23+ assert any ('setup.py' in s for s in sys .argv )
24+
25+ path_to_garlicsim = os .path .abspath ('../garlicsim' )
26+ path_to_garlicsim_lib = os .path .abspath ('../garlicsim_lib' )
1027paths_to_add = [path_to_garlicsim , path_to_garlicsim_lib ]
1128for path_to_add in paths_to_add :
1229 if path_to_add not in sys .path :
1330 sys .path .append (path_to_add )
1431
1532
1633def package_to_path (package ):
34+ '''
35+ Given a package name, convert to path.
36+
37+ The path will be relative to the folder that contains the root packakge. So
38+ `package_to_path('numpy.core') == 'numpy/core'`.
39+ '''
1740 return package .replace ('.' , '/' )
1841
1942
2043def get_garlicsim_packages ():
44+ '''
45+ Get all the packages in garlicsim.
46+
47+ This returns an answer in the form: ['garlicsim.data_structures',
48+ 'garlicsim.bootstrap', 'garlicsim.misc', ...]
49+ '''
2150 return ['garlicsim.' + p for p
22- in setuptools .find_packages ('../../ garlicsim/garlicsim' )] + \
51+ in setuptools .find_packages ('../garlicsim/garlicsim' )] + \
2352 ['garlicsim' ]
2453
2554garlicsim_packages = get_garlicsim_packages ()
2655
2756
2857def get_garlicsim_lib_packages ():
58+ '''
59+ Get all the packages in garlicsim_lib.
60+
61+ This returns an answer in the form: ['garlicsim_lib.simpacks.life',
62+ 'garlicsim_lib.simpacks.prisoner', ...]
63+ '''
2964 return ['garlicsim_lib.' + p for p
30- in setuptools .find_packages ('../../ garlicsim_lib/garlicsim_lib' )] + \
65+ in setuptools .find_packages ('../garlicsim_lib/garlicsim_lib' )] + \
3166 ['garlicsim_lib' ]
3267
3368garlicsim_lib_packages = get_garlicsim_lib_packages ()
3469
3570
3671def get_garlicsim_wx_packages ():
72+ '''
73+ Get all the packages in garlicsim_wx.
74+
75+ This returns an answer in the form: ['garlicsim_wx.frame',
76+ 'garlicsim_wx.widgets', 'garlicsim_wx.misc', ...]
77+ '''
3778 return ['garlicsim_wx.' + p for p
38- in setuptools .find_packages ('../ garlicsim_wx' )] + \
79+ in setuptools .find_packages ('garlicsim_wx' )] + \
3980 ['garlicsim_wx' ]
4081
4182garlicsim_wx_packages = get_garlicsim_wx_packages ()
@@ -45,7 +86,8 @@ def get_garlicsim_data_files():
4586 total_data_files = []
4687 for package in garlicsim_packages :
4788 path = package_to_path (package )
48- all_files_and_folders = glob .glob (path_to_garlicsim + '/' + path + '/*' )
89+ all_files_and_folders = \
90+ glob .glob (path_to_garlicsim + '/' + path + '/*' )
4991 data_files = [f for f in all_files_and_folders if
5092 (not '.py' in f [4 :]) and (not os .path .isdir (f ))]
5193 total_data_files .append (('lib/' + path , data_files ))
@@ -56,7 +98,8 @@ def get_garlicsim_lib_data_files():
5698 total_data_files = []
5799 for package in garlicsim_lib_packages :
58100 path = package_to_path (package )
59- all_files_and_folders = glob .glob (path_to_garlicsim + '/' + path + '/*' )
101+ all_files_and_folders = \
102+ glob .glob (path_to_garlicsim_lib + '/' + path + '/*' )
60103 data_files = [f for f in all_files_and_folders if
61104 (not '.py' in f [4 :]) and (not os .path .isdir (f ))]
62105 total_data_files .append (('lib/' + path , data_files ))
@@ -104,7 +147,7 @@ def get_all_subpackages(package_name):
104147 return [
105148 (package_name + '.' + m ) for m in
106149 setuptools .find_packages (
107- imp .find_module (package_name )[1 ]
150+ imp .find_module (package_name , sys . path )[1 ]
108151 )
109152 ]
110153
0 commit comments