Skip to content

Commit

Permalink
Merge pull request #176 from mgorny/tomli
Browse files Browse the repository at this point in the history
Use the modern tomllib/tomli backends for reading TOML
  • Loading branch information
carsongee authored Oct 6, 2023
2 parents 6a09517 + 90e8b46 commit 8e22844
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions pytest_pylint/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
"""


import sys
from collections import defaultdict
from configparser import ConfigParser, NoOptionError, NoSectionError
from os import getcwd, makedirs, sep
from os.path import dirname, exists, getmtime, join
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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down

0 comments on commit 8e22844

Please sign in to comment.