Skip to content

Commit

Permalink
Add support for tomllib
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobDev authored and ssbarnea committed Jul 27, 2022
1 parent 53ab889 commit 1a2fa1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -102,7 +102,7 @@ instead.
* ``$CWD/tox.ini``
* ``$CWD/pep8.ini``
* ``$CWD/setup.cfg``
* ``$CWD/pyproject.toml`` in section ``[tool.doc8]`` if ``tomli`` is installed
* ``$CWD/pyproject.toml`` in section ``[tool.doc8]`` if ``tomli`` is installed or when using a Python version greater or equal than 3.11

An example section that can be placed into one of these files::

Expand Down
16 changes: 10 additions & 6 deletions src/doc8/main.py
Expand Up @@ -31,16 +31,20 @@
import argparse
import collections
import configparser
import importlib
import logging
import os
import sys

try:
import tomli

HAVE_TOML = True
except ImportError:
HAVE_TOML = False
HAVE_TOML = False
for module_name in ("tomllib", "tomli"):
try:
toml_module = importlib.import_module(module_name)
HAVE_TOML = True
break
except ModuleNotFoundError:
pass

from stevedore import extension

Expand Down Expand Up @@ -135,7 +139,7 @@ def from_ini(fp):

def from_toml(fp):
with open(fp, "rb") as f:
parsed = tomli.load(f).get("tool", {}).get("doc8", {})
parsed = toml_module.load(f).get("tool", {}).get("doc8", {})

cfg = {}
for key, value in parsed.items():
Expand Down

0 comments on commit 1a2fa1a

Please sign in to comment.