localstack/localstack

View on GitHub
localstack-core/localstack/utils/container_utils/container_client.py

Summary

Maintainability
F
1 wk
Test Coverage

File container_client.py has 1159 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import dataclasses
import io
import ipaddress
import logging
import os
Severity: Major
Found in localstack-core/localstack/utils/container_utils/container_client.py - About 2 days to fix

    Function parse_additional_flags has a Cognitive Complexity of 93 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_additional_flags(
            additional_flags: str,
            env_vars: Optional[Dict[str, str]] = None,
            labels: Optional[Dict[str, str]] = None,
            mounts: Optional[List[SimpleVolumeBind]] = None,
    Severity: Minor
    Found in localstack-core/localstack/utils/container_utils/container_client.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

    ContainerClient has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ContainerClient(metaclass=ABCMeta):
        @abstractmethod
        def get_system_info(self) -> dict:
            """Returns the docker system-wide information as dictionary (``docker info``)."""
    
    
    Severity: Minor
    Found in localstack-core/localstack/utils/container_utils/container_client.py - About 6 hrs to fix

      Function add has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          def add(
              self,
              port: Union[int, PortRange],
              mapped: Union[int, PortRange] = None,
              protocol: PortProtocol = "tcp",
      Severity: Minor
      Found in localstack-core/localstack/utils/container_utils/container_client.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_container has 27 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def run_container(
      Severity: Major
      Found in localstack-core/localstack/utils/container_utils/container_client.py - About 3 hrs to fix

        Function create_container has 26 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def create_container(
        Severity: Major
        Found in localstack-core/localstack/utils/container_utils/container_client.py - About 3 hrs to fix

          Function to_dict has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_dict(self) -> Dict[str, Union[Tuple[str, Union[int, List[int]]], int]]:
                  bind_address = self.bind_host or ""
          
                  def bind_port(bind_address, host_port):
                      if host_port == 0:

          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_additional_flags has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def parse_additional_flags(

            Function parse_additional_flags has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def parse_additional_flags(
                    additional_flags: str,
                    env_vars: Optional[Dict[str, str]] = None,
                    labels: Optional[Dict[str, str]] = None,
                    mounts: Optional[List[SimpleVolumeBind]] = None,

              Function exec_in_container has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def exec_in_container(

                Avoid deeply nested control flow statements.
                Open

                                        if env_value := os.environ.get(lhs):
                                            env_vars[lhs] = env_value
                
                
                Severity: Major
                Found in localstack-core/localstack/utils/container_utils/container_client.py - About 45 mins to fix

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

                      def to_str(self) -> str:
                          bind_address = f"{self.bind_host}:" if self.bind_host else ""
                  
                          def entry(k, v):
                              from_range, protocol = k
                  Severity: Minor
                  Found in localstack-core/localstack/utils/container_utils/container_client.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 start_container has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def start_container(
                  Severity: Minor
                  Found in localstack-core/localstack/utils/container_utils/container_client.py - About 35 mins to fix

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

                        def create_env_vars_file_flag(cls, env_vars: Dict) -> Tuple[List[str], Optional[str]]:
                            if not env_vars:
                                return [], None
                            result = []
                            env_vars = dict(env_vars)
                    Severity: Minor
                    Found in localstack-core/localstack/utils/container_utils/container_client.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 convert_mount_list_to_dict has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def convert_mount_list_to_dict(
                            mount_volumes: Union[List[SimpleVolumeBind], VolumeMappings],
                        ) -> Dict[str, Dict[str, str]]:
                            """Converts a List of (host_path, container_path) tuples to a Dict suitable as volume argument for docker sdk"""
                    
                    
                    Severity: Minor
                    Found in localstack-core/localstack/utils/container_utils/container_client.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

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

                        def strip_wellknown_repo_prefixes(image_names: List[str]) -> List[str]:
                            """
                            Remove well-known repo prefixes like `localhost/` or `docker.io/library/` from the list of given
                            image names. This is mostly to ensure compatibility of our Docker client with Podman API responses.
                            :return: a copy of the list of image names, with well-known repo prefixes removed
                    Severity: Minor
                    Found in localstack-core/localstack/utils/container_utils/container_client.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

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

                        def contains(self, port: int, protocol: PortProtocol = "tcp") -> bool:
                            for from_range_w_protocol, to_range in self.mappings.items():
                                from_protocol = from_range_w_protocol[1]
                                if from_protocol == protocol:
                                    from_range = from_range_w_protocol[0]
                    Severity: Minor
                    Found in localstack-core/localstack/utils/container_utils/container_client.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

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

                        def expand_range(
                            self, port: int, range: PortRange, protocol: PortProtocol = "tcp", remap: bool = False
                        ):
                            """
                            Expand the given port range by the given port. If remap==True, put the updated range into self.mappings
                    Severity: Minor
                    Found in localstack-core/localstack/utils/container_utils/container_client.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