gwsumm/tabs/core.py

Summary

Maintainability
F
5 days
Test Coverage

File core.py has 877 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding=utf-8
# Copyright (C) Duncan Macleod (2013)
#
# This file is part of GWSumm.
#
Severity: Major
Found in gwsumm/tabs/core.py - About 2 days to fix

    Function _html_navbar_links has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def _html_navbar_links(self, tabs):
            """Construct the ordered list of tabs to write into the navbar
    
            Parameters
            ----------
    Severity: Minor
    Found in gwsumm/tabs/core.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Cyclomatic complexity is too high in method _html_navbar_links. (29)
    Open

        def _html_navbar_links(self, tabs):
            """Construct the ordered list of tabs to write into the navbar
    
            Parameters
            ----------
    Severity: Minor
    Found in gwsumm/tabs/core.py by radon

    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 from_ini. (24)
    Open

        @classmethod
        def from_ini(cls, cp, section, *args, **kwargs):
            """Define a new tab from a `~gwsumm.config.GWConfigParser`
    
            Parameters
    Severity: Minor
    Found in gwsumm/tabs/core.py by radon

    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

    Function from_ini has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def from_ini(cls, cp, section, *args, **kwargs):
            """Define a new tab from a `~gwsumm.config.GWConfigParser`
    
            Parameters
            ----------
    Severity: Minor
    Found in gwsumm/tabs/core.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    BaseTab has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BaseTab(object):
        """The core `Tab` object, defining basic functionality
        """
        def __init__(self, name, index=None, shortname=None, parent=None,
                     children=list(), group=None, notes=None, overlay=None,
    Severity: Minor
    Found in gwsumm/tabs/core.py - About 4 hrs to fix

      Cyclomatic complexity is too high in method write_html. (11)
      Open

          def write_html(self, maincontent, title=None, subtitle=None, tabs=list(),
                         ifo=None, ifomap=dict(), help_=None, base=None, css=None,
                         js=None, about=None, footer=None, issues=True, **inargs):
              """Write the HTML page for this `Tab`.
      
      
      Severity: Minor
      Found in gwsumm/tabs/core.py by radon

      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 get_hierarchy. (10)
      Open

          def get_hierarchy(self):
              parents = OrderedDict()
              # 1. Assume all tabs without parents are parents themselves
              for tab in [tab for tab in self if tab.parent is None]:
                  parents[tab.name] = tab
      Severity: Minor
      Found in gwsumm/tabs/core.py by radon

      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 from_ini. (10)
      Open

          @classmethod
          def from_ini(cls, config, tag='tab[_-]', match=[],
                       path=os.curdir, plotdir='plots'):
              if isinstance(tag, str):
                  tag = re.compile(tag)
      Severity: Minor
      Found in gwsumm/tabs/core.py by radon

      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 _sortkey. (7)
      Open

          @staticmethod
          def _sortkey(tab):
              # NOTE: we need all return values to be strings for
              #       the sorting to actually work
              if 'Home' in tab.shortname:
      Severity: Minor
      Found in gwsumm/tabs/core.py by radon

      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 class TabList. (6)
      Open

      class TabList(list):
          """Custom `list` of `Tab` objects with sorting and parsing
          """
      
          def __init__(self, entries=[]):
      Severity: Minor
      Found in gwsumm/tabs/core.py by radon

      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

      Function write_html has 14 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def write_html(self, maincontent, title=None, subtitle=None, tabs=list(),
      Severity: Major
      Found in gwsumm/tabs/core.py - About 1 hr to fix

        Function from_ini has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def from_ini(cls, config, tag='tab[_-]', match=[],
                         path=os.curdir, plotdir='plots'):
                if isinstance(tag, str):
                    tag = re.compile(tag)
                tabs = cls()
        Severity: Minor
        Found in gwsumm/tabs/core.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, name, index=None, shortname=None, parent=None,
        Severity: Major
        Found in gwsumm/tabs/core.py - About 1 hr to fix

          Function write_html has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def write_html(self, maincontent, title=None, subtitle=None, tabs=list(),
                             ifo=None, ifomap=dict(), help_=None, base=None, css=None,
                             js=None, about=None, footer=None, issues=True, **inargs):
                  """Write the HTML page for this `Tab`.
          
          
          Severity: Minor
          Found in gwsumm/tabs/core.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function html_navbar has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def html_navbar(self, help_=None, calendar=[], tabs=list(),
          Severity: Minor
          Found in gwsumm/tabs/core.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if child == self:
                                        active = [len(links) - 1, i]
                            if (children[0].shortname == 'Summary' and
            Severity: Major
            Found in gwsumm/tabs/core.py - About 45 mins to fix

              Function from_ini has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def from_ini(cls, config, tag='tab[_-]', match=[],
              Severity: Minor
              Found in gwsumm/tabs/core.py - About 35 mins to fix

                Function __call__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def __call__(cls, *args, **kwargs):
                        """Parse the `mode` kwarg for the Tab and add the right flavour
                        """
                        # parse default mode based on other kwargs
                        try:
                Severity: Minor
                Found in gwsumm/tabs/core.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function get_hierarchy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def get_hierarchy(self):
                        parents = OrderedDict()
                        # 1. Assume all tabs without parents are parents themselves
                        for tab in [tab for tab in self if tab.parent is None]:
                            parents[tab.name] = tab
                Severity: Minor
                Found in gwsumm/tabs/core.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Avoid too many return statements within this function.
                Open

                            return tab.shortname.upper()
                Severity: Major
                Found in gwsumm/tabs/core.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return tab.shortname.lower()
                  Severity: Major
                  Found in gwsumm/tabs/core.py - About 30 mins to fix

                    Function index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def index(self):
                            """The HTML path (relative to the `~Tab.path`) for this tab
                            """
                            if not self._index:
                                if self.shortname.lower() == 'summary':
                    Severity: Minor
                    Found in gwsumm/tabs/core.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    There are no issues that match your filters.

                    Category
                    Status