How to use the radon.raw.analyze function in radon

To help you get started, we’ve selected a few radon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xbmc / addon-check / script.test / main.py View on Github external
def number_of_lines(filepath):
    with open(filepath, 'r') as file:
        data = file.read()

    return (analyze(data).lloc)
github xbmc / addon-check / kodi_addon_checker / check_entrypoint.py View on Github external
def _number_of_lines(report: Report, filepath: str, library: str, max_entrypoint_count: int):
    """Returns the number of logical lines of code in a given python file
        :filepath: Path of the python file
        :library: relative path of the file
        :max_entypoint_line_count: max value allowed in any entrypoint file
    """

    with open(filepath, 'r') as file:
        data = file.read()

    try:
        lineno = analyze(data).lloc
        if lineno >= max_entrypoint_count:
            report.add(Record(WARNING,
                              "Complex entry point. Check: %s | Counted lines: %d | Lines allowed: %d"
                              % (library, lineno, max_entrypoint_count)))
    except SyntaxError as e:
        if e.msg == 'SyntaxError at line: 1':
            report.add(Record(PROBLEM,
                              ("Error parsing file, is your file saved with UTF-8 encoding? "
                               "Make sure it has no BOM. Check: %s")
                              % library))
        else:
            report.add(Record(PROBLEM,
                              "Error parsing file, is there a syntax error in your file? Check: %s"
                              % library))