1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
Radon
=====
.. image:: https://img.shields.io/codacy/623b84f5f6e6708c486f371e10da3610.svg
:alt: Codacy badge
:target: https://www.codacy.com/app/rubik/radon/dashboard
.. image:: https://img.shields.io/travis/rubik/radon/master.svg
:alt: Travis-CI badge
:target: https://travis-ci.org/rubik/radon
.. image:: https://img.shields.io/coveralls/rubik/radon/master.svg
:alt: Coveralls badge
:target: https://coveralls.io/r/rubik/radon?branch=master
.. image:: https://img.shields.io/pypi/v/radon.svg
:alt: PyPI latest version badge
:target: https://pypi.python.org/pypi/radon
.. image:: https://img.shields.io/pypi/format/radon.svg
:alt: Download format
:target: http://pythonwheels.com/
.. image:: https://img.shields.io/pypi/l/radon.svg
:alt: Radon license
:target: https://pypi.python.org/pypi/radon
----
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.7** to **Python 3.6** 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 5.8.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.
**Note**:
**Python 2.6** was supported until version 1.5.0. Starting from version 2.0, it
is not supported anymore.
Installation
------------
With Pip:
.. code-block:: sh
$ pip install radon
Or download the source and run the setup file:
.. code-block:: sh
$ 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:
.. code-block:: sh
$ 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!
.. image:: https://cloud.githubusercontent.com/assets/238549/3707477/5793aeaa-1435-11e4-98fb-00e0bd8137f5.png
:alt: 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 <https://github.com/rubik/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.
Codacy
++++++++++++
`Codacy <https://www.codacy.com/>`_ uses Radon `by default <https://support.codacy.com/hc/en-us/articles/213632009-Engines#other-tools>`_ to calculate metrics from the source code.
Code Climate
++++++++++++
Radon is available as a `Code Climate Engine <https://docs.codeclimate.com/docs/list-of-engines>`_.
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 <http://coala-analyzer.org/>`_. To add Radon's
checks to coala, simply add the ``RadonBear`` to one of the sections in
your ``.coafile``.
CodeFactor
++++++++++++
`CodeFactor <https://www.codefactor.io/>`_ uses Radon `out-of-the-box <https://support.codefactor.io/i24-analysis-tools-open-source>`_ to calculate Cyclomatic Complexity.
Links
-----
* Documentation: https://radon.readthedocs.org
* PyPI: http://pypi.python.org/pypi/radon
* Issue Tracker: https://github.com/rubik/radon/issues
|