def chase_imports(self): modules = set() queue = [self.file_name_root] for name in queue: try: modobj = filepath.try_import(module_name=name) file = getattr(modobj, '__file__', None) if not file: sys.stderr.write("Module object %s missing __name__ att\n" % name) raise Exception (base, _) = os.path.splitext(file) m = ModuleCompiler(base + '.py') if file not in (m.file, m.pycfile): sys.stderr.write("Module cannot be parsed: %s\n" % file) raise Exception if not os.path.exists(m.file): sys.stderr.write("Module does not exist: %s\n" % m.file) raise Exception if not filepath.is_writable(m.pycfile): sys.stderr.write("Path cannot be written to: %s\n" % m.pycfile) else: modules.add(m) found = m.find_imports() for f in found: if f not in queue: queue.append(f) except: raise return list(modules)
def find_modules(self, path): modules = [] for (dir, dirs, files) in os.walk(path): for f in files: f = os.path.join(dir, f) (_, e) = os.path.splitext(f) if e == '.py': pyc = f + 'c' if not filepath.is_writable(pyc): sys.stderr.write("Path cannot be written to: %s\n" % pyc) else: modules.append(f) modules = list(set(modules)) return modules