运行" pylint" Windows Machine上的多个Python文件上的工具

时间:2015-11-20 13:08:30

标签: windows pylint multiple-files

我想跑#34; pylint"一个目录下的多个python文件的工具。 我想要一个包含所有Python文件的综合报告。

我能够单独运行一个python文件,但想要在一堆文件上运行。 请帮助解决相同的命令。

2 个答案:

答案 0 :(得分:0)

我不是Windows用户,但不是" pylint目录/ * .py"够了吗?

如果目录是一个包(在PYTHONPATH中),你也可以运行" pylint目录"

答案 1 :(得分:0)

有人写了一个wrapper in python 2来处理这个

代码:

#! /usr/bin/env python
'''
Module that runs pylint on all python scripts found in a directory tree..
'''

import os
import re
import sys

total = 0.0
count = 0

def check(module):
  '''
  apply pylint to the file specified if it is a *.py file
  '''
  global total, count

  if module[-3:] == ".py":

    print "CHECKING ", module
    pout = os.popen('pylint %s'% module, 'r')
    for line in pout:
      if  re.match("E....:.", line):
        print line
      if "Your code has been rated at" in line:
        print line
         score = re.findall("\d+.\d\d", line)[0]
        total += float(score)
        count += 1

if __name__ == "__main__":
  try:
    print sys.argv   
    BASE_DIRECTORY = sys.argv[1]
  except IndexError:
    print "no directory specified, defaulting to current working directory"
    BASE_DIRECTORY = os.getcwd()

  print "looking for *.py scripts in subdirectories of ", BASE_DIRECTORY 
  for root, dirs, files in os.walk(BASE_DIRECTORY):
    for name in files:
      filepath = os.path.join(root, name)
      check(filepath)

  print "==" * 50
  print "%d modules found"% count
  print "AVERAGE SCORE = %.02f"% (total / count)