Cloud-CV/EvalAI

View on GitHub
apps/challenges/aws_utils.py

Summary

Maintainability
F
1 wk
Test Coverage

File aws_utils.py has 1597 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import logging
import os
import random
import string
Severity: Major
Found in apps/challenges/aws_utils.py - About 4 days to fix

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

    def restart_workers_signal_callback(sender, instance, field_name, **kwargs):
        """
        Called when either evaluation_script or test_annotation_script for challenge
        is updated, to restart the challenge workers.
        """
    Severity: Minor
    Found in apps/challenges/aws_utils.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 register_task_def_by_challenge_pk has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def register_task_def_by_challenge_pk(client, queue_name, challenge):
        """
        Registers the task definition of the worker for a challenge, before creating a service.
    
        Parameters:
    Severity: Minor
    Found in apps/challenges/aws_utils.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 challenge_approval_callback has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def challenge_approval_callback(sender, instance, field_name, **kwargs):
        """This is to check if a challenge has been approved or disapproved since last time.
    
        On approval of a challenge, it launches a worker on Fargate.
        On disapproval, it scales down the workers to 0, and deletes the challenge's service on Fargate.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 get_logs_from_cloudwatch has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_logs_from_cloudwatch(
        log_group_name, log_stream_prefix, start_time, end_time, pattern, limit
    ):
        """
        To fetch logs of a container from cloudwatch within a specific time frame.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 stop_ec2_instance has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def stop_ec2_instance(challenge):
        """
        Stop the EC2 instance associated with a challenge if status checks are ready.
    
        Args:
    Severity: Minor
    Found in apps/challenges/aws_utils.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 restart_workers has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def restart_workers(queryset):
        """
        The function called by the admin action method to restart all the selected workers.
    
        Calls the service_manager method. Before calling, verifies that the challenge worker(s) is(are) active.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 create_service_by_challenge_pk has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_service_by_challenge_pk(client, challenge, client_token):
        """
        Creates the worker service for a challenge, and sets the number of workers to one.
    
        Parameters:
    Severity: Minor
    Found in apps/challenges/aws_utils.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 start_workers has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def start_workers(queryset):
        """
        The function called by the admin action method to start all the selected workers.
    
        Calls the service_manager method. Before calling, checks if all the workers are incactive.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 stop_workers has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def stop_workers(queryset):
        """
        The function called by the admin action method to stop all the selected workers.
    
        Calls the service_manager method. Before calling, verifies that the challenge is not new, and is active.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 delete_workers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def delete_workers(queryset):
        """
        The function called by the admin action method to delete all the selected workers.
    
        Calls the delete_service_by_challenge_pk method. Before calling, verifies that the challenge is not new.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 setup_eks_cluster has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def setup_eks_cluster(challenge):
        """
        Creates EKS and NodeGroup ARN roles
    
        Arguments:
    Severity: Minor
    Found in apps/challenges/aws_utils.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 scale_workers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def scale_workers(queryset, num_of_tasks):
        """
        The function called by the admin action method to scale all the selected workers.
    
        Calls the service_manager method. Before calling, checks if the target scaling number is different than current.
    Severity: Minor
    Found in apps/challenges/aws_utils.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 scale_resources has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def scale_resources(challenge, worker_cpu_cores, worker_memory):
        """
        The function called by scale_resources_by_challenge_pk to send the AWS ECS request to update the resources used by
        a challenge's workers.
    
    
    Severity: Minor
    Found in apps/challenges/aws_utils.py - About 55 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 create_ec2_instance has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_ec2_instance(challenge, ec2_storage=None, worker_instance_type=None, worker_image_url=None):
        """
        Create the EC2 instance associated with a challenge.
    
        Args:
    Severity: Minor
    Found in apps/challenges/aws_utils.py - About 55 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 get_logs_from_cloudwatch has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def get_logs_from_cloudwatch(
    Severity: Minor
    Found in apps/challenges/aws_utils.py - About 45 mins to fix

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

      def start_ec2_instance(challenge):
          """
          Start the EC2 instance associated with a challenge.
      
          Args:
      Severity: Minor
      Found in apps/challenges/aws_utils.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 create_eks_cluster has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def create_eks_cluster(challenge):
          """
          Called when Challenge is approved by the EvalAI admin
          calls the create_eks_nodegroup function
      
      
      Severity: Minor
      Found in apps/challenges/aws_utils.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
      Severity: Major
      Found in apps/challenges/aws_utils.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return {
        Severity: Major
        Found in apps/challenges/aws_utils.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return e.response
          Severity: Major
          Found in apps/challenges/aws_utils.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return
            Severity: Major
            Found in apps/challenges/aws_utils.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return {
              Severity: Major
              Found in apps/challenges/aws_utils.py - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status