diff --git a/pytest_pylint/plugin.py b/pytest_pylint/plugin.py index 86d343f..dcab2ab 100644 --- a/pytest_pylint/plugin.py +++ b/pytest_pylint/plugin.py @@ -4,6 +4,7 @@ """ +import sys from collections import defaultdict from configparser import ConfigParser, NoOptionError, NoSectionError from os import getcwd, makedirs, sep @@ -11,13 +12,18 @@ from pathlib import Path import pytest -import toml from pylint import config as pylint_config from pylint import lint from .pylint_util import ProgrammaticReporter from .util import PyLintException, get_rel_path, should_include_file +if sys.version_info >= (3, 11): + import tomllib +else: + # pylint: disable=import-error + import tomli as tomllib + HISTKEY = "pylint/mtimes" PYLINT_CONFIG_CACHE_KEY = "pylintrc" FILL_CHARS = 80 @@ -178,10 +184,10 @@ def _load_rc_file(self, pylintrc_file): pass def _load_pyproject_toml(self, pylintrc_file): - with open(pylintrc_file, "r", encoding="utf-8") as f_p: + with open(pylintrc_file, "rb") as f_p: try: - content = toml.load(f_p) - except (TypeError, toml.decoder.TomlDecodeError): + content = tomllib.load(f_p) + except (TypeError, tomllib.TOMLDecodeError): return try: diff --git a/setup.py b/setup.py index 556488a..9c1e40f 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,11 @@ packages=["pytest_pylint"], entry_points={"pytest11": ["pylint = pytest_pylint.plugin"]}, python_requires=">=3.7", - install_requires=["pytest>=7.0", "pylint>=2.15.0", "toml>=0.7.1"], + install_requires=[ + "pytest>=7.0", + "pylint>=2.15.0", + "tomli>=1.1.0; python_version < '3.11'", + ], setup_requires=["pytest-runner"], tests_require=["coverage", "flake8", "black", "isort"], classifiers=[