Xenon is a Python code complexity tool that analyzes source code for various metrics like cyclomatic complexity, raw LOC, and maintainability index, leveraging the `radon` library. It's designed for integration into CI pipelines to monitor code quality against defined thresholds. The current version is 0.9.3, with updates occurring periodically, often tied to `radon` releases.
pip install xenonVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to run `xenon` programmatically by calling its `main` function, simulating a command-line invocation. This allows capturing its output and exit code for integration into Python scripts or build systems. Note that `main` can raise `SystemExit`, which should be handled.
Review release notes for 0.9.0 regarding configuration (`pyproject.toml`, `.xenon.ini`), file inclusions, and adapt any automated parsing of JSON reports. Explicitly specify `--include` or `--pattern` for non-Python files if needed.
Wrap calls to `xenon.main.main` in a `try...except SystemExit` block to handle its exit behavior. Process results by capturing `stdout` or parsing JSON reports saved to a file, rather than expecting direct return values.
Add `--include` or `--pattern` arguments to your CLI command or configuration to match the desired files, for example, `--pattern '*.py,*.ipynb'`.