如何在每个文件的Pylint中获取运行时间

时间:2018-05-25 09:53:38

标签: django pylint pylintrc

我在我的项目中使用了pylint,它运行时间超过1分钟,这对我来说太长了。如何才能获得项目中每个文件的具体运行时间?

这是我的研究:

The issue on the github

How to speed up pylint

你能就这个问题以及如何加快pylint提供一些建议吗?

提前致谢!!!!

1 个答案:

答案 0 :(得分:0)

我创建了一个新的检查器类并添加了打印句子以获得时间。我认为这不是最好的方式,我会做进一步的研究

from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker


class CustomTimeChecker(BaseChecker):
    """
    find the check type in the following url:
    https://github.com/PyCQA/pylint/blob/63eb8c4663a77d0caf2a842b716e4161f9763a16/pylint/checkers/typecheck.py
    """
    print(begin)
    __implements__ = IAstroidChecker
    name = 'import-time-checker'
    priority = -1

    def __init__(self, linter):
        super().__init__(linter)
        print('test In samuel !')

    def visit_importfrom(self, node):
        end = datetime.datetime.now()
         print('')

    def visit_import(self, node):
)

    def visit_attribute(self, node):
        end = datetime.datetime.now()
        print('        function Name  '+str(node.name)+ ' takes the time for '+ str(end - self.begin))

    def leave_functiondef(self, node):
        end = datetime.datetime.now()
        print('        function Name  '+str(node.name)+ ' takes the time for '+ str(end - self.begin))

    def leave_module(self, node):
        """
        Actual checks are implemented here
        """
        end = datetime.datetime.now()
        print('Leaving the module ' + str(node.name) +' when the time is '+str(end - self.begin))
        print('*'*40)
        # print(node.name)

    def visit_module(self, node):
        end = datetime.datetime.now()
        print('Entering the module ' + str(node.name) + ' when the time is' + str(end - self.begin))


def register(linter):
    linter.register_checker(CustomTimeChecker(linter))