Your issue
TypeError: 'LinterStats' object is not subscriptable
Just means, that LinterStats
is not idexable (see: What does it mean if a Python object is "subscriptable" or not?)
Old code (not working anymore)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Print ``pylint`` score (old way)."""
from pylint.lint import Run
score = Run([...], exit=False).linter.stats["global_note"]
print(score)
Example: https://github.com/apmechev/pylint-badge/blob/master/pylintbadge/pylintbadge.py
New code (working)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Print ``pylint`` score (new way)."""
from pylint.lint import Run
score = Run([...], exit=False).linter.stats.global_note
print(score)
Working silent code
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Print ``pylint`` score (new & silent way)."""
import sys
from typing import TextIO
from pylint.lint import Run
default_stdout = sys.stdout
sys.stdout = type("Dummy", (TextIO,), {"write": lambda self, data: ()})()
score = Run(["./src"], exit=False).linter.stats.global_note
sys.stdout = default_stdout
print(score)