Skip to content

Commit

Permalink
BREAK: rename enforce_multiline to multiline in to_toml_array() (
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Aug 12, 2024
1 parent 70db258 commit b0d1b22
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def __update_ruff_lint_settings(pyproject: ModifiablePyproject) -> None:
ignored_rules = ___merge_rules(settings.get("ignore", []), ignored_rules)
minimal_settings = {
"select": to_toml_array(["ALL"]),
"ignore": to_toml_array(sorted(ignored_rules), enforce_multiline=True),
"ignore": to_toml_array(sorted(ignored_rules), multiline=True),
"task-tags": ___get_task_tags(settings),
}
if not complies_with_subset(settings, minimal_settings):
Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _update_taplo_config() -> None:
excludes = filter_patterns(expected["exclude"]) # type:ignore[arg-type]
if excludes:
sorted_excludes = sorted(excludes, key=str.lower)
expected["exclude"] = to_toml_array(sorted_excludes, enforce_multiline=True)
expected["exclude"] = to_toml_array(sorted_excludes, multiline=True)
else:
del expected["exclude"]
with open(CONFIG_PATH.taplo) as f:
Expand Down
4 changes: 2 additions & 2 deletions src/compwa_policy/utilities/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from tomlkit.items import Array


def to_toml_array(items: Iterable[Any], enforce_multiline: bool = False) -> Array:
def to_toml_array(items: Iterable[Any], multiline: bool = False) -> Array:
array = tomlkit.array()
array.extend(items)
if enforce_multiline or len(array) > 1:
if multiline or len(array) > 1:
array.multiline(True)
else:
array.multiline(False)
Expand Down
2 changes: 1 addition & 1 deletion tests/utilities/test_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_edit_and_dump():
work = pyproject.get_table("owner.work", create=True)
work["type"] = "scientist"
tools = pyproject.get_table("tool", create=True)
tools["black"] = to_toml_array(["--line-length=79"], enforce_multiline=True)
tools["black"] = to_toml_array(["--line-length=79"], multiline=True)

new_content = pyproject.dumps()
expected = dedent("""
Expand Down
10 changes: 6 additions & 4 deletions tests/utilities/test_toml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from textwrap import dedent

import pytest
Expand All @@ -16,7 +18,7 @@ def test_to_toml_array_single_item():
array = to_toml_array(lst)
assert _dump(array) == "a = [1]"

array = to_toml_array(lst, enforce_multiline=True)
array = to_toml_array(lst, multiline=True)
expected = dedent("""
a = [
1,
Expand All @@ -25,10 +27,10 @@ def test_to_toml_array_single_item():
assert _dump(array) == expected.strip()


@pytest.mark.parametrize("enforce_multiline", [False, True])
def test_to_toml_array_multiple_items(enforce_multiline: bool):
@pytest.mark.parametrize("multiline", [False, True])
def test_to_toml_array_multiple_items(multiline: bool):
lst = [1, 2, 3]
array = to_toml_array(lst, enforce_multiline)
array = to_toml_array(lst, multiline)
expected = dedent("""
a = [
1,
Expand Down

0 comments on commit b0d1b22

Please sign in to comment.