melexis/sphinx-traceability-extension

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

Summary

Maintainability
A
0 mins
Test Coverage

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

Too many instance attributes (8/7)
Open

class ItemPieChart(TraceableBaseNode):

Used when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class.

Too many local variables (16/15)
Confirmed

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

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

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

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.

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.

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.

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

            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_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.

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.

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 ..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.

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_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

        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.

There are no issues that match your filters.

Category
Status