Skip to content

bug: missing import causes empty GitlabCodeClimateReport

Issue: if one of the module imports is missing, the generated GitlabCodeClimateReport is empty.

Example: I have a project with structure

my_package/
├── pyproject.toml
└── src/
    └── my_package/
        ├── __init__.py
        └── source.py

Contents pyproject.toml:

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "my_package"
version = "1.0.0"

The module __init__.py is empty. Contents source.py:

try:
    import gmpy2
except ImportError:
    pass


def foobar() -> bool:
    return True

The rationale for this use case is an optional dependency on gmpy2.

If I install the project, but not gmpy2, and execute pylint --output-format=pylint_gitlab.GitlabCodeClimateReporter:code-climate.json my_package, the resulting code-climate.json is emtpy. If I install gmpy2 and execute the same command, the resulting file is populated as expected.

Note: if I execute pylint --output-format=pylint_junit.JUnitReporter:pylint-report.xml,pylint_gitlab.GitlabCodeClimateReporter:code-climate.json my_package, then the junit report pylint-report.xml is also empty; however, this may be related to #16 (closed).

EDIT (15-12-2022): To clarify: pylint my_package and pylint --output-format=pylint_junit.JUnitReporter:pylint-report.xml my_package produce output as expected. The output of the first command is:

$ pylint my_package
************* Module my_package.source
.venv/lib/python3.10/site-packages/my_package/source.py:1:0: C0114: Missing module docstring (missing-module-docstring)
.venv/lib/python3.10/site-packages/my_package/source.py:7:0: C0116: Missing function or method docstring (missing-function-docstring)
.venv/lib/python3.10/site-packages/my_package/source.py:2:4: W0611: Unused import gmpy2 (unused-import)

------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)
Edited by Bart Kamphorst