From bc6be1c56f04575c9f96f09f83f6c2e83c0dcd46 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Thu, 27 Nov 2014 12:38:58 +0100 Subject: [PATCH] Fixed some pylint violations. --- gitinspector/blame.py | 30 ++++++++++++++++-------------- gitinspector/clone.py | 2 -- gitinspector/filtering.py | 6 ++++-- gitinspector/metrics.py | 38 ++++++++++++++++++++------------------ 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/gitinspector/blame.py b/gitinspector/blame.py index b589afe..eb1bb58 100644 --- a/gitinspector/blame.py +++ b/gitinspector/blame.py @@ -61,7 +61,9 @@ class BlameThread(threading.Thread): self.blames = blames self.filename = filename - def __clear_blamechunk_information__(self): + self.is_inside_comment = False + + def __clear_blamechunk_info__(self): self.blamechunk_email = None self.blamechunk_is_last = False self.blamechunk_is_prior = False @@ -101,26 +103,25 @@ class BlameThread(threading.Thread): rows = git_blame_r.readlines() git_blame_r.close() - self.is_inside_comment = False - self.__clear_blamechunk_information__() + self.__clear_blamechunk_info__() for j in range(0, len(rows)): row = rows[j].decode("utf-8", "replace").strip() - lr = row.split(" ", 2) + keyval = row.split(" ", 2) if self.blamechunk_is_last: self.__handle_blamechunk_content__(row) - self.__clear_blamechunk_information__() - elif lr[0] == "boundary": + self.__clear_blamechunk_info__() + elif keyval[0] == "boundary": self.blamechunk_is_prior = True - elif lr[0] == "author-mail": - self.blamechunk_email = lr[1].lstrip("<").rstrip(">") - elif lr[0] == "author-time": - self.blamechunk_time = datetime.date.fromtimestamp(int(lr[1])) - elif lr[0] == "filename": + elif keyval[0] == "author-mail": + self.blamechunk_email = keyval[1].lstrip("<").rstrip(">") + elif keyval[0] == "author-time": + self.blamechunk_time = datetime.date.fromtimestamp(int(keyval[1])) + elif keyval[0] == "filename": self.blamechunk_is_last = True - elif Blame.is_revision(lr[0]): - self.blamechunk_revision = lr[0] + elif Blame.is_revision(keyval[0]): + self.blamechunk_revision = keyval[0] __thread_lock__.release() # Lock controlling the number of threads running @@ -275,7 +276,8 @@ class BlameOutput(Outputable): terminal.clear_row() print(textwrap.fill(_(BLAME_INFO_TEXT) + ":", width=terminal.get_size()[0]) + "\n") - terminal.printb(_("Author").ljust(21) + _("Rows").rjust(10) + _("Stability").rjust(15) + _("Age").rjust(13) + _("% in comments").rjust(20)) + terminal.printb(_("Author").ljust(21) + _("Rows").rjust(10) + _("Stability").rjust(15) + _("Age").rjust(13) + + _("% in comments").rjust(20)) for i in sorted(__blame__.get_summed_blames().items()): print(i[0].ljust(20)[0:20], end=" ") diff --git a/gitinspector/clone.py b/gitinspector/clone.py index 8e0d85a..52ec236 100644 --- a/gitinspector/clone.py +++ b/gitinspector/clone.py @@ -43,7 +43,5 @@ def create(url): return url def delete(): - global __cloned_path__ - if __cloned_path__: shutil.rmtree(__cloned_path__, ignore_errors=True) diff --git a/gitinspector/filtering.py b/gitinspector/filtering.py index 9b74e0c..82f2bdb 100644 --- a/gitinspector/filtering.py +++ b/gitinspector/filtering.py @@ -75,8 +75,10 @@ def set_filtered(string, filter_type="file"): FILTERING_INFO_TEXT = N_("The following files were excluded from the statistics due to the specified exclusion patterns") FILTERING_AUTHOR_INFO_TEXT = N_("The following authors were excluded from the statistics due to the specified exclusion patterns") -FILTERING_EMAIL_INFO_TEXT = N_("The authors with the following emails were excluded from the statistics due to the specified exclusion patterns") -FILTERING_EMAIL_INFO_TEXT = N_("The following commit revisions were excluded from the statistics due to the specified exclusion patterns") +FILTERING_EMAIL_INFO_TEXT = N_("The authors with the following emails were excluded from the statistics due to the specified " \ + "exclusion patterns") +FILTERING_EMAIL_INFO_TEXT = N_("The following commit revisions were excluded from the statistics due to the specified " \ + "exclusion patterns") class Filtering(Outputable): @staticmethod diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index 0e6eb9f..4e57489 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -31,7 +31,8 @@ import subprocess __metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "h": 300, "hpp": 300, "php": 500, "py": 500, "glsl": 1000, "rb": 500, "js": 500, "sql": 1000, "xml": 1000} -__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp"], ["else", "for\s+\(.*\)", "if\s+\(.*\)", "case\s+\w+:", "default:", "while\s+\(.*\)"], +__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp"], ["else", "for\s+\(.*\)", "if\s+\(.*\)", "case\s+\w+:", + "default:", "while\s+\(.*\)"], ["assert", "break", "continue", "return"]], [["py"], ["^\s+elif .*:$", "^\s+else:$", "^\s+for .*:", "^\s+if .*:$", "^\s+while .*:$"], ["^\s+assert", "break", "continue", "return"]]] @@ -59,16 +60,16 @@ class MetricsLogic: extension = FileDiff.get_extension(i) lines = MetricsLogic.get_eloc(file_r, extension) - cc = MetricsLogic.get_cyclomatic_complexity(file_r, extension) + cycc = MetricsLogic.get_cyclomatic_complexity(file_r, extension) if __metric_eloc__.get(extension, None) != None and __metric_eloc__[extension] < lines: self.eloc[i.strip()] = lines - if METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD < cc: - self.cyclomatic_complexity[i.strip()] = cc + if METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD < cycc: + self.cyclomatic_complexity[i.strip()] = cycc - if lines > 0 and METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD < cc / float(lines): - self.cyclomatic_complexity_density[i.strip()] = cc / float(lines) + if lines > 0 and METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD < cycc / float(lines): + self.cyclomatic_complexity_density[i.strip()] = cycc / float(lines) @staticmethod def get_cyclomatic_complexity(file_r, extension): @@ -89,13 +90,13 @@ class MetricsLogic: (_, is_inside_comment) = comment.handle_comment_block(is_inside_comment, extension, i) if not is_inside_comment and not comment.is_comment(extension, i): - for t in entry_tokens: - if re.search(t, i, re.DOTALL): + for j in entry_tokens: + if re.search(j, i, re.DOTALL): cc_counter += 2 - for t in exit_tokens: - if re.search(t, i, re.DOTALL): + for j in exit_tokens: + if re.search(j, i, re.DOTALL): cc_counter += 1 - return cc_counter; + return cc_counter return -1 @@ -115,7 +116,8 @@ class MetricsLogic: ELOC_INFO_TEXT = N_("The following files are suspiciously big (in order of severity)") CYCLOMATIC_COMPLEXITY_TEXT = N_("The following files have an elevated cyclomatic complexity (in order of severity)") -CYCLOMATIC_COMPLEXITY_DENSITY_TEXT = N_("The following files have an elevated cyclomatic complexity density (in order of severity)") +CYCLOMATIC_COMPLEXITY_DENSITY_TEXT = N_("The following files have an elevated cyclomatic complexity density " \ + "(in order of severity)") METRICS_MISSING_INFO_TEXT = N_("No metrics violations were found in the repository") METRICS_VIOLATION_SCORES = [[1.0, "minimal"], [1.25, "minor"], [1.5, "medium"], [2.0, "bad"], [3.0, "severe"]] @@ -156,25 +158,25 @@ class Metrics(Outputable): if metrics_logic.eloc: metrics_xml += "

" + _(ELOC_INFO_TEXT) + ".

" - for n, i in enumerate(sorted(set([(j, i) for (i, j) in metrics_logic.eloc.items()]), reverse = True)): + for num, i in enumerate(sorted(set([(j, i) for (i, j) in metrics_logic.eloc.items()]), reverse = True)): metrics_xml += "
" if n % 2 == 1 else "\">") + \ + (" odd\">" if num % 2 == 1 else "\">") + \ _("{0} ({1} estimated lines of code)").format(i[1], str(i[0])) + "
" metrics_xml += "
" if metrics_logic.cyclomatic_complexity: metrics_xml += "

" + _(CYCLOMATIC_COMPLEXITY_TEXT) + "

" - for n, i in enumerate(sorted(set([(j, i) for (i, j) in metrics_logic.cyclomatic_complexity.items()]), reverse = True)): + for num, i in enumerate(sorted(set([(j, i) for (i, j) in metrics_logic.cyclomatic_complexity.items()]), reverse = True)): metrics_xml += "
" if n % 2 == 1 else "\">") + \ + (" odd\">" if num % 2 == 1 else "\">") + \ _("{0} ({1} in cyclomatic complexity)").format(i[1], str(i[0])) + "
" metrics_xml += "
" if metrics_logic.cyclomatic_complexity_density: metrics_xml += "

" + _(CYCLOMATIC_COMPLEXITY_DENSITY_TEXT) + "

" - for n, i in enumerate(sorted(set([(j, i) for (i, j) in metrics_logic.cyclomatic_complexity_density.items()]), reverse = True)): + for num, i in enumerate(sorted(set([(j, i) for (i, j) in metrics_logic.cyclomatic_complexity_density.items()]), reverse = True)): metrics_xml += "
" if n % 2 == 1 else "\">") + \ + (" odd\">" if num % 2 == 1 else "\">") + \ _("{0} ({1:.3f} in cyclomatic complexity density)").format(i[1], i[0]) + "
" metrics_xml += "
"