Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Use tomllib/tomli for reading .toml configs #608

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Release Notes
`Semantic Versioning <http://semver.org/>`_ specification.


Current Development Version
---------------------------

Bug Fixes

* Use tomllib/tomli to correctly read .toml files (#599, #600).

6.2.0 - January 2nd, 2023
---------------------------

Expand Down
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ classifiers = [
[tool.poetry.dependencies]
python = ">=3.6"
snowballstemmer = ">=2.2.0"
toml = {version = ">=0.10.2", optional = true}
tomli = {version = ">=1.2.3", optional = true, python = "<3.11"}
importlib-metadata = {version = ">=2.0.0,<5.0.0", python = "<3.8"}

[tool.poetry.extras]
toml = ["toml"]
toml = ["tomli"]

[tool.poetry.scripts]
pydocstyle = "pydocstyle.cli:main"
Expand Down
2 changes: 1 addition & 1 deletion requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
snowballstemmer>=1.2.1
toml>=0.10.2
tomli>=1.2.3; python_version < "3.11"
importlib-metadata<5.0.0,>=2.0.0; python_version < "3.8"
1 change: 0 additions & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pytest==6.2.5
mypy==0.930
black==22.3
isort==5.4.2
types-toml
types-setuptools
20 changes: 12 additions & 8 deletions src/pydocstyle/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools
import operator
import os
import sys
from collections import namedtuple
from collections.abc import Set
from configparser import NoOptionError, NoSectionError, RawConfigParser
Expand All @@ -14,10 +15,13 @@
from .utils import log
from .violations import ErrorRegistry, conventions

try:
import toml
except ImportError: # pragma: no cover
toml = None # type: ignore
if sys.version_info >= (3, 11):
import tomllib
else:
try:
import tomli as tomllib
except ImportError: # pragma: no cover
tomllib = None # type: ignore


def check_initialized(method):
Expand Down Expand Up @@ -60,15 +64,15 @@ def read(self, filenames, encoding=None):
read_ok = []
for filename in filenames:
try:
with open(filename, encoding=encoding) as fp:
if not toml:
with open(filename, "rb") as fp:
if not tomllib:
log.warning(
"The %s configuration file was ignored, "
"because the `toml` package is not installed.",
"because the `tomli` package is not installed.",
filename,
)
continue
self._config.update(toml.load(fp))
self._config.update(tomllib.load(fp))
except OSError:
continue
if isinstance(filename, os.PathLike):
Expand Down