base.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:django-migration-checker 作者: rev112 项目源码 文件源码
def extract_dependencies(file_path):
    """
    Parse the file contents and return the list of dependencies.
    """
    with open(file_path) as fh:
        file_contents = fh.read()
    match = re.search(r"""^\s+dependencies [^\[]+
                          \[
                          ([^\]]*)
                          \]""",
                      file_contents,
                      flags=re.VERBOSE | re.MULTILINE)
    if not match:
        return []

    deps = match.group(1).strip()
    if not deps:
        return []

    match_iter = re.finditer(r"""\(
                                 '([^']+)'
                                 ,\s*
                                 '([^_][^']+)'
                                 \)""",
                             deps,
                             flags=re.VERBOSE)
    return [(match.group(1), match.group(2)) for match in match_iter]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号