pythonのソースコードを調べる

Cファイルからインクルードしているヘッダファイルを調べる

def iter_docs(file):
    """
    指定したCファイルにインクルードされているヘッダファイルを返す
    """
    for line in file:
        if line.startswith("#include"):
            #include文に続くヘッダファイル名を抜き出す
            m = re.search(r'\".*\"',line)
            if m != None:
                yield m.group().strip("\"").split("/")[-1]

def get_hlist(path_name):
    """
    指定されたCファイルのpath_nameをもらってそのCファイルにインクルード
    されているヘッダファイルファイルをリストにして返す。
    """
    h_file_list = []
    for path in path_name:
        with open(path) as f:
            for hf in iter_docs(f):
                h_file_list.append(hf)
    h_file_list = list(set(h_file_list))
    print("--head file---------------")
    print("上位10位まで表示")
    for v in h_file_list[:10]:
        print(v)
    print("len=",len(h_file_list))
    return h_file_list


    <結果>
    最初10行まで表示
    sha256module.c.h
    unicodedefs.h
    mappings_hk.h
    ucs4lib.h
    datetime.h
    code.h
    grammar.h
    rotatingtree.h
    fileobject.h
    float.h