Standalone tool to convert Mypy output to Code Climate format. It does not require the Code Climate CLI and is dependency-free: great for CI/CD. Keeps sane exit codes for your CI. Additionally, can be used as a Python library.
The Code Climate format is supported by Gitlab CI, so you can generate a Code Quality report from mypy output, and have it tracked and displayed in your Gitlab UI.
mypy-to-codeclimate <mypy_output_file> <code_climate_output_file>
Example:
mypy-to-codeclimate mypy-output.txt mypy-codequality.json
You can replace the filename by -
to read from stdin, write to stdout, or both.
mypy <command_args> | mypy-to-codeclimate - mypy-codequality.json
0
: Success, no mypy errors1
: Mypy errors, codeclimate report generated2
: Mypy crash (unexpected error) or mypy-to-codeclimate error (invalid arguments, invalid input file, etc.)
--version
: Print version and exit--help
: Print help and exit
pip install mypy-to-codeclimate
The package is distributed on Pypi, so you can install it with pipx, PDM, Poetry or any other Python package manager.
Tested against Mypy 1.6.1. It should work with any version of mypy that outputs the same format.
Please open an issue if you find a version of mypy that is not supported.
Example of a job that runs mypy and generates a codeclimate report, on a Linux runner.
Dependency management is left as an exercise for the reader.
See Gitlab CI code-quality artifacts reference
lint_python_mypy:
script:
- mypy --version
# Disable exit on error and pipefail:
# mypy-code-climate will return a non-zero exit code if there are errors but we want to continue the job to generate the report
- set +eo pipefail
- mypy <command_args> | tee mypy-output.txt"
# Enable exit on error again
- set -xeo
- mypy-to-codeclimate mypy-output.txt mypy-codequality.json
artifacts:
when: always
paths:
- mypy-codequality.json
reports:
codequality: mypy-codequality.json
MIT, see LICENSE file.
Inspired by codeclimate-mypy by Scott Larkin (@larkinscott).