(filename, package_root)
return imports
Given a filename, returns a list of modules imported by the file
Given a filename, returns a list of modules imported by the file
Given a filename returns a list of modules imported by the file
def imported_modules(filename, package_root):
    """
    Given a filename, returns a list of modules imported by the file
    """
    try:
        fd = open(filename, 'rt')
        tree = ast.parse(fd.read(), filename=filename)
        fd.close()
    except IOError as e:
        raise SpiderIOError(e)

    imports = set([])
    for item in tree.body:
        if isinstance(item, (ast.Import, ast.ImportFrom)):
            imports.add(
                Import(item, filename=filename, package_root=package_root)
            )
    return imports
def imported_modules ( filename , package_root ) : try : fd = open ( filename , 'rt' ) tree = ast . parse ( fd . read ( ) , filename = filename ) fd . close ( ) except IOError as e : raise SpiderIOError ( e ) imports = set ( [ ] ) for item in tree . body : if isinstance ( item , ( ast . Import , ast . ImportFrom ) ) : imports . add ( Import ( item , filename = filename , package_root = package_root ) ) return imports