Monitoring tool based on radon

Overview

xenon

Travis-CI badge 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 all versions of Python from 2.7 to 3.6 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.

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:

Comments
  • New installation can't find flake8_polyfill library.

    New installation can't find flake8_polyfill library.

    certifi==2020.6.20,chardet==3.0.4,colorama==0.4.3,future==0.18.2,idna==2.10,mando==0.6.4,PyYAML==5.3.1,radon==4.3.1,requests==2.24.0,six==1.15.0,urllib3==1.25.10,xenon==0.7.0
    
    Traceback (most recent call last):
      File "/home/proofit404/data/generics/.tox/xenon/bin/xenon", line 8, in <module>
        sys.exit(main())
      File "/home/proofit404/data/generics/.tox/xenon/lib/python3.8/site-packages/xenon/__init__.py", line 72, in main
        from xenon.core import analyze
      File "/home/proofit404/data/generics/.tox/xenon/lib/python3.8/site-packages/xenon/core.py", line 5, in <module>
        from radon.complexity import cc_rank, SCORE
      File "/home/proofit404/data/generics/.tox/xenon/lib/python3.8/site-packages/radon/complexity.py", line 7, in <module>
        from flake8_polyfill import options
    ModuleNotFoundError: No module named 'flake8_polyfill'
    

    Maybe its a radon issue, but I've got the error when installing xenon tool.

    opened by proofit404 3
  • Xenon takes new --max-average-num argument

    Xenon takes new --max-average-num argument

    I wanted to be able to run this xenon code --max-average A --max-modules C --max-absolute D --max-average-num 2.3

    While this new argument is similar to max-average, it let's you threshold to a more specific value while you're still improving the code's complexity.

    opened by danilito19 3
  • Flake8 plugin

    Flake8 plugin

    Hi! Thanks for this awesome package.

    I guess that user-base can be extended if you create a flake8 plugin for xenon. So, here's how the final usage will look like:

    1. pip install flake8 xenon
    2. flake8 . (runs both flake8 and xenon)
    opened by sobolevn 3
  • Update the `radon` dependency from 1.4.0 to 1.4.2

    Update the `radon` dependency from 1.4.0 to 1.4.2

    This dependency is out of date and is breaking something on my side which is not directly linked to xenon. Whole story below.

    My CI pipeline recently broke with the following exception:

    +flake8 --ignore E501,F403,F401,F405 src
    Traceback (most recent call last):
      File "/home/travis/virtualenv/python3.4.2/bin/flake8", line 11, in <module>
        sys.exit(main())
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/main/cli.py", line 16, in main
        app.run(argv)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/main/application.py", line 316, in run
        self._run(argv)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/main/application.py", line 299, in _run
        self.initialize(argv)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/main/application.py", line 290, in initialize
        self.register_plugin_options()
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/main/application.py", line 150, in register_plugin_options
        self.check_plugins.register_options(self.option_manager)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/plugins/manager.py", line 457, in register_options
        list(self.manager.map(register_and_enable))
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/plugins/manager.py", line 267, in map
        yield func(self.plugins[name], *args, **kwargs)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/plugins/manager.py", line 453, in register_and_enable
        call_register_options(plugin)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/plugins/manager.py", line 363, in generated_function
        return method(optmanager, *args, **kwargs)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/flake8/plugins/manager.py", line 213, in register_options
        add_options(optmanager)
      File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/radon/complexity.py", line 132, in add_options
        parser.config_options.append('radon-max-cc')
    AttributeError: 'OptionManager' object has no attribute 'config_options'
    

    This issue is unrelated to xenon but as I install xenon along with flake8, the installed version of radon is currently the 1.4.0. To work properly, flake8 needs the 1.4.2 version.

    I understand this issue is completely out of scope of this project but I would like to spot the fact that the installed dependency is out of date and that this update would cause no harm to xenon while enabling it to be used more smoothly along with other widely-deployed tools such as flake8.

    opened by MickaelBergem 3
  • Yaml dependency

    Yaml dependency

    On installing xenon via pip install xenon, yaml dependency is missing. Additionally, one cannot simply pip install yaml, so I'm not sure about wich implementation of yaml was used.

    bug 
    opened by hkupty 3
  • PyYAML version preventing installation

    PyYAML version preventing installation

    Hi,

    I see that this has come up in the past and I was hoping it would be possible to again update the PyYAML dependency. My project depends on PyYAML version 6 and xenon is <6.0.

    Using version ^0.8.0 for xenon
    
    Updating dependencies
    Resolving dependencies... (3.8s)
    
      SolverProblemError
    
      Because no versions of xenon match >0.8.0,<0.9.0
       and xenon (0.8.0) depends on PyYAML (>=4.2b1,<6.0), xenon (>=0.8.0,<0.9.0) requires PyYAML (>=4.2b1,<6.0).
      So, because x-service depends on both PyYAML (6.0) and xenon (^0.8.0), version solving failed.
    

    Thanks

    opened by commentator8 2
  • allow xenon to be run as a module (-m)

    allow xenon to be run as a module (-m)

    Many libraries such as radon allow for modules to be executed via python -m.

    This change allows for python -m xenon to work. This allows for CI or local machines that have multiple versions of python to execute xenon and know exactly which interpreter is being invoked.

    opened by davegallant 2
  • Version resolution miss-match

    Version resolution miss-match

    While working on a project that uses secure version of pyyaml I have failed to install xenon with poetry, because these packages rely on different library versions:

    Because no versions of layer-linter match >0.12.0,<0.13.0
     and layer-linter (0.12.0) depends on PyYAML (>=4.2b1,<5.0.0), layer-linter (>=0.1
    2.0,<0.13.0) requires PyYAML (>=4.2b1,<5.0.0).
    Thus, layer-linter (>=0.12.0,<0.13.0) is incompatible with xenon (>=0.5,<0.6).
    So, because kira depends on both xenon (^0.5) and layer-linter (^0.12.0), version
    solving failed.
    

    Steps:

    1. poetry init - to create a new project
    2. poetry add xenon
    3. poetry add layer-lint
    opened by sobolevn 2
  • Latest version of radon causes weird warnings with xenon 0.5.2

    Latest version of radon causes weird warnings with xenon 0.5.2

    Running xenon (version 0.5.1 or 0.5.2 with mando-0.3.3 and radon-1.4.2) on our code base (Python 2.7) works as expected. But as of very recently, the latest dependencies (mando-0.6.4 and radon-2.0.3) are causing weird warnings of this form:

    WARNING:xenon:cannot parse path/to/source.py: invalid syntax (<unknown>, line 1)
    

    There is nothing wrong with those (dozens of) files. Downgrading to radon-1.4.2 gets rid of the warnings.

    Not a critical issue, but figured worth opening a ticket for :slightly_smiling_face: Thanks!

    PS1. I just confirmed that radon-2.0.2 works. The issue was introduced in radon-2.0.3 :information_source: PS2. Oops, looks like there was already a ticket in radon's issue tracker: https://github.com/rubik/radon/issues/133

    opened by spmaniato 2
  • Update PyYAML requirement to allow 3.12

    Update PyYAML requirement to allow 3.12

    PyYAML 3.11 fails compilation during pip install. If xenon allowed PyYaml 3.12, which added Windows wheels for Py27, 34, and 35, then Windows users would be super happy :-)

    opened by dougthor42 2
  • Doesn't like to be installed from pypi

    Doesn't like to be installed from pypi

    I can't seem to get xenon to install with a simple pip install. I tried with a python setup.py install as well and got the same result. It looks like the README.rst isn't included in the distribution on pypi.

    [josh@jh-mbp tmp]$ virtualenv xenonradon
    New python executable in xenonradon/bin/python
    Installing Setuptools..............................................................................................................................................................................................................................done.
    Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
    [josh@jh-mbp tmp]$ cd xenonradon/
    [josh@jh-mbp xenonradon]$ source bin/activate
    (xenonradon)[josh@jh-mbp xenonradon]$ php install radon
    Could not open input file: install
    (xenonradon)[josh@jh-mbp xenonradon]$ pip install radon
    Downloading/unpacking radon
      Downloading radon-0.5.1.tar.gz (224kB): 224kB downloaded
      Running setup.py egg_info for package radon
    
    Downloading/unpacking mando (from radon)
      Downloading mando-0.3.1.tar.gz
      Running setup.py egg_info for package mando
    
    Downloading/unpacking colorama (from radon)
      Downloading colorama-0.3.1.tar.gz
      Running setup.py egg_info for package colorama
    
    Downloading/unpacking pathfinder (from radon)
      Downloading pathfinder-0.5.3.tar.gz
      Running setup.py egg_info for package pathfinder
    
    Installing collected packages: radon, mando, colorama, pathfinder
      Running setup.py install for radon
    
        Installing radon script to /private/tmp/xenonradon/bin
      Running setup.py install for mando
    
      Running setup.py install for colorama
    
      Running setup.py install for pathfinder
    
    Successfully installed radon mando colorama pathfinder
    Cleaning up...
    (xenonradon)[josh@jh-mbp xenonradon]$ pip install xenon
    Downloading/unpacking xenon
      Downloading xenon-0.1.tar.gz
      Running setup.py egg_info for package xenon
        Traceback (most recent call last):
          File "<string>", line 16, in <module>
          File "/private/tmp/xenonradon/build/xenon/setup.py", line 6, in <module>
            with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as fobj:
        IOError: [Errno 2] No such file or directory: '/private/tmp/xenonradon/build/xenon/README.rst'
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
    
      File "<string>", line 16, in <module>
    
      File "/private/tmp/xenonradon/build/xenon/setup.py", line 6, in <module>
    
        with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as fobj:
    
    IOError: [Errno 2] No such file or directory: '/private/tmp/xenonradon/build/xenon/README.rst'
    
    ----------------------------------------
    Cleaning up...
    Command python setup.py egg_info failed with error code 1 in /private/tmp/xenonradon/build/xenon
    Storing complete log in /Users/josh/.pip/pip.log
    
    opened by skwash 2
  • Add 'link' option to skip loglevel and module info in output

    Add 'link' option to skip loglevel and module info in output

    Skip the level and module name to have log line starting with message. This option affects also how the "block" and "module" violations are printed - the path is in the front of the message. When using xenon in PyCharm terminal, one can benefit from PyCharm changing the path to the violation location into the active link.

    For more details see Feature Request #49

    opened by izikeros 0
  • Feature request - option to change log format for more convenient usage with PyCharm Terminal

    Feature request - option to change log format for more convenient usage with PyCharm Terminal

    The PyCharm terminal has a feature that if the line starts with the path to the file and code line, it is replaced with a link, and when clicked, the user is moved to that location. This property of the terminal is very useful when using various linters that return the location of violation of some rules.

    Would it be possible to e.g. add an option that will change the default log format to one without log level, module and change the log message format - remove quotes around the path?

    CURRENT:

    ERROR:xenon:block "jaba/core/engine.py:53 get_info" has a rank of C
    ERROR:xenon:block "jaba/scripts/monitor.py:26 display_dashboard" has a rank of C
    

    (desired) PyCharm Friendly:

    jaba/core/engine.py:53 get_info has a rank of C
    jaba/scripts/monitor.py:26 display_dashboard has a rank of C
    
    opened by izikeros 0
  • [pre-commit] - short options works, long are not working

    [pre-commit] - short options works, long are not working

    The problem is that xenon with "long options" (--max-absolute B, --max-modules B, --max-average A) does not find issues with complexity when used as pre-commit hook. When used with "short options" ( -bB, -mB, -aA) - it finds the issues with too complex code.

    Here is my xenon hook definition in .pre-commit-config.yaml:

        # 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 ]
                   #  args: [ -bB, -mB, -aA ]
    

    I was running it on macOS.

    opened by izikeros 0
  • Add the option to ignore by block name, instead of by module

    Add the option to ignore by block name, instead of by module

    I want to use xenon to prevent developers in my organization from adding new bad blocks, but still don't fail for existing bad blocks. Ignore/Exclude only allows to exclude by module, this isn't specific enough for us.

    opened by GuybarTapingo 1
  • Read configuration from `setup.cfg`

    Read configuration from `setup.cfg`

    My list of ignore and exclude options grew quite big, together with --max-absolute B --max-modules A --max-average A it looks to verbose to use.

    Is it an option to specify the configuration inside setup.cfg (default place for configuring python tools like flake8, mypy, isort, etc)?

    opened by sobolevn 2
An extensible and friendly code review tool for projects and companies of all sizes.

Review Board Review Board is an open source, web-based code and document review tool built to help companies, open source projects, and other organiza

Review Board 1.5k Jan 2, 2023
HTTP(s) "monitoring" webpage via FastAPI+Jinja2. Inspired by https://github.com/RaymiiOrg/bash-http-monitoring

python-http-monitoring HTTP(s) "monitoring" powered by FastAPI+Jinja2+aiohttp. Inspired by bash-http-monitoring. Installation can be done with pipenv

itzk 39 Aug 26, 2022
Monitoring plugin to check network interfaces with Icinga, Nagios and other compatible monitoring solutions

check_network_interface - Monitor network interfaces This is a monitoring plugin for Icinga, Nagios and other compatible monitoring solutions to check

DinoTools 3 Nov 15, 2022
Monitoring plugin to check disk io with Icinga, Nagios and other compatible monitoring solutions

check_disk_io - Monitor disk io This is a monitoring plugin for Icinga, Nagios and other compatible monitoring solutions to check the disk io. It uses

DinoTools 3 Nov 15, 2022
Logging-monitoring-instrumentation - A brief repository on logging monitoring and instrumentation in Python

logging-monitoring-instrumentation A brief repository on logging monitoring and

Noah Gift 6 Feb 17, 2022
Pebble is a stat's visualization tool, this will provide a skeleton to develop a monitoring tool.

Pebble is a stat's visualization tool, this will provide a skeleton to develop a monitoring tool.

Aravind Kumar G 2 Nov 17, 2021
Flower is a web based tool for monitoring and administrating Celery clusters.

Real-time monitor and web admin for Celery distributed task queue

Mher Movsisyan 5.5k Jan 2, 2023
System monitor - A python-based real-time system monitoring tool

System monitor A python-based real-time system monitoring tool Screenshots Installation Run My project with these commands pip install -r requiremen

Sachit Yadav 4 Feb 11, 2022
A cron monitoring tool written in Python & Django

Healthchecks Healthchecks is a cron job monitoring service. It listens for HTTP requests and email messages ("pings") from your cron jobs and schedule

Healthchecks 5.8k Jan 2, 2023
Tool for ROS 2 IP Discovery + System Monitoring

Monitor the status of computers on a network using the DDS function of ROS2.

Ar-Ray 33 Apr 3, 2022
Real-Time Social Distance Monitoring tool using Computer Vision

Social Distance Detector A Real-Time Social Distance Monitoring Tool Table of Contents Motivation YOLO Theory Detection Output Tech Stack Functionalit

Pranav B 13 Oct 14, 2022
Tactical RMM is a remote monitoring & management tool for Windows computers, built with Django and Vue.

Tactical RMM is a remote monitoring & management tool for Windows computers, built with Django and Vue. It uses an agent written in golan

Dan 1.4k Dec 30, 2022
Command line tool for monitoring changes of File entities scoped in a Synapse File View

Synapse Monitoring Provides tools for monitoring and keeping track of File entity changes in Synapse with the use of File Views. Learn more about File

Sage Bionetworks 3 May 28, 2022
Dipto Chakrabarty 7 Sep 6, 2022
Network monitoring tool

netmeter If you are looking for a tool to monitor your network interfaces, here you are. See netmeter-exporter to export Prometheus metrics. Installat

Saeid Bostandoust 97 Dec 3, 2022
Scout: an open-source version of the monitoring tool

Badger Scout Scout is an open-source version of the monitoring tool used by Badg

Badger Finance 2 Jan 13, 2022
More than 130 check plugins for Icinga and other Nagios-compatible monitoring applications. Each plugin is a standalone command line tool (written in Python) that provides a specific type of check.

Python-based Monitoring Check Plugins Collection This Enterprise Class Check Plugin Collection offers a package of more than 130 Python-based, Nagios-

Linuxfabrik 119 Dec 27, 2022
A project based example of Data pipelines, ML workflow management, API endpoints and Monitoring.

MLOps template with examples for Data pipelines, ML workflow management, API development and Monitoring.

Utsav 33 Dec 3, 2022
Coin-based opinion monitoring system

介绍 本仓库提供了基于币安 (Binance) 的二级市场舆情系统,可以根据自己的需求修改代码,设定各类告警提示 代码结构 binance.py - 与币安API交互 data_loader.py - 数据相关的读写 monitor.py - 监控的核心方法实现 analyze.py - 基于历史数

luv_dusk 6 Jun 8, 2022
Home solar infrastructure (with Peimar Inverter) monitoring based on Raspberry Pi 3 B+ using Grafana, InfluxDB, Custom Python Collector and Shelly EM.

raspberry-solar-mon Home solar infrastructure (with Peimar Inverter) monitoring based on Raspberry Pi 3 B+ using Grafana, InfluxDB, Custom Python Coll

cislow 10 Dec 23, 2022