diff --git a/README.rst b/README.rst index 5d6992d..71628eb 100644 --- a/README.rst +++ b/README.rst @@ -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`` An example section that can be placed into one of these files:: diff --git a/setup.cfg b/setup.cfg index baf0db5..d8b680a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ install_requires = docutils restructuredtext-lint>=0.7 stevedore + tomli; python_version < '3.11' Pygments [options.entry_points] diff --git a/src/doc8/main.py b/src/doc8/main.py index b355362..7aa80d6 100644 --- a/src/doc8/main.py +++ b/src/doc8/main.py @@ -35,12 +35,13 @@ import os import sys -try: - import tomli - HAVE_TOML = True +try: + # py3.11+ + from tomllib import load as toml_load # type: ignore except ImportError: - HAVE_TOML = False + # py3.10 or older + from tomli import load as toml_load from stevedore import extension @@ -51,9 +52,14 @@ FILE_PATTERNS = [".rst", ".txt"] MAX_LINE_LENGTH = 79 -CONFIG_FILENAMES = ["doc8.ini", ".config/doc8.ini", "tox.ini", "pep8.ini", "setup.cfg"] -if HAVE_TOML: - CONFIG_FILENAMES.extend(["pyproject.toml"]) +CONFIG_FILENAMES = [ + "doc8.ini", + ".config/doc8.ini", + "tox.ini", + "pep8.ini", + "setup.cfg", + "pyproject.toml", +] def split_set_type(text, delimiter=","): @@ -135,7 +141,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_load(f).get("tool", {}).get("doc8", {}) cfg = {} for key, value in parsed.items(): @@ -157,7 +163,7 @@ def extract_config(args): continue if cfg_file.endswith((".ini", ".cfg")): cfg = from_ini(cfg_file) - elif cfg_file.endswith(".toml") and HAVE_TOML: + elif cfg_file.endswith(".toml"): cfg = from_toml(cfg_file) if cfg: break