AlexMathew/scrapple

View on GitHub
scrapple/utils/exceptions.py

Summary

Maintainability
A
1 hr
Test Coverage

Cyclomatic complexity is too high in function check_arguments. (13)
Open

def check_arguments(args):
    """
    Validates the arguments passed through the CLI commands.

    :param args: The arguments passed in the CLI, parsed by the docopt module
Severity: Minor
Found in scrapple/utils/exceptions.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function check_arguments has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

def check_arguments(args):
    """
    Validates the arguments passed through the CLI commands.

    :param args: The arguments passed in the CLI, parsed by the docopt module
Severity: Minor
Found in scrapple/utils/exceptions.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

Merge this if statement with the enclosing one.
Open

        if args['--output_type'] not in ['json', 'csv']:
Severity: Major
Found in scrapple/utils/exceptions.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

Merge this if statement with the enclosing one.
Open

        if projectname_re.search(args['<projectname>']) is not None:
Severity: Major
Found in scrapple/utils/exceptions.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

Indentation contains tabs
Open

    """Exception class for invalid in arguments."""
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    :param args: The arguments passed in the CLI, parsed by the docopt module
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    projectname_re = re.compile(r'[^a-zA-Z0-9_]')
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        ])
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    Validates the arguments passed through the CLI commands.
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    :return: None
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    pass
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    pass
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        if int(args['--levels']) < 1:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    """Exception class for invalid type in arguments."""
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        message = " ".join([
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    """Exception class for invalid levels in arguments."""
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        if projectname_re.search(args['<projectname>']) is not None:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            message = "--levels should be greater than, or equal to 1"
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    """Exception class for invalid output_type in arguments."""
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    pass
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    if args['genconfig'] or args['generate'] or args['run']:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    pass
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            raise InvalidType("--type has to be 'scraper' or 'crawler'")
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            "{}".format(type(args['--levels']))
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    except (TypeError, ValueError):
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        if args['--selector'] not in ['xpath', 'css']:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            raise InvalidProjectName(message)
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            "--levels should be an integer and not of type",
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        raise InvalidLevels(message)
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    """Exception class for invalid <projectname> in arguments."""
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    """
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    if args['generate'] or args['run']:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    try:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    if args['genconfig']:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        if args['--output_type'] not in ['json', 'csv']:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            raise InvalidOutputType("--output_type has to be 'json' or 'csv'")
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            raise InvalidLevels(message)
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    pass
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

    """
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

        if args['--type'] not in ['scraper', 'crawler']:
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            raise InvalidSelector("--selector has to be 'xpath' or 'css'")
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

Indentation contains tabs
Open

            message = "<projectname> should consist of letters, digits or _"
Severity: Minor
Found in scrapple/utils/exceptions.py by pep8

On new projects, spaces-only are strongly recommended over tabs.

Okay: if True:\n    return
W191: if True:\n\treturn

There are no issues that match your filters.

Category
Status