Skip to main content

Monitor code metrics for Python on your CI server

Project description

Coveralls badge PyPI latest version badge Download format Xenon license

Xenon is a monitoring tool based on Radon. It monitors your code’s complexity. Ideally, Xenon is run every time you commit code. Through command line options, you can set various thresholds for the complexity of your code. It will fail (i.e. it will exit with a non-zero exit code) when any of these requirements is not met.

Installation

With Pip:

$ pip install xenon

Or download the source and run the setup file (requires setuptools):

$ python setup.py install

Xenon is tested with Python versions 2.7 and 3.6 to 3.12 as well as PyPy.

Usage

Typically you would use Xenon in two scenarios:

  1. As a git commit hook: to make sure that your code never exceeds some complexity values.

  2. On a continuous integration server: as a part of your build, to keep under control, as above, your code’s complexity. See Xenon’s .travis.yml file for an example usage.

The command line

Everything boils down to Xenon’s command line usage. To control which files are analyzed, you use the options -e, --exclude and -i, --ignore. Both accept a comma-separated list of glob patterns. The value usually needs quoting at the command line, to prevent the shell from expanding the pattern (in case there is only one). Every filename is matched against the exclude patterns. Every directory name is matched against the ignore patterns. If any of the patterns matches, Xenon won’t even descend into them.

The actual threshold values are defined through these options:

  • -a, --max-average: Threshold for the average complexity (across all the codebase).

  • -m, --max-modules: Threshold for modules complexity.

  • -b, --max-absolute: Absolute threshold for block complexity.

All of these options are inclusive.

An actual example

$ xenon --max-absolute B --max-modules A --max-average A

or, more succinctly:

$ xenon -b B -m A -a A

With these options Xenon will exit with a non-zero exit code if any of the following conditions is met:

  • At least one block has a rank higher than B (i.e. C, D, E or F).

  • At least one module has a rank higher than A.

  • The average complexity (among all of the analyzed blocks) is ranked with B or higher.

Pre-commit hook

Xenon can be used in combination with pre-commit as follows:

# monitor code complexity
- repo: https://github.com/rubik/xenon
  rev: v0.9.0
  hooks:
  - id: xenon
    args: ['--max-absolute=B', '--max-modules=B', '--max-average=A']

Note: due to how options are passed to commands by pre-commit, make sure to pass values either with an equals sign like in the above example, or by splitting them as separate list items, e.g. ['--max-absolute', 'B'].

Other resources

For more information regarding cyclomatic complexity and static analysis in Python, please refer to Radon’s documentation, the project on which Xenon is based on:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xenon-0.9.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

xenon-0.9.3-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file xenon-0.9.3.tar.gz.

File metadata

  • Download URL: xenon-0.9.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.7

File hashes

Hashes for xenon-0.9.3.tar.gz
Algorithm Hash digest
SHA256 4a7538d8ba08aa5d79055fb3e0b2393c0bd6d7d16a4ab0fcdef02ef1f10a43fa
MD5 ad5704f183619803a022c70429743b62
BLAKE2b-256 c47c2b341eaeec69d514b635ea18481885a956d196a74322a4b0942ef0c31691

See more details on using hashes here.

File details

Details for the file xenon-0.9.3-py2.py3-none-any.whl.

File metadata

  • Download URL: xenon-0.9.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.7

File hashes

Hashes for xenon-0.9.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6e2c2c251cc5e9d01fe984e623499b13b2140fcbf74d6c03a613fa43a9347097
MD5 ed9bead1c27c61b5fbab3644c8087223
BLAKE2b-256 6f5d29ff8665b129cafd147d90b86e92babee32e116e3c84447107da3e77f8fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page