From a4e97fc10b4a5ec1a047d50fc27c23c4e882bc23 Mon Sep 17 00:00:00 2001 From: Piotr Machura Date: Mon, 3 Jan 2022 18:44:04 +0100 Subject: [PATCH] Fix pygame greeting breaking pylint JSON output --- pylsp/plugins/pylint_lint.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pylsp/plugins/pylint_lint.py b/pylsp/plugins/pylint_lint.py index 69bad1cd..d974a2f8 100644 --- a/pylsp/plugins/pylint_lint.py +++ b/pylsp/plugins/pylint_lint.py @@ -8,6 +8,7 @@ import sys import re from subprocess import Popen, PIPE +import os from pylint.epylint import py_run from pylsp import hookimpl, lsp @@ -19,6 +20,15 @@ log = logging.getLogger(__name__) +# Pylint fails to suppress STDOUT when importing whitelisted C +# extensions, mangling their output into the expected JSON which breaks the +# parser. The most prominent example (and maybe the only one out there) is +# pygame - we work around that by asking pygame to NOT display the message upon +# import via an (otherwise harmless) environment variable. This is an ad-hoc +# fix for a very specific upstream issue. +# Related: https://github.com/PyCQA/pylint/issues/3518 +os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = 'hide' + class PylintLinter: last_diags = collections.defaultdict(list)