Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for reading doc8 config from pyproject.toml file #49

Merged
merged 3 commits into from
Nov 27, 2020
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
46 changes: 35 additions & 11 deletions doc8/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
import os
import sys

try:
import toml

HAVE_TOML = True
except ImportError:
HAVE_TOML = False

from stevedore import extension

Expand All @@ -46,6 +52,8 @@
FILE_PATTERNS = [".rst", ".txt"]
MAX_LINE_LENGTH = 79
CONFIG_FILENAMES = ["doc8.ini", "tox.ini", "pep8.ini", "setup.cfg"]
if HAVE_TOML:
CONFIG_FILENAMES.extend(["pyproject.toml"])


def split_set_type(text, delimiter=","):
Expand All @@ -69,18 +77,11 @@ def parse_ignore_path_errors(entries):
return dict(ignore_path_errors)


def extract_config(args):
def from_ini(fp):
parser = configparser.RawConfigParser()
read_files = []
if args["config"]:
for fn in args["config"]:
with open(fn, "r") as fh:
parser.readfp(fh, filename=fn)
read_files.append(fn)
else:
read_files.extend(parser.read(CONFIG_FILENAMES))
if not read_files:
return {}
with open(fp, "r") as fh:
parser.read_file(fh)

cfg = {}
try:
cfg["max_line_length"] = parser.getint("doc8", "max-line-length")
Expand Down Expand Up @@ -132,6 +133,29 @@ def extract_config(args):
return cfg


def from_toml(fp):
cfg = toml.load(fp).get("tool", {}).get("doc8", {})
return cfg


def extract_config(args):
cfg = {}
for cfg_file in args["config"] or CONFIG_FILENAMES:
if not os.path.isfile(cfg_file):
if args["config"]:
print(
"Configuration file %s does not exist...ignoring" % (args["config"])
)
continue
if cfg_file.endswith((".ini", ".cfg")):
cfg = from_ini(cfg_file)
elif cfg_file.endswith(".toml") and HAVE_TOML:
cfg = from_toml(cfg_file)
if cfg:
break
return cfg


def fetch_checks(cfg):
base = [
checks.CheckValidity(cfg),
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mock # BSD
nose # LGPL
testtools # MIT
toml # MIT