alot/settings/manager.py

Summary

Maintainability
D
2 days
Test Coverage

File manager.py has 440 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright (C) 2011-2012  Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import importlib.util
import itertools
Severity: Minor
Found in alot/settings/manager.py - About 6 hrs to fix

    SettingsManager has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SettingsManager:
        """Organizes user settings"""
        def __init__(self):
            self.hooks = None
            self._mailcaps = mailcap.getcaps()
    Severity: Minor
    Found in alot/settings/manager.py - About 2 hrs to fix

      Function get_keybindings has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_keybindings(self, mode):
              """look up keybindings from `MODE-maps` sections
      
              :param mode: mode identifier
              :type mode: str
      Severity: Minor
      Found in alot/settings/manager.py - About 2 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

      Function read_config has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def read_config(self, path):
              """
              parse alot's config file
              :param path: path to alot's config file
              :type path: str
      Severity: Minor
      Found in alot/settings/manager.py - About 2 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

      Function get_addressbooks has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_addressbooks(self, order=None, append_remaining=True):
              """returns list of all defined :class:`AddressBook` objects"""
              order = order or []
              abooks = []
              for a in order:
      Severity: Minor
      Found in alot/settings/manager.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 _parse_accounts has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def _parse_accounts(config):
              """
              read accounts information from config
      
              :param config: valit alot config
      Severity: Minor
      Found in alot/settings/manager.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 _expand_config_values has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def _expand_config_values(section, key):
              """
              Walker function for ConfigObj.walk
      
              Applies expand_environment_and_home to all configuration values that
      Severity: Minor
      Found in alot/settings/manager.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 get_tagstring_representation has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_tagstring_representation(self, tag, onebelow_normal=None,
                                           onebelow_focus=None):
              """
              looks up user's preferred way to represent a given tagstring.
      
      
      Severity: Minor
      Found in alot/settings/manager.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 get_keybinding has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_keybinding(self, mode, key):
              """look up keybinding from `MODE-maps` sections
      
              :param mode: mode identifier
              :type mode: str
      Severity: Minor
      Found in alot/settings/manager.py - About 55 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 account_matching_address has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def account_matching_address(self, address, return_default=False):
              """returns :class:`Account` for a given email address (str)
      
              :param str address: address to look up. A realname part will be ignored.
              :param bool return_default: If True and no address can be found, then
      Severity: Minor
      Found in alot/settings/manager.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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                      normal = resolve_att(colourpick(cfg['tags'][sec]['normal']),
                                           fallback_normal)
      Severity: Minor
      Found in alot/settings/manager.py and 1 other location - About 30 mins to fix
      alot/settings/manager.py on lines 361..362

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 32.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                      focus = resolve_att(colourpick(cfg['tags'][sec]['focus']),
                                          fallback_focus)
      Severity: Minor
      Found in alot/settings/manager.py and 1 other location - About 30 mins to fix
      alot/settings/manager.py on lines 359..360

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 32.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Do not use bare 'except'
      Open

              except:
      Severity: Minor
      Found in alot/settings/manager.py by pep8

      When catching exceptions, mention specific exceptions when possible.

      Okay: except Exception:
      Okay: except BaseException:
      E722: except:

      Continuation line over-indented for hanging indent
      Open

                      'mail_container': checks.mail_container,
      Severity: Minor
      Found in alot/settings/manager.py by pep8

      Continuation lines indentation.

      Continuation lines should align wrapped elements either vertically
      using Python's implicit line joining inside parentheses, brackets
      and braces, or using a hanging indent.
      
      When using a hanging indent these considerations should be applied:
      - there should be no arguments on the first line, and
      - further indentation should be used to clearly distinguish itself
        as a continuation line.
      
      Okay: a = (\n)
      E123: a = (\n    )
      
      Okay: a = (\n    42)
      E121: a = (\n   42)
      E122: a = (\n42)
      E123: a = (\n    42\n    )
      E124: a = (24,\n     42\n)
      E125: if (\n    b):\n    pass
      E126: a = (\n        42)
      E127: a = (24,\n      42)
      E128: a = (24,\n    42)
      E129: if (a or\n    b):\n    pass
      E131: a = (\n    42\n 24)

      There are no issues that match your filters.

      Category
      Status