cppcheck-codequality
raw JSON → 1.6.0 verified Fri May 01 auth: no python
Convert a CppCheck XML report to a GitLab-compatible Code Quality JSON report. Version 1.6.0 supports Python 3.7 to 3.14. Releases are sporadic.
pip install cppcheck-codequality Common errors
error ImportError: No module named 'cppcheck_codequality' ↓
cause Installed package is `cppcheck-codequality` but import uses underscore; many users try `import cppcheck_codequality` which should work. This error may occur if the package is not installed or if there's a naming conflict.
fix
Run
pip install cppcheck-codequality and ensure no other package named cppcheck_codequality is interfering. error TypeError: expected string or bytes-like object ↓
cause Passed a file path (string) instead of XML content to `convert()`.
fix
Read the file content first:
with open('report.xml') as f: xml = f.read(); convert(xml). Warnings
gotcha The `convert` function expects a **string** containing XML, not a file path. Passing a file path will raise an error. ↓
fix Read the XML file contents into a string first using `open().read()`.
gotcha The library output is a JSON string, not a Python dict. If you need to manipulate the report further, parse it with `json.loads(json_output)`. ↓
fix Use `json.loads(convert(xml_str))` to get a Python dict.
deprecated Support for Python 3.7 and 3.8 may be dropped in future releases. The current version requires Python >=3.7, <3.15. ↓
fix Upgrade to Python 3.9+ to ensure future compatibility.
Imports
- convert
from cppcheck_codequality import convert
Quickstart
import subprocess
import cppcheck_codequality
# Run cppcheck and produce XML output
with open("cppcheck_report.xml", "r") as f:
report_xml = f.read()
# Convert to Code Quality JSON
json_output = cppcheck_codequality.convert(report_xml)
with open("gl-code-quality-report.json", "w") as f:
f.write(json_output)