Code Climate report generation fails on FIPS systems

When running a codeclimate report on a FIPS enabled system, the following failure is seen:

$ pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter $(find -type f -name "*.py" ! -path "**/.venv/**") > codeclimate.json
Traceback (most recent call last):
  File "/home/python/.local/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/python/.local/lib/python3.9/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/python/.local/lib/python3.9/site-packages/pylint/lint/run.py", line 398, in __init__
    linter.check(args)
  File "/home/python/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 996, in check
    self._check_files(
  File "/home/python/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1045, in _check_files
    self.add_message(symbol, args=msg)
  File "/home/python/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1519, in add_message
    self._add_one_message(
  File "/home/python/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1477, in _add_one_message
    self.reporter.handle_message(
  File "/home/python/.local/lib/python3.9/site-packages/pylint_gitlab/reporter.py", line 131, in handle_message
    "fingerprint": hashlib.md5(":".join([msg.path, str(msg.line), msg.msg_id]).encode()).hexdigest()
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS

It seems as though the following changes can work around this.

Create a new pylint_gitlab/compat.py file with the following contents:

import hashlib
import sys
from functools import partial

if sys.version_info >= (3, 9):
    md5 = partial(hashlib.md5, usedforsecurity=False)
else:
    md5 = hashlib.md5

Modify pylint_gitlab/reporter.py with the following changes:

  • add from pylint_gitlab.compat import md5
  • replace hashlib.md5 with md5 at line 131