Radon
=====
.. image:: https://img.shields.io/codacy/grade/623b84f5f6e6708c486f371e10da3610.svg?style=for-the-badge
:alt: Codacy badge
:target: https://www.codacy.com/app/rubik/radon/dashboard
.. image:: https://img.shields.io/travis/rubik/radon/master.svg?style=for-the-badge
:alt: Travis-CI badge
:target: https://travis-ci.org/rubik/radon
.. image:: https://img.shields.io/coveralls/rubik/radon/master.svg?style=for-the-badge
:alt: Coveralls badge
:target: https://coveralls.io/r/rubik/radon?branch=master
.. image:: https://img.shields.io/pypi/v/radon.svg?style=for-the-badge
:alt: PyPI latest version badge
:target: https://pypi.python.org/pypi/radon
.. image:: https://img.shields.io/pypi/l/radon.svg?style=for-the-badge
: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.8** (except Python versions
from 3.0 to 3.3) 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
3.5 v7.3.1 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
If you want to configure Radon from `pyproject.toml` and you run Python <3.11,
you'll need the extra `toml` dependency:
.. code-block:: sh
$ pip install radon[toml]
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.io/>`_. 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.
Usage with Jupyter Notebooks
----------------------------
Radon can be used with ``.ipynb`` files to inspect code metrics for Python cells. Any ``%`` macros will be ignored in the metrics.
.. note::
Jupyter Notebook support requires the optional ``nbformat`` package. To install, run ``pip install nbformat``.
To enable scanning of Jupyter notebooks, add the ``--include-ipynb`` flag.
To enable reporting of individual cells, add the ``--ipynb-cells`` flag.
Quick example:
.. code-block:: sh
$ radon raw --include-ipynb --ipynb-cells .
example.ipynb
LOC: 63
LLOC: 37
SLOC: 37
Comments: 3
Single comments: 2
Multi: 10
Blank: 14
- Comment Stats
(C % L): 5%
(C % S): 8%
(C + M % L): 21%
example.ipynb:[0]
LOC: 0
LLOC: 0
SLOC: 0
Comments: 0
Single comments: 0
Multi: 0
Blank: 0
- Comment Stats
(C % L): 0%
(C % S): 0%
(C + M % L): 0%
example.ipynb:[1]
LOC: 2
LLOC: 2
SLOC: 2
Comments: 0
Single comments: 0
Multi: 0
Blank: 0
- Comment Stats
(C % L): 0%
(C % S): 0%
(C + M % L): 0%
Links
-----
* Documentation: https://radon.readthedocs.org
* PyPI: http://pypi.python.org/pypi/radon
* Issue Tracker: https://github.com/rubik/radon/issues
Raw data
{
"_id": null,
"home_page": "https://radon.readthedocs.org/",
"name": "radon",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "static analysis code complexity metrics",
"author": "Michele Lacchia",
"author_email": "michelelacchia@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b1/6d/98e61600febf6bd929cf04154537c39dc577ce414bafbfc24a286c4fa76d/radon-6.0.1.tar.gz",
"platform": "any",
"description": "Radon\n=====\n\n.. image:: https://img.shields.io/codacy/grade/623b84f5f6e6708c486f371e10da3610.svg?style=for-the-badge\n :alt: Codacy badge\n :target: https://www.codacy.com/app/rubik/radon/dashboard\n\n.. image:: https://img.shields.io/travis/rubik/radon/master.svg?style=for-the-badge\n :alt: Travis-CI badge\n :target: https://travis-ci.org/rubik/radon\n\n.. image:: https://img.shields.io/coveralls/rubik/radon/master.svg?style=for-the-badge\n :alt: Coveralls badge\n :target: https://coveralls.io/r/rubik/radon?branch=master\n\n.. image:: https://img.shields.io/pypi/v/radon.svg?style=for-the-badge\n :alt: PyPI latest version badge\n :target: https://pypi.python.org/pypi/radon\n\n.. image:: https://img.shields.io/pypi/l/radon.svg?style=for-the-badge\n :alt: Radon license\n :target: https://pypi.python.org/pypi/radon\n\n\n----\n\nRadon is a Python tool that computes various metrics from the source code.\nRadon can compute:\n\n* **McCabe's complexity**, i.e. cyclomatic complexity\n* **raw** metrics (these include SLOC, comment lines, blank lines, &c.)\n* **Halstead** metrics (all of them)\n* **Maintainability Index** (the one used in Visual Studio)\n\nRequirements\n------------\n\nRadon will run from **Python 2.7** to **Python 3.8** (except Python versions\nfrom 3.0 to 3.3) with a single code base and without the need of tools like\n2to3 or six. It can also run on **PyPy** without any problems (currently PyPy\n3.5 v7.3.1 is used in tests).\n\nRadon depends on as few packages as possible. Currently only `mando` is\nstrictly required (for the CLI interface). `colorama` is also listed as a\ndependency but if Radon cannot import it, the output simply will not be\ncolored.\n\n**Note**:\n**Python 2.6** was supported until version 1.5.0. Starting from version 2.0, it\nis not supported anymore.\n\nInstallation\n------------\n\nWith Pip:\n\n.. code-block:: sh\n\n $ pip install radon\n\nIf you want to configure Radon from `pyproject.toml` and you run Python <3.11,\nyou'll need the extra `toml` dependency:\n\n.. code-block:: sh\n\n $ pip install radon[toml]\n\nOr download the source and run the setup file:\n\n.. code-block:: sh\n\n $ python setup.py install\n\nUsage\n-----\n\nRadon can be used either from the command line or programmatically.\nDocumentation is at https://radon.readthedocs.org/.\n\nCyclomatic Complexity Example\n-----------------------------\n\nQuick example:\n\n.. code-block:: sh\n\n $ radon cc sympy/solvers/solvers.py -a -nc\n sympy/solvers/solvers.py\n F 346:0 solve - F\n F 1093:0 _solve - F\n F 1434:0 _solve_system - F\n F 2647:0 unrad - F\n F 110:0 checksol - F\n F 2238:0 _tsolve - F\n F 2482:0 _invert - F\n F 1862:0 solve_linear_system - E\n F 1781:0 minsolve_linear_system - D\n F 1636:0 solve_linear - D\n F 2382:0 nsolve - C\n\n 11 blocks (classes, functions, methods) analyzed.\n Average complexity: F (61.0)\n\nExplanation:\n\n* ``cc`` is the radon command to compute Cyclomatic Complexity\n* ``-a`` tells radon to calculate the average complexity at the end. Note that\n the average is computed among the *shown* blocks. If you want the total\n average, among all the blocks, regardless of what is being shown, you should\n use ``--total-average``.\n* ``-nc`` tells radon to print only results with a complexity rank of C or\n worse. Other examples: ``-na`` (from A to F), or ``-nd`` (from D to F).\n* The letter *in front of* the line numbers represents the type of the block\n (**F** means function, **M** method and **C** class).\n\nActually it's even better: it's got colors!\n\n.. image:: https://cloud.githubusercontent.com/assets/238549/3707477/5793aeaa-1435-11e4-98fb-00e0bd8137f5.png\n :alt: A screen of Radon's cc command\n\n\n**Note about file encoding**\n\nOn some systems, such as Windows, the default encoding is not UTF-8. If you are\nusing Unicode characters in your Python file and want to analyze it with Radon,\nyou'll have to set the `RADONFILESENCODING` environment variable to `UTF-8`.\n\n\nOn a Continuous Integration server\n----------------------------------\n\nIf you are looking to use `radon` on a CI server you may be better off with\n`xenon <https://github.com/rubik/xenon>`_. Although still experimental, it will\nfail (that means exiting with a non-zero exit code) when various thresholds are\nsurpassed. `radon` is more of a reporting tool, while `xenon` is a monitoring\none.\n\nIf you are looking for more complete solutions, read the following sections.\n\nCodacy\n++++++++++++\n\n`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.\n\nCode Climate\n++++++++++++\n\nRadon is available as a `Code Climate Engine <https://docs.codeclimate.com/docs/list-of-engines>`_.\nTo understand how to add Radon's checks to your Code Climate Platform, head\nover to their documentation:\nhttps://docs.codeclimate.com/v1.0/docs/radon\n\ncoala Analyzer\n++++++++++++++\n\nRadon is also supported in `coala <http://coala.io/>`_. To add Radon's\nchecks to coala, simply add the ``RadonBear`` to one of the sections in\nyour ``.coafile``.\n\nCodeFactor\n++++++++++++\n\n`CodeFactor <https://www.codefactor.io/>`_ uses Radon `out-of-the-box <https://support.codefactor.io/i24-analysis-tools-open-source>`_ to calculate Cyclomatic Complexity.\n\nUsage with Jupyter Notebooks\n----------------------------\n\nRadon can be used with ``.ipynb`` files to inspect code metrics for Python cells. Any ``%`` macros will be ignored in the metrics.\n\n.. note::\n\n Jupyter Notebook support requires the optional ``nbformat`` package. To install, run ``pip install nbformat``.\n\nTo enable scanning of Jupyter notebooks, add the ``--include-ipynb`` flag.\n\nTo enable reporting of individual cells, add the ``--ipynb-cells`` flag.\n\nQuick example:\n\n.. code-block:: sh\n\n $ radon raw --include-ipynb --ipynb-cells .\n example.ipynb\n LOC: 63\n LLOC: 37\n SLOC: 37\n Comments: 3\n Single comments: 2\n Multi: 10\n Blank: 14\n - Comment Stats\n (C % L): 5%\n (C % S): 8%\n (C + M % L): 21%\n example.ipynb:[0]\n LOC: 0\n LLOC: 0\n SLOC: 0\n Comments: 0\n Single comments: 0\n Multi: 0\n Blank: 0\n - Comment Stats\n (C % L): 0%\n (C % S): 0%\n (C + M % L): 0%\n example.ipynb:[1]\n LOC: 2\n LLOC: 2\n SLOC: 2\n Comments: 0\n Single comments: 0\n Multi: 0\n Blank: 0\n - Comment Stats\n (C % L): 0%\n (C % S): 0%\n (C + M % L): 0%\n\n\n\nLinks\n-----\n\n* Documentation: https://radon.readthedocs.org\n* PyPI: http://pypi.python.org/pypi/radon\n* Issue Tracker: https://github.com/rubik/radon/issues\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Code Metrics in Python",
"version": "6.0.1",
"split_keywords": [
"static",
"analysis",
"code",
"complexity",
"metrics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "93f7d00d9b4a0313a6be3a3e0818e6375e15da6d7076f4ae47d1324e7ca986a1",
"md5": "f43fa37a3da11b3783e050142cc45cd7",
"sha256": "632cc032364a6f8bb1010a2f6a12d0f14bc7e5ede76585ef29dc0cecf4cd8859"
},
"downloads": -1,
"filename": "radon-6.0.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "f43fa37a3da11b3783e050142cc45cd7",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 52784,
"upload_time": "2023-03-26T06:24:33",
"upload_time_iso_8601": "2023-03-26T06:24:33.949321Z",
"url": "https://files.pythonhosted.org/packages/93/f7/d00d9b4a0313a6be3a3e0818e6375e15da6d7076f4ae47d1324e7ca986a1/radon-6.0.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b16d98e61600febf6bd929cf04154537c39dc577ce414bafbfc24a286c4fa76d",
"md5": "8c0ba595d9f98729065c1fcd60871c71",
"sha256": "d1ac0053943a893878940fedc8b19ace70386fc9c9bf0a09229a44125ebf45b5"
},
"downloads": -1,
"filename": "radon-6.0.1.tar.gz",
"has_sig": false,
"md5_digest": "8c0ba595d9f98729065c1fcd60871c71",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 1874992,
"upload_time": "2023-03-26T06:24:38",
"upload_time_iso_8601": "2023-03-26T06:24:38.868567Z",
"url": "https://files.pythonhosted.org/packages/b1/6d/98e61600febf6bd929cf04154537c39dc577ce414bafbfc24a286c4fa76d/radon-6.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-26 06:24:38",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "radon"
}