diff options
-rw-r--r-- | pylint/checkers/__init__.py | 12 | ||||
-rw-r--r-- | pylint/checkers/base.py | 11 | ||||
-rw-r--r-- | pylint/checkers/raw_metrics.py | 13 | ||||
-rw-r--r-- | pylint/utils/utils.py | 18 |
4 files changed, 45 insertions, 9 deletions
diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index d9ed5833c..35831e4c4 100644 --- a/pylint/checkers/__init__.py +++ b/pylint/checkers/__init__.py @@ -48,10 +48,10 @@ messages nor reports. XXX not true, emit a 07 report ! from pylint.checkers.base_checker import BaseChecker, BaseTokenChecker from pylint.checkers.deprecated import DeprecatedMixin from pylint.checkers.mapreduce_checker import MapReduceMixin -from pylint.utils import register_plugins +from pylint.utils import diff_string, register_plugins -def table_lines_from_stats(stats, _, columns): +def table_lines_from_stats(stats, old_stats, columns): """get values listed in <columns> from <stats> and <old_stats>, and return a formated list of values, designed to be given to a ureport.Table object @@ -60,7 +60,13 @@ def table_lines_from_stats(stats, _, columns): for m_type in columns: new = stats[m_type] new = "%.3f" % new if isinstance(new, float) else str(new) - lines += (m_type.replace("_", " "), new, "NC", "NC") + old = old_stats.get(m_type) + if old is not None: + diff_str = diff_string(old, new) + old = format(old) + else: + old, diff_str = "NC", "NC" + lines += (m_type.replace("_", " "), new, old, diff_str) return lines diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index c27a91180..9cf68083a 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -386,7 +386,7 @@ def _has_abstract_methods(node): return len(utils.unimplemented_abstract_methods(node)) > 0 -def report_by_type_stats(sect, stats, _): +def report_by_type_stats(sect, stats, old_stats): """make a report of * percentage of different types documented @@ -415,11 +415,16 @@ def report_by_type_stats(sect, stats, _): lines = ("type", "number", "old number", "difference", "%documented", "%badname") for node_type in ("module", "class", "method", "function"): new = stats[node_type] + old = old_stats.get(node_type, None) + if old is not None: + diff_str = lint_utils.diff_string(old, new) + else: + old, diff_str = "NC", "NC" lines += ( node_type, str(new), - "NC", - "NC", + str(old), + diff_str, nice_stats[node_type].get("percent_documented", "0"), nice_stats[node_type].get("percent_badname", "0"), ) diff --git a/pylint/checkers/raw_metrics.py b/pylint/checkers/raw_metrics.py index b713c4bf6..bb3a519d4 100644 --- a/pylint/checkers/raw_metrics.py +++ b/pylint/checkers/raw_metrics.py @@ -20,10 +20,12 @@ from pylint.checkers import BaseTokenChecker from pylint.exceptions import EmptyReportError from pylint.interfaces import ITokenChecker from pylint.reporters.ureports.nodes import Table +from pylint.utils import diff_string -def report_raw_stats(sect, stats, _): - """calculate percentage of code / doc / comment / empty""" +def report_raw_stats(sect, stats, old_stats): + """calculate percentage of code / doc / comment / empty + """ total_lines = stats["total_lines"] if not total_lines: raise EmptyReportError() @@ -33,7 +35,12 @@ def report_raw_stats(sect, stats, _): key = node_type + "_lines" total = stats[key] percent = float(total * 100) / total_lines - lines += (node_type, str(total), "%.2f" % percent, "NC", "NC") + old = old_stats.get(key, None) + if old is not None: + diff_str = diff_string(old, total) + else: + old, diff_str = "NC", "NC" + lines += (node_type, str(total), "%.2f" % percent, str(old), diff_str) sect.append(Table(children=lines, cols=5, rheaders=1)) diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index 4b1d7566c..354d5a47a 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -34,6 +34,24 @@ def normalize_text(text, line_len=DEFAULT_LINE_LENGTH, indent=""): ) +CMPS = ["=", "-", "+"] + +# py3k has no more cmp builtin +if sys.version_info >= (3, 0): + + def cmp(a, b): # pylint: disable=redefined-builtin + return (a > b) - (a < b) + + +def diff_string(old, new): + """given an old and new int value, return a string representing the + difference + """ + diff = abs(old - new) + diff_str = "%s%s" % (CMPS[cmp(old, new)], diff and ("%.2f" % diff) or "") + return diff_str + + def get_module_and_frameid(node): """return the module name and the frame id in the module""" frame = node.frame() |