How to use radon - 10 common examples

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 caleb531 / automata / tests / test_compliance.py View on Github external
def test_complexity():
    """All source file functions should have a low cyclomatic complexity."""
    file_paths = itertools.chain(
        glob.iglob('automata/*/*.py'),
        glob.iglob('tests/*.py'))
    for file_path in file_paths:
        with open(file_path, 'r') as file_obj:
            blocks = radon.cc_visit(file_obj.read())
        for block in blocks:
            fail_msg = '{} ({}) has a cyclomatic complexity of {}'.format(
                block.name, file_path, block.complexity)
            yield nose.assert_less_equal, block.complexity, 10, fail_msg
github caleb531 / youversion-suggest-alfred / tests / test_compliance.py View on Github external
def test_complexity():
    """All source and test files should have a low cyclomatic complexity"""
    file_paths = glob.iglob('*/*.py')
    for file_path in file_paths:
        with open(file_path, 'r') as file_obj:
            blocks = radon.cc_visit(file_obj.read())
        for block in blocks:
            fail_msg = '{} ({}) has a cyclomatic complexity of {}'.format(
                block.name, file_path, block.complexity)
            yield nose.assert_less_equal, block.complexity, 10, fail_msg
github caleb531 / cache-simulator / tests / test_compliance.py View on Github external
def test_complexity():
    file_paths = glob.iglob('*/*.py')
    for file_path in file_paths:
        with open(file_path, 'r') as file_obj:
            blocks = radon.cc_visit(file_obj.read())
        for block in blocks:
            test_doc = '{} ({}) should have a low cyclomatic complexity score'
            test_complexity.__doc__ = test_doc.format(
                block.name, file_path)
            fail_msg = '{} ({}) has a cyclomatic complexity of {}'.format(
                block.name, file_path, block.complexity)
            yield nose.assert_less_equal, block.complexity, 10, fail_msg
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 rubik / xenon / xenon / core.py View on Github external
def _analyze_cc(self):
        import radon
        print radon.__version__
        import inspect
        print inspect.getsource(iter_filenames)
        for name in iter_filenames(self.args.path, self.args.exclude,
                                   self.args.ignore):
            with open(name) as fobj:
                yield name, cc_visit(fobj.read(),
                                     no_assert=self.args.no_assert)
github tonybaloney / wily / src / wily / commands / diff.py View on Github external
:type  revision: ``str``
    """
    config.targets = files
    files = list(files)
    state = State(config)

    # Resolve target paths when the cli has specified --path
    if config.path != DEFAULT_PATH:
        targets = [str(Path(config.path) / Path(file)) for file in files]
    else:
        targets = files

    # Expand directories to paths
    files = [
        os.path.relpath(fn, config.path)
        for fn in radon.cli.harvest.iter_filenames(targets)
    ]
    logger.debug(f"Targeting - {files}")

    if not revision:
        target_revision = state.index[state.default_archiver].last_revision
    else:
        rev = resolve_archiver(state.default_archiver).cls(config).find(revision)
        logger.debug(f"Resolved {revision} to {rev.key} ({rev.message})")
        try:
            target_revision = state.index[state.default_archiver][rev.key]
        except KeyError:
            logger.error(
                f"Revision {revision} is not in the cache, make sure you have run wily build."
            )
            exit(1)
github rubik / xenon / xenon / core.py View on Github external
def _analyze_cc(self):
        import radon
        print radon.__version__
        import inspect
        print inspect.getsource(iter_filenames)
        for name in iter_filenames(self.args.path, self.args.exclude,
                                   self.args.ignore):
            with open(name) as fobj:
                yield name, cc_visit(fobj.read(),
                                     no_assert=self.args.no_assert)
github rubik / xenon / xenon / core.py View on Github external
def _analyze_cc(self):
        import radon
        print radon.__version__
        import inspect
        print inspect.getsource(iter_filenames)
        for name in iter_filenames(self.args.path, self.args.exclude,
                                   self.args.ignore):
            with open(name) as fobj:
                yield name, cc_visit(fobj.read(),
                                     no_assert=self.args.no_assert)
github rubik / xenon / xenon / core.py View on Github external
def _analyze_cc(self):
        import radon
        print radon.__version__
        import inspect
        print inspect.getsource(iter_filenames)
        for name in iter_filenames(self.args.path, self.args.exclude,
                                   self.args.ignore):
            with open(name) as fobj:
                yield name, cc_visit(fobj.read(),
                                     no_assert=self.args.no_assert)
github SergeySatskiy / codimension / codimension / ui / pyflakesviewer.py View on Github external
complains += escape(item)
                    else:
                        complains += "Line " + str(lineNo) + \
                                     ": " + escape(item)
            label.setToolTip(complains.replace(' ', ' '))
            label.setPixmap(getPixmap('flakeserrors.png'))
        else:
            # There are no complains
            label.setToolTip('Buffer checked: no pyflakes complains')
            label.setPixmap(getPixmap('flakesok.png'))

        if ccResults:
            complains = 'Buffer cyclomatic complexity:<br>'
            worstComplexity = 'A'
            for item in ccResults:
                complexity = cc_rank(item.complexity)
                worstComplexity = max(complexity, worstComplexity)

                if complexity != 'A':
                    complains += '<br>' + complexity + \
                                 '(' + str(item.complexity) + ') ' + \
                                 escape(item.fullname)
                    if item.letter in ('F', 'M'):
                        complains += '()'

            if worstComplexity == 'A':
                ccLabel.setToolTip('Buffer cyclomatic complexity: no complains')
            else:
                ccLabel.setToolTip(complains.replace(' ', '&nbsp;'))
            ccLabel.setPixmap(getPixmap(COMPLEXITY_PIXMAPS[worstComplexity]))
        else:
            ccLabel.setToolTip('No complexity information available')