saltstack/salt

View on GitHub
salt/states/pip_state.py

Summary

Maintainability
F
1 wk
Test Coverage

Function installed has a Cognitive Complexity of 149 (exceeds 5 allowed). Consider refactoring.
Open

def installed(name,
              pkgs=None,
              pip_bin=None,
              requirements=None,
              bin_env=None,
Severity: Minor
Found in salt/states/pip_state.py - About 3 days 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

File pip_state.py has 906 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Installation of Python Packages Using pip
=========================================

Severity: Major
Found in salt/states/pip_state.py - About 2 days to fix

    Cyclomatic complexity is too high in function installed. (68)
    Open

    def installed(name,
                  pkgs=None,
                  pip_bin=None,
                  requirements=None,
                  bin_env=None,
    Severity: Minor
    Found in salt/states/pip_state.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 _check_if_installed has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

    def _check_if_installed(prefix,
                            state_pkg_name,
                            version_spec,
                            ignore_installed,
                            force_reinstall,
    Severity: Minor
    Found in salt/states/pip_state.py - About 1 day 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 mod_aggregate has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    def mod_aggregate(low, chunks, running):
        '''
        The mod_aggregate function which looks up all packages in the available
        low chunks and merges them into a single pkgs ref in the present low data
        '''
    Severity: Minor
    Found in salt/states/pip_state.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

    Function _check_pkg_version_format has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def _check_pkg_version_format(pkg):
        '''
        Takes a package name and version specification (if any) and checks it using
        the pip library.
        '''
    Severity: Minor
    Found in salt/states/pip_state.py - About 3 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 function _check_if_installed. (21)
    Open

    def _check_if_installed(prefix,
                            state_pkg_name,
                            version_spec,
                            ignore_installed,
                            force_reinstall,
    Severity: Minor
    Found in salt/states/pip_state.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

    Avoid deeply nested control flow statements.
    Open

                        if _fulfills_version_spec(version, version_spec):
                            desired_version = version
                            break
                else:
    Severity: Major
    Found in salt/states/pip_state.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if 'rc' in spec[1]:
                              include_rc = True
                  available_versions = __salt__['pip.list_all_versions'](
      Severity: Major
      Found in salt/states/pip_state.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if 'a' in spec[1]:
                                include_alpha = True
                            if 'b' in spec[1]:
        Severity: Major
        Found in salt/states/pip_state.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if not pipsearch:
                                  pkg_404_comms.append(
                                      'There was no error installing package \'{0}\' '
                                      'although it does not show when calling '
                                      '\'pip.freeze\'.'.format(pkg)
          Severity: Major
          Found in salt/states/pip_state.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if not any(
                                    [
                                        line.strip().startswith(x)
                                        for x in PIP_REQUIREMENTS_NOCHANGE
                                    ]
            Severity: Major
            Found in salt/states/pip_state.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if version is not None:
                                      pkgs.append({chunk['name']: version})
                                  else:
                                      pkgs.append(chunk['name'])
                                  chunk['__agg__'] = True
              Severity: Major
              Found in salt/states/pip_state.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if 'b' in spec[1]:
                                        include_beta = True
                                    if 'rc' in spec[1]:
                Severity: Major
                Found in salt/states/pip_state.py - About 45 mins to fix

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

                  def _pep440_version_cmp(pkg1, pkg2, ignore_epoch=False):
                      '''
                      Compares two version strings using pkg_resources.parse_version.
                      Return -1 if version1 < version2, 0 if version1 ==version2,
                      and 1 if version1 > version2. Return None if there was a problem
                  Severity: Minor
                  Found in salt/states/pip_state.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 ret
                  Severity: Major
                  Found in salt/states/pip_state.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return ret
                    Severity: Major
                    Found in salt/states/pip_state.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return ret
                      Severity: Major
                      Found in salt/states/pip_state.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                        return ret
                        Severity: Major
                        Found in salt/states/pip_state.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return ret
                          Severity: Major
                          Found in salt/states/pip_state.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                return ret
                            Severity: Major
                            Found in salt/states/pip_state.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Wontfix

                                  return None
                              Severity: Major
                              Found in salt/states/pip_state.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return ret
                                Severity: Major
                                Found in salt/states/pip_state.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                      return ret
                                  Severity: Major
                                  Found in salt/states/pip_state.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return ret
                                    Severity: Major
                                    Found in salt/states/pip_state.py - About 30 mins to fix

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

                                      def uptodate(name,
                                                   bin_env=None,
                                                   user=None,
                                                   cwd=None,
                                                   use_vt=False):
                                      Severity: Minor
                                      Found in salt/states/pip_state.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

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

                                                  if pkg_type == 'pkgs':
                                                      # Pull out the pkg names!
                                                      if 'pkgs' in chunk:
                                                          pkgs.extend(chunk['pkgs'])
                                                          chunk['__agg__'] = True
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 1 other location - About 1 day to fix
                                      salt/states/pkg.py on lines 3309..3320

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

                                      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

                                          if use_wheel:
                                              min_version = '1.4'
                                              max_version = '9.0.3'
                                              too_low = salt.utils.versions.compare(ver1=cur_version, oper='<', ver2=min_version)
                                              too_high = salt.utils.versions.compare(ver1=cur_version, oper='>', ver2=max_version)
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 1 other location - About 5 hrs to fix
                                      salt/states/pip_state.py on lines 698..708

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

                                      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

                                          if no_use_wheel:
                                              min_version = '1.4'
                                              max_version = '9.0.3'
                                              too_low = salt.utils.versions.compare(ver1=cur_version, oper='<', ver2=min_version)
                                              too_high = salt.utils.versions.compare(ver1=cur_version, oper='>', ver2=max_version)
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 1 other location - About 5 hrs to fix
                                      salt/states/pip_state.py on lines 685..695

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

                                      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 4 locations. Consider refactoring.
                                      Open

                                          try:
                                              pip_list = __salt__['pip.list'](bin_env=bin_env, user=user, cwd=cwd)
                                          except (CommandExecutionError, CommandNotFoundError) as err:
                                              ret['result'] = False
                                              ret['comment'] = 'Error uninstalling \'{0}\': {1}'.format(name, err)
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 3 other locations - About 2 hrs to fix
                                      salt/states/bower.py on lines 257..262
                                      salt/states/bower.py on lines 296..301
                                      salt/states/cabal.py on lines 98..104

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

                                      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

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

                                          if pkg_type is not None and pkgs:
                                              if pkg_type in low:
                                                  low[pkg_type].extend(pkgs)
                                              else:
                                                  low[pkg_type] = pkgs
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 1 other location - About 2 hrs to fix
                                      salt/states/pkg.py on lines 3321..3325

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

                                      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

                                          try:
                                              cur_version = __salt__['pip.version'](bin_env)
                                          except (CommandNotFoundError, CommandExecutionError) as err:
                                              ret['result'] = None
                                              ret['comment'] = 'Error installing \'{0}\': {1}'.format(name, err)
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 1 other location - About 2 hrs to fix
                                      salt/states/timezone.py on lines 61..69

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

                                      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 5 locations. Consider refactoring.
                                      Open

                                          normalize = lambda x: six.text_type(x).split('!', 1)[-1] if ignore_epoch else six.text_type(x)
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 4 other locations - About 40 mins to fix
                                      salt/modules/aptpkg.py on lines 1425..1426
                                      salt/modules/opkg.py on lines 1215..1215
                                      salt/modules/rpm_lowpkg.py on lines 696..698
                                      salt/utils/versions.py on lines 243..244

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

                                      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 6 locations. Consider refactoring.
                                      Open

                                                  available_versions = __salt__['pip.list_all_versions'](
                                      Severity: Major
                                      Found in salt/states/pip_state.py and 5 other locations - About 30 mins to fix
                                      salt/states/boto_secgroup.py on lines 699..699
                                      salt/states/boto_secgroup.py on lines 735..735
                                      salt/states/git.py on lines 1468..1469
                                      salt/states/git.py on lines 1713..1714
                                      salt/states/git.py on lines 2622..2623

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

                                      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

                                      There are no issues that match your filters.

                                      Category
                                      Status