m4ce/cook-jobclient-python

View on GitHub

Showing 12 of 12 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        if len(jobs) > 1:
            for r in self._batch_request(jobs):
                req.append(
                    ''.join([self._scheduler_endpoint, '?', '&'.join(r)]))
        else:
Severity: Major
Found in cook/jobclient.py and 1 other location - About 4 hrs to fix
cook/jobclient.py on lines 223..229

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

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 len(jobs) > 1:
            for r in self._batch_request(jobs):
                req.append(
                    ''.join([self._scheduler_endpoint, '?', '&'.join(r)]))
        else:
Severity: Major
Found in cook/jobclient.py and 1 other location - About 4 hrs to fix
cook/jobclient.py on lines 194..200

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

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

        with requests.Session() as session:
            for q in query:
                r = session.get(self._url + q, headers={'Content-Type': 'application/json',
                                                        'Accept': 'application/json'}, auth=self._auth,
                                timeout=self._request_timeout_secs)
Severity: Major
Found in cook/jobclient.py and 1 other location - About 2 hrs to fix
cook/jobclient.py on lines 146..151

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

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 q in query:
            r = requests.delete(self._url + q, headers={'Content-Type': 'application/json',
                                                        'Accept': 'application/json'}, auth=self._auth,
                                timeout=self._request_timeout_secs)
            r.raise_for_status()
Severity: Major
Found in cook/jobclient.py and 1 other location - About 2 hrs to fix
cook/jobclient.py on lines 124..130

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

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

File jobclient.py has 276 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import getpass
import json
import logging
import time
from uuid import UUID, uuid1
Severity: Minor
Found in cook/jobclient.py - About 2 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            if start_time:
                assert isinstance(start_time, datetime), "start time must be a datetime object"
                r.append("start_ms={}".format((start_time - datetime.utcfromtimestamp(0)).total_seconds() * 1000.0))
    Severity: Major
    Found in cook/jobclient.py and 1 other location - About 2 hrs to fix
    cook/jobclient.py on lines 312..314

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

    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

            if stop_time:
                assert isinstance(stop_time, datetime), "stop time must be a datetime object"
                r.append("stop_ms={}".format((stop_time - datetime.utcfromtimestamp(0)).total_seconds() * 1000.0))
    Severity: Major
    Found in cook/jobclient.py and 1 other location - About 2 hrs to fix
    cook/jobclient.py on lines 308..310

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

    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

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

        def wait(self, jobs):
            """Wait for jobs to complete
    
            Args:
                jobs (list): List of jobs to wait for
    Severity: Minor
    Found in cook/jobclient.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 __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, url, auth='http_basic', http_user=None, http_password=None, batch_request_size=32,
    Severity: Major
    Found in cook/jobclient.py - About 1 hr to fix

      Function list has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def list(self, user=getpass.getuser(), state=['success', 'running', 'failed', 'completed', 'waiting'],
                   start_time=None, stop_time=None,
                   limit=None):
              """List jobs run by a given user over a specific time range.
      
      
      Severity: Minor
      Found in cook/jobclient.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 list has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def list(self, user=getpass.getuser(), state=['success', 'running', 'failed', 'completed', 'waiting'],
      Severity: Minor
      Found in cook/jobclient.py - About 35 mins to fix

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

            def query(self, jobs):
                """Query one or more jobs
        
                Args:
                    jobs (list): Jobs to query
        Severity: Minor
        Found in cook/jobclient.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

        Severity
        Category
        Status
        Source
        Language