| 966 | | pylint_value = 0 |
|---|
| 967 | | cnt = 0 |
|---|
| 968 | | |
|---|
| 969 | | # wbg: switching cwd so that pylint works correctly regarding |
|---|
| 970 | | # running it on individual modules |
|---|
| | 965 | # Exclude __init__.py files from score as they cause pylint |
|---|
| | 966 | # to fail with ImportError "Unable to find module for %s in %s". |
|---|
| | 967 | files_to_lint = filter(lambda name: not name.endswith('__init__.py'), |
|---|
| | 968 | get_files_of_type(files_list, 'module')) |
|---|
| | 969 | |
|---|
| | 970 | # Switching cwd so that pylint works correctly regarding |
|---|
| | 971 | # running it on individual modules. |
|---|
| 979 | | for pyfile in get_files_of_type(files_list, 'module'): |
|---|
| 980 | | # wbg: because we change the working dir, we can use relative |
|---|
| 981 | | # paths which pylint is happier about. |
|---|
| 982 | | # fullpath = os.path.join(package_dir, pyfile) |
|---|
| 983 | | fullpath = pyfile |
|---|
| 984 | | path, filename = os.path.split(fullpath) |
|---|
| 985 | | module, ext = os.path.splitext(filename) |
|---|
| 986 | | |
|---|
| 987 | | self.cheesecake.log.debug("Running pylint on file " + fullpath) |
|---|
| 988 | | rc, output = run_cmd("pylint %s %s" % (self.pylint_args, fullpath)) |
|---|
| 989 | | if rc: |
|---|
| 990 | | self.cheesecake.log.debug("encountered an error (%d)." % rc) |
|---|
| 991 | | continue |
|---|
| 992 | | |
|---|
| 993 | | score_line = output.split("\n")[-3] |
|---|
| 994 | | s = re.search(r" (\d+\.\d+)/10", score_line) |
|---|
| 995 | | |
|---|
| 996 | | # We only take positive scores into account |
|---|
| 997 | | if s: |
|---|
| 998 | | score = s.group(1) |
|---|
| 999 | | if score == "0.00": |
|---|
| 1000 | | self.cheesecake.log.debug("ignoring 0.00 score.") |
|---|
| 1001 | | continue |
|---|
| 1002 | | else: |
|---|
| 1003 | | self.cheesecake.log.debug("pylint score for module %s: %s" % (module, score)) |
|---|
| 1004 | | pylint_value += float(score) |
|---|
| 1005 | | cnt += 1 |
|---|
| 1006 | | |
|---|
| 1007 | | # wbg: switching back to the original cwd in case that's important |
|---|
| | 981 | self.cheesecake.log.debug("Running pylint on files: %s." % ' '.join(files_to_lint)) |
|---|
| | 982 | |
|---|
| | 983 | rc, output = run_cmd("pylint %s %s" % (' '.join(files_to_lint), self.pylint_args)) |
|---|
| | 984 | if rc: |
|---|
| | 985 | self.cheesecake.log.debug("encountered an error (%d):\n***\n%s\n***\n" % (rc, output)) |
|---|
| | 986 | |
|---|
| | 987 | # Switching back to the original cwd. |
|---|
| 1010 | | avg_score = 0 |
|---|
| 1011 | | if cnt: |
|---|
| 1012 | | avg_score = float(pylint_value)/float(cnt) |
|---|
| 1013 | | |
|---|
| 1014 | | self.value = int(ceil(avg_score/10.0 * self.max_value)) |
|---|
| 1015 | | self.details = "average pylint score is %.2f out of 10" % avg_score |
|---|
| | 990 | # Extract score from pylint output. |
|---|
| | 991 | score_line = output.split("\n")[-3] |
|---|
| | 992 | s = re.search(r" (\d+\.\d+)/10", score_line) |
|---|
| | 993 | |
|---|
| | 994 | # Scores below 0 are treated as 0. |
|---|
| | 995 | pylint_score = 0 |
|---|
| | 996 | if s: |
|---|
| | 997 | pylint_score = float(s.group(1)) |
|---|
| | 998 | |
|---|
| | 999 | self.value = int(ceil(pylint_score/10.0 * self.max_value)) |
|---|
| | 1000 | self.details = "pylint score was %.2f out of 10" % pylint_score |
|---|