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

BREAK: rename enforce_multiline in to_toml_array() #372

Merged
merged 1 commit into from
Aug 12, 2024
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
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
Loading