Skip to content
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
10 changes: 6 additions & 4 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,12 @@ def convert_arg_line_to_args(self, arg_line: str) -> list[str]:
if tomllib is not None:
for toml_file in toml_files:
with open(toml_file, "rb") as f:
data = tomllib.load(f).get("tool", {})
if "codespell" in data:
data["codespell"] = _toml_to_parseconfig(data["codespell"])
config.read_dict(data)
data = tomllib.load(f).get("tool", {}).get("codespell")
if data is not None:
if not isinstance(data, dict):
msg = f"{toml_file}: [tool.codespell] must be a table"
raise configparser.Error(msg)
config.read_dict({"codespell": _toml_to_parseconfig(data)})

# Collect which config files are going to be used
used_cfg_files = []
Expand Down
35 changes: 32 additions & 3 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,10 @@ def test_ill_formed_ini_config_file(
assert "ill-formed config file" in stderr


@pytest.mark.parametrize("kind", ["cfg", "cfg_multiline", "toml", "toml_list"])
@pytest.mark.parametrize(
"kind",
["cfg", "cfg_multiline", "toml", "toml_list", "toml_sibling_array"],
)
def test_config_toml(
tmp_path: Path,
capsys: pytest.CaptureFixture[str],
Expand Down Expand Up @@ -1482,13 +1485,23 @@ def test_config_toml(
check-filenames = false
count = true
"""
else:
assert kind == "toml_list"
elif kind == "toml_list":
text = """\
[tool.codespell]
skip = ['bad.txt', 'whatever.txt']
check-filenames = false
count = true
"""
else:
assert kind == "toml_sibling_array"
text = """\
[tool.codespell]
skip = 'bad.txt,whatever.txt'
check-filenames = false
count = true

[[tool.dynamic-metadata]]
provider = 'scikit_build_core.metadata.version'
"""
tomlfile.write_text(text)

Expand All @@ -1514,6 +1527,22 @@ def test_config_toml(
assert "abandonned.txt" not in stdout


def test_config_toml_codespell_array(
tmp_path: Path,
capsys: pytest.CaptureFixture[str],
) -> None:
if sys.version_info < (3, 11):
pytest.importorskip("tomli")
tomlfile = tmp_path / "pyproject.toml"
tomlfile.write_text("[[tool.codespell]]\nskip = 'bad.txt'\n")

result = cs.main("--toml", tomlfile, std=True)
assert isinstance(result, tuple)
code, _, stderr = result
assert code == EX_CONFIG
assert "[tool.codespell] must be a table" in stderr


@contextlib.contextmanager
def FakeStdin(text: str) -> Generator[None, None, None]:
oldin = sys.stdin
Expand Down
Loading