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', 'macfsn']
23 MAC_MAYMISS_MODULES
=['posix', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
25 'nturl2path', 'pwd', 'sitecustomize',
29 Missing
="macmodulefinder.Missing"
31 class Module(modulefinder
.Module
):
34 """Return type of module"""
43 class ModuleFinder(modulefinder
.ModuleFinder
):
45 def add_module(self
, fqname
):
46 if self
.modules
.has_key(fqname
):
47 return self
.modules
[fqname
]
48 self
.modules
[fqname
] = m
= Module(fqname
)
51 def process(program
, modules
=None, module_files
=None, debug
=0):
54 if module_files
is None:
58 # Add the standard modules needed for startup
60 modules
= modules
+ MAC_INCLUDE_MODULES
62 # search the main source for directives
64 extra_modules
, exclude_modules
, optional_modules
, extra_path
= \
65 directives
.findfreezedirectives(program
)
66 for m
in extra_modules
:
69 module_files
.append(m
)
72 # collect all modules of the program
74 dir = os
.path
.dirname(program
)
75 path
[0] = dir # "current dir"
76 path
= extra_path
+ path
78 # Create the module finder and let it do its work
80 modfinder
= ModuleFinder(path
,
81 excludes
=exclude_modules
, debug
=debug
)
83 modfinder
.import_hook(m
)
84 for m
in module_files
:
85 modfinder
.load_file(m
)
86 modfinder
.run_script(program
)
87 module_dict
= modfinder
.modules
89 # Tell the user about missing modules
91 maymiss
= exclude_modules
+ optional_modules
+ MAC_MAYMISS_MODULES
92 for m
in modfinder
.badmodules
.keys():
98 # Warn the user about unused builtins
100 for m
in sys
.builtin_module_names
:
101 if m
in ('__main__', '__builtin__'):
103 elif not module_dict
.has_key(m
):
106 elif module_dict
[m
].gettype() != 'builtin':
107 # XXXX Can this happen?
110 return module_dict
, missing