How to use the radon.complexity.cc_rank 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 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')
github rubik / xenon / xenon / core.py View on Github external
*results* is a dictionary holding the results of the complexity analysis.

    The number of infractions with respect to the threshold values is returned.
    '''
    infractions = 0
    module_averages = []
    total_cc = 0.
    total_blocks = 0
    for module, blocks in results.items():
        module_cc = 0.
        if isinstance(blocks, dict) and blocks.get('error'):
            logger.warning('cannot parse %s: %s', module, blocks['error'])
            continue
        for block in blocks:
            module_cc += block['complexity']
            r = cc_rank(block['complexity'])
            if check(r, args.absolute):
                logger.error('block "%s:%s %s" has a rank of %s', module,
                             block['lineno'], block['name'], r)
                infractions += 1
        module_averages.append((module, av(module_cc, len(blocks))))
        total_cc += module_cc
        total_blocks += len(blocks)

    ar = cc_rank(av(total_cc, total_blocks))
    if check(ar, args.average):
        logger.error('average complexity is ranked %s', ar)
        infractions += 1
    for module, ma in module_averages:
        mar = cc_rank(ma)
        if check(mar, args.modules):
            logger.error('module %r has a rank of %s', module, mar)
github rubik / xenon / xenon / core.py View on Github external
module_cc = 0.
        if isinstance(blocks, dict) and blocks.get('error'):
            logger.warning('cannot parse %s: %s', module, blocks['error'])
            continue
        for block in blocks:
            module_cc += block['complexity']
            r = cc_rank(block['complexity'])
            if check(r, args.absolute):
                logger.error('block "%s:%s %s" has a rank of %s', module,
                             block['lineno'], block['name'], r)
                infractions += 1
        module_averages.append((module, av(module_cc, len(blocks))))
        total_cc += module_cc
        total_blocks += len(blocks)

    ar = cc_rank(av(total_cc, total_blocks))
    if check(ar, args.average):
        logger.error('average complexity is ranked %s', ar)
        infractions += 1
    for module, ma in module_averages:
        mar = cc_rank(ma)
        if check(mar, args.modules):
            logger.error('module %r has a rank of %s', module, mar)
            infractions += 1
    return infractions
github rubik / xenon / xenon / core.py View on Github external
def run(self):
        module_averages = []
        total_cc = 0.
        total_blocks = 0
        for module, results in self._analyze_cc():
            module_cc = 0.
            for block in results:
                module_cc += block.complexity
                r = cc_rank(block.complexity)
                if check(r, self.args.absolute):
                    self.log('block "{0}:{1} {2}" has a rank of {3}', module,
                             block.lineno, block.name, r)
            module_averages.append((module, av(module_cc, len(results))))
            total_cc += module_cc
            total_blocks += len(results)

        ar = cc_rank(av(total_cc, total_blocks))
        if check(ar, self.args.average):
            self.log('average complexity is ranked {0}', ar)
        for module, ma in module_averages:
            mar = cc_rank(ma)
            if check(mar, self.args.modules):
                self.log('module "{0}" has a rank of {1}', module, mar)

        return self.errors
github SergeySatskiy / codimension / codimension / editor / flakesmargin.py View on Github external
def setAnalysisMessages(self, messages, ccMessages):
        """Sets a new set of messages"""
        self.__messages = dict(messages)

        for lineno in self.__messages:
            if lineno > 0:
                self.setBlockValue(
                    self._qpart.document().findBlockByNumber(lineno - 1), 1)

        self.__ccMessages = {}
        for item in ccMessages:
            if item.lineno not in self.__messages:
                complexity = cc_rank(item.complexity)
                if complexity != 'A':
                    msg = 'Cyclomatic complexity is ' + complexity + \
                          ' (value: ' + str(item.complexity) + ')'
                    self.__ccMessages[item.lineno] = (msg, ord(complexity))
                    self.setBlockValue(
                        self._qpart.document().findBlockByNumber(
                            item.lineno - 1), 1)

        self.__noTooltip = False
        self.update()
github SergeySatskiy / codimension / codimension / ui / pyflakesviewer.py View on Github external
def __showCCContextMenu(self, pos):
        """Triggered when the cc icon context menu is requested"""
        if self.__currentUUID is None:
            return
        if self.__currentUUID not in self.__flakesResults:
            return

        count = 0
        contextMenu = QMenu(self.__ccLabel)
        for item in self.__flakesResults[self.__currentUUID].ccMessages:
            complexity = cc_rank(item.complexity)

            if complexity != 'A':
                count += 1
                title = complexity + '(' + str(item.complexity) + ') ' + \
                        item.fullname
                if item.letter in ('F', 'M'):
                    title += '()'
                act = contextMenu.addAction(getIcon('ccmarker.png'), title)
                act.setData(item.lineno)
        if count > 0:
            contextMenu.triggered.connect(self.__onContextMenu)
            contextMenu.popup(self.__ccLabel.mapToGlobal(pos))
        else:
            del contextMenu