Code Monkey home page Code Monkey logo

radon's Introduction

Radon

Codacy badge

Travis-CI badge

Coveralls badge

PyPI latest version badge

PyPI downloads badge

Download format

Radon license


Radon is a Python tool that computes various metrics from the source code. Radon can compute:

  • McCabe's complexity, i.e. cyclomatic complexity
  • raw metrics (these include SLOC, comment lines, blank lines, &c.)
  • Halstead metrics (all of them)
  • Maintainability Index (the one used in Visual Studio)

Requirements

Radon will run from Python 2.6 to Python 3.5 with a single code base and without the need of tools like 2to3 or six. It can also run on PyPy without any problems (currently PyPy 4.0.0 is used in tests).

Radon depends on as few packages as possible. Currently only mando is strictly required (for the CLI interface). colorama is also listed as a dependency but if Radon cannot import it, the output simply will not be colored.

Installation

With Pip:

$ pip install radon

Or download the source and run the setup file:

$ python setup.py install

Usage

Radon can be used either from the command line or programmatically. Documentation is at https://radon.readthedocs.org/.

Cyclomatic Complexity Example

Quick example:

$ radon cc sympy/solvers/solvers.py -a -nc
sympy/solvers/solvers.py
    F 346:0 solve - F
    F 1093:0 _solve - F
    F 1434:0 _solve_system - F
    F 2647:0 unrad - F
    F 110:0 checksol - F
    F 2238:0 _tsolve - F
    F 2482:0 _invert - F
    F 1862:0 solve_linear_system - E
    F 1781:0 minsolve_linear_system - D
    F 1636:0 solve_linear - D
    F 2382:0 nsolve - C

11 blocks (classes, functions, methods) analyzed.
Average complexity: F (61.0)

Explanation:

  • cc is the radon command to compute Cyclomatic Complexity
  • -a tells radon to calculate the average complexity at the end. Note that the average is computed among the shown blocks. If you want the total average, among all the blocks, regardless of what is being shown, you should use --total-average.
  • -nc tells radon to print only results with a complexity rank of C or worse. Other examples: -na (from A to F), or -nd (from D to F).
  • The letter in front of the line numbers represents the type of the block (F means function, M method and C class).

Actually it's even better: it's got colors!

A screen of Radon's cc command

Note about file encoding

On some systems, such as Windows, the default encoding is not UTF-8. If you are using Unicode characters in your Python file and want to analyze it with Radon, you'll have to set the RADONFILESENCODING environment variable to UTF-8.

On a Continuous Integration server

If you are looking to use radon on a CI server you may be better off with xenon. Although still experimental, it will fail (that means exiting with a non-zero exit code) when various thresholds are surpassed. radon is more of a reporting tool, while xenon is a monitoring one.

If you are looking for more complete solutions, read the following sections.

Code Climate

Radon is available as a Code Climate Engine. To understand how to add Radon's checks to your Code Climate Platform, head over to their documentation: https://docs.codeclimate.com/v1.0/docs/radon

Coala Analyzer

Radon is also supported in coala. To add Radon's checks to coala, simply add the RadonBear to one of the sections in your .coafile.

radon's People

Contributors

rubik avatar jpignata avatar schettino72 avatar jsargiot avatar kernc avatar io41 avatar thunderk avatar schlamar avatar lucasmazza avatar kennknowles avatar coagulant avatar gdiggs avatar dblandin avatar jesskay avatar ashanbrown avatar andrewkittredge avatar pointlessone avatar

Watchers

Victor Liu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.