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']
23 MAC_MAYMISS_MODULES
=['posix', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
24 'win32api', 'ce', '_winreg',
25 'nturl2path', 'pwd', 'sitecustomize',
27 'riscos', 'riscosenviron', 'riscospath'
31 Missing
="macmodulefinder.Missing"
33 class Module(modulefinder
.Module
):
36 """Return type of module"""
45 class ModuleFinder(modulefinder
.ModuleFinder
):
47 def add_module(self
, fqname
):
48 if self
.modules
.has_key(fqname
):
49 return self
.modules
[fqname
]
50 self
.modules
[fqname
] = m
= Module(fqname
)
53 def process(program
, modules
=None, module_files
=None, debug
=0):
56 if module_files
is None:
60 # Add the standard modules needed for startup
62 modules
= modules
+ MAC_INCLUDE_MODULES
64 # search the main source for directives
66 extra_modules
, exclude_modules
, optional_modules
, extra_path
= \
67 directives
.findfreezedirectives(program
)
68 for m
in extra_modules
:
71 module_files
.append(m
)
74 # collect all modules of the program
76 dir = os
.path
.dirname(program
)
77 path
[0] = dir # "current dir"
78 path
= extra_path
+ path
80 # Create the module finder and let it do its work
82 modfinder
= ModuleFinder(path
,
83 excludes
=exclude_modules
, debug
=debug
)
85 modfinder
.import_hook(m
)
86 for m
in module_files
:
87 modfinder
.load_file(m
)
88 modfinder
.run_script(program
)
89 module_dict
= modfinder
.modules
91 # Tell the user about missing modules
93 maymiss
= exclude_modules
+ optional_modules
+ MAC_MAYMISS_MODULES
94 for m
in modfinder
.badmodules
.keys():
100 # Warn the user about unused builtins
102 for m
in sys
.builtin_module_names
:
103 if m
in ('__main__', '__builtin__'):
105 elif not module_dict
.has_key(m
):
108 elif module_dict
[m
].gettype() != 'builtin':
109 # XXXX Can this happen?
112 return module_dict
, missing