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
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,
- Read upRead up
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``)."""
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",
- Read upRead up
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(
Function create_container
has 26 arguments (exceeds 4 allowed). Consider refactoring. Open
def create_container(
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:
- Read upRead up
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
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
- Read upRead up
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(
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)
- Read upRead up
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"""
- Read upRead up
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
- Read upRead up
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]
- Read upRead up
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
- Read upRead up
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"