def find_imports(fn, verbose, ignores): "Yields a list of the module names the file 'fn' depends on." ast, _ = parse_python_source(fn) found_imports = get_ast_imports(ast) if found_imports is None: raise StopIteration dn = dirname(fn) packroot = None for modname, rname, lname, lineno, _, _ in found_imports: islocal = False names = modname.split('.') if find_dotted(names, dn): # This is a local import, we need to find the root in order to # compute the absolute module name. if packroot is None: packroot = find_package_root(fn, ignores) if not packroot: logging.warning( "%d: Could not find package root for local import '%s' from '%s'." % (lineno, modname, fn)) continue reldir = dirname(fn)[len(packroot) + 1:] modname = '%s.%s' % (reldir.replace(os.sep, '.'), modname) islocal = True if rname is not None: modname = '%s.%s' % (modname, rname) yield (modname, lineno, islocal)
def find_imports(fn, verbose, ignores): "Yields a list of the module names the file 'fn' depends on." ast, _ = parse_python_source(fn) if ast is None: raise StopIteration found_imports = get_ast_imports(ast) if found_imports is None: raise StopIteration dn = dirname(fn) packroot = None for modname, rname, lname, lineno, _, _ in found_imports: islocal = False names = modname.split('.') if find_dotted(names, dn): # This is a local import, we need to find the root in order to # compute the absolute module name. if packroot is None: packroot = find_package_root(fn, ignores) if not packroot: logging.warning( "%d: Could not find package root for local import '%s' from '%s'." % (lineno, modname, fn)) continue reldir = dirname(fn)[len(packroot)+1:] modname = '%s.%s' % (reldir.replace(os.sep, '.'), modname) islocal = True if rname is not None: modname = '%s.%s' % (modname, rname) yield (modname, lineno, islocal)