Skip to main content

Standalone tool to convert a mypy output to CodeQuality JSON, for Gitlab or other CIs.

Project description

mypy-code-climate

PyPI - Python Version PyPI Downloads PyPI - License Code style: black Ruff

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.

Why?

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.

Usage

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

Program will exit with code 1 if there are errors in the mypy output, and 0 otherwise.

Installation

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.

Supported versions

Mypy versions

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.

Python versions

Tested against Python 3.11. It should work with any actively supported version of Python.

Please open an issue if you have any problem with a specific version of Python.

Example usage in Gitlab CI

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.

Gitlab CI code-quality artifacts reference: https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscodequality

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

License

MIT, see LICENSE file.

Acknowledgements

Inspired by codeclimate-mypy by Scott Larkin (@larkinscott).

Project details


Download files

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

Source Distribution

mypy_to_codeclimate-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

mypy_to_codeclimate-0.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file mypy_to_codeclimate-0.0.1.tar.gz.

File metadata

  • Download URL: mypy_to_codeclimate-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.10.0 CPython/3.11.6

File hashes

Hashes for mypy_to_codeclimate-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fbf778b99523bbcc73ac64c9a2b6b0d3f27c36ca15bad5d95f9c7ec870223074
MD5 fc8044d28649f0335401865085ca7f7c
BLAKE2b-256 443fa423b1821ae4d0eb7a3f422eac193b180223170d1af90f91941edc63a1ad

See more details on using hashes here.

File details

Details for the file mypy_to_codeclimate-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mypy_to_codeclimate-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 370658dd2c1234a5c517572d8decc3c08e9b43dfad85937d39e4e188b9aebcfd
MD5 d1c20eb66f377d206a5f2622153a2a5f
BLAKE2b-256 f926ce5d6d43843a84717dd24c001010dd5e64726ab81078496a375cf2302a00

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