saltstack/salt

View on GitHub
salt/utils/versions.py

Summary

Maintainability
D
2 days
Test Coverage

File versions.py has 288 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
    :copyright: Copyright 2017 by the SaltStack Team, see AUTHORS for more details.
    :license: Apache 2.0, see LICENSE for more details.

Severity: Minor
Found in salt/utils/versions.py - About 2 hrs to fix

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

    def check_boto_reqs(boto_ver=None,
                        boto3_ver=None,
                        botocore_ver=None,
                        check_boto=True,
                        check_boto3=True):
    Severity: Minor
    Found in salt/utils/versions.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 _cmp has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

            def _cmp(self, other):
                if isinstance(other, six.string_types):
                    other = LooseVersion(other)
    
                string_in_version = False
    Severity: Minor
    Found in salt/utils/versions.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 compare has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def compare(ver1='', oper='==', ver2='', cmp_func=None, ignore_epoch=False):
        '''
        Compares two version numbers. Accepts a custom function to perform the
        cmp-style version comparison, otherwise uses version_cmp().
        '''
    Severity: Minor
    Found in salt/utils/versions.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 kwargs_warn_until has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def kwargs_warn_until(kwargs,
                          version,
                          category=DeprecationWarning,
                          stacklevel=None,
                          _version_info_=None,
    Severity: Minor
    Found in salt/utils/versions.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 warn_until has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def warn_until(version,
                   message,
                   category=DeprecationWarning,
                   stacklevel=None,
                   _version_info_=None,
    Severity: Minor
    Found in salt/utils/versions.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 cmp_result in cmp_map[oper]
    Severity: Major
    Found in salt/utils/versions.py - About 30 mins to fix

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

      def version_cmp(pkg1, pkg2, ignore_epoch=False):
          '''
          Compares two version strings using salt.utils.versions.LooseVersion. This
          is a fallback for providers which don't have a version comparison utility
          built into them.  Return -1 if version1 < version2, 0 if version1 ==
      Severity: Minor
      Found in salt/utils/versions.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 not isinstance(version, (tuple,
                                      six.string_types,
                                      salt.version.SaltStackVersion)):
              raise RuntimeError(
                  'The \'version\' argument should be passed as a tuple, string or '
      Severity: Major
      Found in salt/utils/versions.py and 1 other location - About 4 hrs to fix
      salt/utils/versions.py on lines 106..116

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

      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 not isinstance(version, (tuple,
                                      six.string_types,
                                      salt.version.SaltStackVersion)):
              raise RuntimeError(
                  'The \'version\' argument should be passed as a tuple, string or '
      Severity: Major
      Found in salt/utils/versions.py and 1 other location - About 4 hrs to fix
      salt/utils/versions.py on lines 199..209

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

      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/utils/versions.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/states/pip_state.py on lines 306..306

      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

      There are no issues that match your filters.

      Category
      Status