0

I am using the pylint in my project and it runs over 1min which is too long for me .How can I get the specific running time of each file in my project?

Here is my research:

The issue on the github

How to speed up pylint

Can you give me some advice about the issue and how to speed up the pylint ?

thanks in advance !!!!

Deft-pawN
  • 943
  • 10
  • 12

2 Answers2

1

I create a new checker class and add the print sentences to get the time. I think it is not the best way and I will do the further research

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))
Deft-pawN
  • 943
  • 10
  • 12
1

You can speed up pylint by spawning multiple processes and checking files in parallel. This functionality is exposed via the -j command-line parameter. If the provided number is 0, then the total number of CPUs will be autodetected and used. From the output of 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]

There are some limitations in running checks in parallel in the current implementation. It is not possible to use custom plugins (i.e. --load-plugins option), nor it is not possible to use initialization hooks (i.e. the --init-hook option).

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378