rules.py 文件源码

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

项目:open-project-linter 作者: OpenNewsLabs 项目源码 文件源码
def guess_code_present(filepath):
    """Guess whether a file contains "code" or not. Structured text
    (as listed in NOT_CODE) does not count as "code", but anything else
    that the Pygments lexer-guesser finds a probable lexer for counts
    as "code" for these purposes.

    Parameters
    ----------
    filepath : string
        Path to the file that may contain code.
    Returns
    -------
    boolean
        True if the file contains "code" (as a best guess), False otherwise
    """
    text = get_file_text(filepath)
    filename = os.path.split(filepath)[1]
    try:
        lexer = lexers.guess_lexer_for_filename(filename, text)
        if lexer.name not in NOT_CODE:
            return True
        else:
            return False
    except lexers.ClassNotFound:
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号