atlassian/localstack

View on GitHub
localstack/utils/common.py

Summary

Maintainability
F
3 days
Test Coverage

File common.py has 431 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import print_function

import threading
import traceback
import os
Severity: Minor
Found in localstack/utils/common.py - About 6 hrs to fix

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

        def run_cmd(self, params):
    
            def convert_line(line):
                line = to_str(line)
                return line.strip() + '\r\n'
    Severity: Minor
    Found in localstack/utils/common.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

    Function run has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def run(cmd, cache_duration_secs=0, print_error=True, async=False, stdin=False,
            stderr=subprocess.STDOUT, outfile=None, env_vars=None, inherit_cwd=False):
        # don't use subprocess module as it is not thread-safe
        # http://stackoverflow.com/questions/21194380/is-subprocess-popen-not-thread-safe
        # import subprocess
    Severity: Minor
    Found in localstack/utils/common.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

    Function run has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def run(cmd, cache_duration_secs=0, print_error=True, async=False, stdin=False,
    Severity: Major
    Found in localstack/utils/common.py - About 1 hr to fix

      Function generate_ssl_cert has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def generate_ssl_cert(target_file=None, overwrite=False, random=False):
          # Note: Do NOT import "OpenSSL" at the root scope
          # (Our test Lambdas are importing this file but don't have the module installed)
          from OpenSSL import crypto
      
      
      Severity: Minor
      Found in localstack/utils/common.py - About 1 hr to fix

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

            def __init__(self, cmd, params={}, outfile=None, env_vars={}, stdin=False,
        Severity: Major
        Found in localstack/utils/common.py - About 50 mins to fix

          Function generate_ssl_cert has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def generate_ssl_cert(target_file=None, overwrite=False, random=False):
              # Note: Do NOT import "OpenSSL" at the root scope
              # (Our test Lambdas are importing this file but don't have the module installed)
              from OpenSSL import crypto
          
          
          Severity: Minor
          Found in localstack/utils/common.py - About 45 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 merge_recursive has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def merge_recursive(source, destination):
              for key, value in source.items():
                  if isinstance(value, dict):
                      # get node or create one
                      node = destination.setdefault(key, {})
          Severity: Minor
          Found in localstack/utils/common.py - About 45 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 retry has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def retry(function, retries=3, sleep=1, sleep_before=0, **kwargs):
          Severity: Minor
          Found in localstack/utils/common.py - About 35 mins to fix

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

            def cleanup_tmp_files():
                for tmp in TMP_FILES:
                    try:
                        if os.path.isdir(tmp):
                            run('rm -rf "%s"' % tmp)
            Severity: Minor
            Found in localstack/utils/common.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

                                for line in iter(self.process.stderr.readline, ''):
                                    if not (line and line.strip()) and self.is_killed():
                                        break
                                    line = convert_line(line)
                                    sys.stderr.write(line)
            Severity: Major
            Found in localstack/utils/common.py and 1 other location - About 3 hrs to fix
            localstack/utils/common.py on lines 107..112

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

            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

                                for line in iter(self.process.stdout.readline, ''):
                                    if not (line and line.strip()) and self.is_killed():
                                        break
                                    line = convert_line(line)
                                    sys.stdout.write(line)
            Severity: Major
            Found in localstack/utils/common.py and 1 other location - About 3 hrs to fix
            localstack/utils/common.py on lines 113..118

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

            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