Skip to content

Commit 744199e

Browse files
author
Ram Rachum
committed
-
1 parent 22b5ae2 commit 744199e

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

garlicsim_wx/py2exe_cruft/setup_extension.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,28 @@
3030
if path_to_add not in sys.path:
3131
sys.path.append(path_to_add)
3232

33+
def cute_find_module(module_name):
34+
'''tododoc'''
35+
current_module_name = module_name
36+
current_paths = sys.path
37+
38+
while '.' in current_module_name:
39+
(big_package_name, current_module_name) = \
40+
current_module_name.split('.', 1)
41+
big_package_path = imp.find_module(big_package_name, current_paths)[1]
42+
current_paths = [big_package_path]
43+
44+
return imp.find_module(current_module_name, current_paths)[1]
45+
3346

3447
def package_to_path(package):
3548
'''
3649
Given a package name, convert to path.
3750
38-
The path will be relative to the folder that contains the root packakge. So
39-
`package_to_path('numpy.core') == 'numpy/core'`.
51+
The path will be relative to the folder that contains the root package.
52+
53+
Example:
54+
package_to_path('numpy.core') == 'numpy/core'
4055
'''
4156
return package.replace('.', '/')
4257

@@ -187,16 +202,27 @@ def get_all_submodules(package_name):
187202
188203
This includes both modules and packages.
189204
190-
For example:
191-
`get_all_subpackages('numpy') == ['numpy.core', 'numpy.random', ...]`
205+
Example:
206+
207+
get_all_subpackages('numpy') == ['numpy.compat._inspect',
208+
'numpy.compat.setup', 'numpy.compat.setupscons', ... ]
192209
'''
193-
package_path = imp.find_module(package_name, sys.path)[1]
194-
return [module for (loader, module, is_package) in
195-
pkgutil.iter_modules([package_path], package_name + '.') if not is_package]
196-
197-
198-
g=get_all_submodules('numpy')
199-
0
210+
package_path = cute_find_module(package_name)
211+
212+
subpackage_names = [(package_name + '.' + m) for m in
213+
setuptools.find_packages(package_path)]
214+
215+
modules = []
216+
for subpackage_name in subpackage_names:
217+
subpackage_path = cute_find_module(subpackage_name)
218+
modules += [
219+
module for (loader, module, is_package) in
220+
pkgutil.iter_modules([subpackage_path], subpackage_name + '.')
221+
if not is_package
222+
]
223+
modules.append(subpackage_name)
224+
225+
return modules
200226

201227

202228
# This is a list of packages that should be included in the library, with all

0 commit comments

Comments
 (0)