1 """macmodulefinder - Find modules used in a script. Only slightly
2 mac-specific, really."""
10 # This will work if we are frozen ourselves
13 # And this will work otherwise
14 _FREEZEDIR
=os
.path
.join(sys
.prefix
, ':Tools:freeze')
15 sys
.path
.insert(0, _FREEZEDIR
)
19 # Modules that must be included, and modules that need not be included
20 # (but are if they are found)
22 MAC_INCLUDE_MODULES
=['site', 'exceptions']
23 MAC_MAYMISS_MODULES
=['posix', 'os2', 'nt', 'dos', 'dospath', 'nturl2path', 'pwd', 'sitecustomize']
26 Missing
="macmodulefinder.Missing"
28 class Module(modulefinder
.Module
):
31 """Return type of module"""
40 class ModuleFinder(modulefinder
.ModuleFinder
):
42 def add_module(self
, fqname
):
43 if self
.modules
.has_key(fqname
):
44 return self
.modules
[fqname
]
45 self
.modules
[fqname
] = m
= Module(fqname
)
48 def process(program
, modules
=[], module_files
= [], debug
=0):
51 # Add the standard modules needed for startup
53 modules
= modules
+ MAC_INCLUDE_MODULES
55 # search the main source for directives
57 extra_modules
, exclude_modules
, extra_path
= \
58 directives
.findfreezedirectives(program
)
59 for m
in extra_modules
:
62 module_files
.append(m
)
65 # collect all modules of the program
67 dir = os
.path
.dirname(program
)
68 path
[0] = dir # "current dir"
69 path
= extra_path
+ path
71 # Create the module finder and let it do its work
73 modfinder
= ModuleFinder(path
,
74 excludes
=exclude_modules
, debug
=debug
)
76 modfinder
.import_hook(m
)
77 for m
in module_files
:
78 modfinder
.load_file(m
)
79 modfinder
.run_script(program
)
80 module_dict
= modfinder
.modules
82 # Tell the user about missing modules
84 maymiss
= exclude_modules
+ MAC_MAYMISS_MODULES
85 for m
in modfinder
.badmodules
.keys():
91 # Warn the user about unused builtins
93 for m
in sys
.builtin_module_names
:
94 if m
in ('__main__', '__builtin__'):
96 elif not module_dict
.has_key(m
):
99 elif module_dict
[m
].gettype() != 'builtin':
100 # XXXX Can this happen?