MetaPhase-Consulting/State-TalentMAP-API

View on GitHub
talentmap_api/log_viewer/services.py

Summary

Maintainability
A
1 hr
Test Coverage
F
26%

Avoid deeply nested control flow statements.
Open

                        with myzip.open(f) as myfile:
                            lines = myfile.read()
            else:
Severity: Major
Found in talentmap_api/log_viewer/services.py - About 45 mins to fix

    Function get_log has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
    Open

    def get_log(log_name, size=1000):
        lines = ""
        file_name = f"{log_dir}{log_name}"
        if os.path.exists(f"{file_name}"):
            try:
    Severity: Minor
    Found in talentmap_api/log_viewer/services.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

    At least two spaces before inline comment
    Open

    import subprocess # nosec
    Severity: Minor
    Found in talentmap_api/log_viewer/services.py by pep8

    Separate inline comments by at least two spaces.

    An inline comment is a comment on the same line as a statement.
    Inline comments should be separated by at least two spaces from the
    statement. They should start with a # and a single space.
    
    Each line of a block comment starts with a # and a single space
    (unless it is indented text inside the comment).
    
    Okay: x = x + 1  # Increment x
    Okay: x = x + 1    # Increment x
    Okay: # Block comment
    E261: x = x + 1 # Increment x
    E262: x = x + 1  #Increment x
    E262: x = x + 1  #  Increment x
    E265: #Block comment
    E266: ### Block comment

    At least two spaces before inline comment
    Open

        proc = subprocess.Popen(['tail', '-n', str(n), f], stdout=subprocess.PIPE) # nosec
    Severity: Minor
    Found in talentmap_api/log_viewer/services.py by pep8

    Separate inline comments by at least two spaces.

    An inline comment is a comment on the same line as a statement.
    Inline comments should be separated by at least two spaces from the
    statement. They should start with a # and a single space.
    
    Each line of a block comment starts with a # and a single space
    (unless it is indented text inside the comment).
    
    Okay: x = x + 1  # Increment x
    Okay: x = x + 1    # Increment x
    Okay: # Block comment
    E261: x = x + 1 # Increment x
    E262: x = x + 1  #Increment x
    E262: x = x + 1  #  Increment x
    E265: #Block comment
    E266: ### Block comment

    There are no issues that match your filters.

    Category
    Status