melexis/sphinx-traceability-extension

View on GitHub
mlx/traceability/directives/item_pie_chart_directive.py

Summary

Maintainability
A
0 mins
Test Coverage

File item_pie_chart_directive.py has 568 lines of code (exceeds 500 allowed). Consider refactoring.
Wontfix

"""Module for the item-piechart directive"""
import operator
import re
from hashlib import sha256
from itertools import zip_longest
Severity: Major
Found in mlx/traceability/directives/item_pie_chart_directive.py - About 3 hrs to fix

    Cyclomatic complexity is too high in method _rows_per_source. (12)
    Wontfix

        def _rows_per_source(self, source, match, add_result_column, app):
            """ Builds a list of rows for the given source item
    
            Args:
                source (TraceableItem): Source item

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method perform_replacement. (12)
    Wontfix

        def perform_replacement(self, app, collection):
            """
            Very similar to item-matrix: but instead of creating a table, the empty cells in the right column are counted.
            Generates a pie chart with coverage percentages. Only items matching regexp in ``id_set`` option shall be
            included.

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Avoid deeply nested control flow statements.
    Wontfix

                            if add_result_column:
                                row_without_targets += self.generate_result_cell(target, nested_target)
                            if nested_target != nested_targets[-1]:
    Severity: Major
    Found in mlx/traceability/directives/item_pie_chart_directive.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Wontfix

                              if add_result_column:
                                  row_without_targets += nodes.entry('')
                      rows.append(row_without_targets)
      Severity: Major
      Found in mlx/traceability/directives/item_pie_chart_directive.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Wontfix

                                if nested_target != nested_targets[-1]:
                                    rows.append(row_without_targets)
                                    row_without_targets = nodes.row()
                            if not nested_targets:
        Severity: Major
        Found in mlx/traceability/directives/item_pie_chart_directive.py - About 45 mins to fix

          Too many local variables (17/15)
          Confirmed

              def build_pie_chart(self, sizes, labels, colors, env):

          Used when a function or method has too many local variables.

          Consider using '{aspect: 'equal'}' instead of a call to 'dict'.
          Open

                  fig, axes = plt.subplots(subplot_kw=dict(aspect="equal"))

          Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.

          Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.
          Open

              def loop_relationships(self, top_source_id, source_item, relationships, regex, match_function):

          Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

          See

          Refactor this function to reduce its Cognitive Complexity from 35 to the 15 allowed.
          Wontfix

              def _rows_per_source(self, source, match, add_result_column, app):

          Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

          See

          Import from sphinx.builders.latex import LaTeXBuilder should be placed at the top of the module
          Wontfix

          from sphinx.builders.latex import LaTeXBuilder

          Used when code and imports are mixed.

          Formatting a regular string which could be a f-string
          Open

                  return "{:.0f}%\n({:d})".format(pct, absolute)

          Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

          Import from ..traceability_exception import report_warning should be placed at the top of the module
          Wontfix

          from ..traceability_exception import report_warning

          Used when code and imports are mixed.

          Formatting a regular string which could be a f-string
          Open

                      report_warning("item-piechart can contain up to {} slices but only {} colors have been provided: some "

          Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

          Import from ..traceable_base_node import TraceableBaseNode should be placed at the top of the module
          Wontfix

          from ..traceable_base_node import TraceableBaseNode

          Used when code and imports are mixed.

          Import from ..traceable_item import TraceableItem should be placed at the top of the module
          Wontfix

          from ..traceable_item import TraceableItem

          Used when code and imports are mixed.

          Import import matplotlib.pyplot as plt should be placed at the top of the module
          Wontfix

          import matplotlib.pyplot as plt  # pylint: disable=wrong-import-order

          Used when code and imports are mixed.

          Formatting a regular string which could be a f-string
          Open

                  return 'Statistics: {cover} out of {total} covered: {pct}%'.format(cover=count_covered,

          Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

          Import from ..traceable_base_directive import TraceableBaseDirective should be placed at the top of the module
          Wontfix

          from ..traceable_base_directive import TraceableBaseDirective

          Used when code and imports are mixed.

          Formatting a regular string which could be a f-string
          Open

                  rel_file_path = path.join('_images', 'piechart-{}.{}'.format(hash_value, image_format))

          Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6.

          Import from natsort import natsorted should be placed at the top of the module
          Wontfix

          from natsort import natsorted

          Used when code and imports are mixed.

          There are no issues that match your filters.

          Category
          Status