【问题标题】:How to get the running time in the Pylint of each file如何在每个文件的 Pylint 中获取运行时间
【发布时间】:2018-05-25 09:53:38
【问题描述】:

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

这是我的研究:

The issue on the github

How to speed up pylint

你能给我一些关于这个问题以及如何加快 pylint 的建议吗?

提前谢谢!!!!

【问题讨论】:

    标签: django pylint pylintrc


    【解决方案1】:

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

    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))
    

    【讨论】:

      【解决方案2】:

      您可以通过生成多个进程和checking files in parallel 来加速pylint。此功能通过-j 命令行参数公开。如果提供的数字是0,那么将自动检测并使用 CPU 的总数。来自pylint --help的输出:

      -j <n-processes>, --jobs=<n-processes>
          Use multiple processes to speed up Pylint. Specifying
          0 will auto-detect the number of processors available
          to use. [current: 1]
      

      在当前实现中并行运行检查存在一些限制。不能使用自定义插件(即--load-plugins 选项),也不能使用初始化挂钩(即--init-hook 选项)。

      【讨论】:

        猜你喜欢
        • 2020-06-03
        • 2021-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-23
        相关资源
        最近更新 更多